2018-09-25 23:45:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-11-29 17:50:25 -05:00
|
|
|
class Projects::ImportsController < Projects::ApplicationController
|
2016-03-07 04:36:16 -05:00
|
|
|
include ContinueParams
|
2019-04-11 11:26:16 -04:00
|
|
|
include ImportUrlParams
|
2016-03-07 04:06:54 -05:00
|
|
|
|
2014-11-29 17:50:25 -05:00
|
|
|
# Authorize
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :authorize_admin_project!
|
2016-01-25 18:00:23 -05:00
|
|
|
before_action :require_no_repo, only: [:new, :create]
|
|
|
|
before_action :redirect_if_progress, only: [:new, :create]
|
2016-02-17 09:05:44 -05:00
|
|
|
before_action :redirect_if_no_import, only: :show
|
2014-11-29 17:50:25 -05:00
|
|
|
|
|
|
|
def new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2018-12-17 12:45:29 -05:00
|
|
|
if @project.update(import_params)
|
2019-04-08 09:33:36 -04:00
|
|
|
@project.import_state.reset.schedule
|
2014-11-29 17:50:25 -05:00
|
|
|
end
|
|
|
|
|
2017-06-29 13:06:35 -04:00
|
|
|
redirect_to project_import_path(@project)
|
2014-11-29 17:50:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2016-01-25 18:00:23 -05:00
|
|
|
if @project.import_finished?
|
2019-06-20 13:13:02 -04:00
|
|
|
if continue_params[:to]
|
2015-12-18 04:03:34 -05:00
|
|
|
redirect_to continue_params[:to], notice: continue_params[:notice]
|
2014-11-29 17:50:25 -05:00
|
|
|
else
|
2017-06-29 13:06:35 -04:00
|
|
|
redirect_to project_path(@project), notice: finished_notice
|
2014-11-29 17:50:25 -05:00
|
|
|
end
|
2015-12-18 04:03:34 -05:00
|
|
|
elsif @project.import_failed?
|
2017-06-29 13:06:35 -04:00
|
|
|
redirect_to new_project_import_path(@project)
|
2015-12-18 04:03:34 -05:00
|
|
|
else
|
2019-06-20 13:13:02 -04:00
|
|
|
flash.now[:notice] = continue_params[:notice_now]
|
2014-11-29 17:50:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-01-25 18:00:23 -05:00
|
|
|
def finished_notice
|
|
|
|
if @project.forked?
|
2019-03-27 12:52:52 -04:00
|
|
|
_('The project was successfully forked.')
|
2016-01-25 18:00:23 -05:00
|
|
|
else
|
2019-03-27 12:52:52 -04:00
|
|
|
_('The project was successfully imported.')
|
2016-01-25 18:00:23 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-29 17:50:25 -05:00
|
|
|
def require_no_repo
|
2016-01-25 18:00:23 -05:00
|
|
|
if @project.repository_exists?
|
2017-06-29 13:06:35 -04:00
|
|
|
redirect_to project_path(@project)
|
2014-11-29 17:50:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def redirect_if_progress
|
|
|
|
if @project.import_in_progress?
|
2017-06-29 13:06:35 -04:00
|
|
|
redirect_to project_import_path(@project)
|
2016-02-17 09:05:44 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def redirect_if_no_import
|
|
|
|
if @project.repository_exists? && @project.no_import?
|
2017-06-29 13:06:35 -04:00
|
|
|
redirect_to project_path(@project)
|
2014-11-29 17:50:25 -05:00
|
|
|
end
|
|
|
|
end
|
2018-11-27 04:41:27 -05:00
|
|
|
|
2018-12-17 12:45:29 -05:00
|
|
|
def import_params_attributes
|
2019-04-11 11:26:16 -04:00
|
|
|
[]
|
2018-11-27 04:41:27 -05:00
|
|
|
end
|
|
|
|
|
2018-12-17 12:45:29 -05:00
|
|
|
def import_params
|
2019-04-11 11:26:16 -04:00
|
|
|
params.require(:project)
|
|
|
|
.permit(import_params_attributes)
|
|
|
|
.merge(import_url_params)
|
2018-11-27 04:41:27 -05:00
|
|
|
end
|
2014-11-29 17:50:25 -05:00
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
Projects::ImportsController.prepend_if_ee('EE::Projects::ImportsController')
|