debian-mirror-gitlab/app/controllers/projects/imports_controller.rb

85 lines
2 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2015-04-26 12:48:37 +05:30
class Projects::ImportsController < Projects::ApplicationController
2016-06-02 11:05:42 +05:30
include ContinueParams
2019-07-31 22:56:46 +05:30
include ImportUrlParams
2016-06-02 11:05:42 +05:30
2015-04-26 12:48:37 +05:30
# Authorize
2020-11-24 15:15:51 +05:30
before_action :authorize_admin_project!, except: :show
2020-07-28 23:09:34 +05:30
before_action :require_namespace_project_creation_permission, only: :show
2020-11-24 15:15:51 +05:30
before_action :require_no_repo, except: :show
before_action :redirect_if_progress, except: :show
2016-04-02 18:10:28 +05:30
before_action :redirect_if_no_import, only: :show
2015-04-26 12:48:37 +05:30
2021-01-03 14:25:43 +05:30
feature_category :importers
2015-04-26 12:48:37 +05:30
def new
end
def create
2019-02-15 15:39:39 +05:30
if @project.update(import_params)
2019-07-31 22:56:46 +05:30
@project.import_state.reset.schedule
2015-04-26 12:48:37 +05:30
end
2017-09-10 17:25:29 +05:30
redirect_to project_import_path(@project)
2015-04-26 12:48:37 +05:30
end
def show
2016-02-05 20:25:01 +05:30
if @project.import_finished?
2019-09-30 21:07:59 +05:30
if continue_params[:to]
redirect_to continue_params[:to], notice: continue_params[:notice]
2015-04-26 12:48:37 +05:30
else
2017-09-10 17:25:29 +05:30
redirect_to project_path(@project), notice: finished_notice
2015-04-26 12:48:37 +05:30
end
elsif @project.import_failed?
2017-09-10 17:25:29 +05:30
redirect_to new_project_import_path(@project)
else
2019-09-30 21:07:59 +05:30
flash.now[:notice] = continue_params[:notice_now]
2015-04-26 12:48:37 +05:30
end
end
private
2016-02-05 20:25:01 +05:30
def finished_notice
if @project.forked?
2019-07-07 11:18:12 +05:30
_('The project was successfully forked.')
2016-02-05 20:25:01 +05:30
else
2019-07-07 11:18:12 +05:30
_('The project was successfully imported.')
2016-02-05 20:25:01 +05:30
end
end
2015-04-26 12:48:37 +05:30
def require_no_repo
2016-02-05 20:25:01 +05:30
if @project.repository_exists?
2017-09-10 17:25:29 +05:30
redirect_to project_path(@project)
2015-04-26 12:48:37 +05:30
end
end
2020-07-28 23:09:34 +05:30
def require_namespace_project_creation_permission
2021-01-29 00:20:46 +05:30
render_404 unless can?(current_user, :admin_project, @project) || can?(current_user, :create_projects, @project.namespace)
2020-07-28 23:09:34 +05:30
end
2015-04-26 12:48:37 +05:30
def redirect_if_progress
if @project.import_in_progress?
2017-09-10 17:25:29 +05:30
redirect_to project_import_path(@project)
2016-04-02 18:10:28 +05:30
end
end
def redirect_if_no_import
if @project.repository_exists? && @project.no_import?
2017-09-10 17:25:29 +05:30
redirect_to project_path(@project)
2015-04-26 12:48:37 +05:30
end
end
2019-02-15 15:39:39 +05:30
def import_params_attributes
2019-07-31 22:56:46 +05:30
[]
2019-02-15 15:39:39 +05:30
end
def import_params
2019-07-31 22:56:46 +05:30
params.require(:project)
.permit(import_params_attributes)
.merge(import_url_params)
2019-02-15 15:39:39 +05:30
end
2015-04-26 12:48:37 +05:30
end
2019-12-04 20:38:33 +05:30
Projects::ImportsController.prepend_if_ee('EE::Projects::ImportsController')