2018-09-23 19:44:14 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-04-26 08:59:00 +00:00
|
|
|
class Import::GitlabProjectsController < Import::BaseController
|
2020-05-21 09:08:04 +00:00
|
|
|
include WorkhorseImportExportUpload
|
2020-03-10 18:08:17 +00:00
|
|
|
|
2018-01-15 15:21:04 +00:00
|
|
|
before_action :whitelist_query_limiting, only: [:create]
|
2016-04-25 16:00:15 +00:00
|
|
|
before_action :verify_gitlab_project_import_enabled
|
|
|
|
|
2016-04-26 08:59:00 +00:00
|
|
|
def new
|
2016-10-20 14:54:55 +00:00
|
|
|
@namespace = Namespace.find(project_params[:namespace_id])
|
|
|
|
return render_404 unless current_user.can?(:create_projects, @namespace)
|
2017-11-14 09:02:39 +00:00
|
|
|
|
2016-04-26 15:12:50 +00:00
|
|
|
@path = project_params[:path]
|
2016-04-25 16:00:15 +00:00
|
|
|
end
|
|
|
|
|
2016-05-13 15:03:03 +00:00
|
|
|
def create
|
2020-05-21 09:08:04 +00:00
|
|
|
unless file_is_valid?(project_params[:file])
|
2019-03-27 16:52:52 +00:00
|
|
|
return redirect_back_or_default(options: { alert: _("You need to upload a GitLab project export archive (ending in .gz).") })
|
2016-06-13 18:35:57 +00:00
|
|
|
end
|
|
|
|
|
2017-08-07 17:24:40 +00:00
|
|
|
@project = ::Projects::GitlabProjectsImportService.new(current_user, project_params).execute
|
2016-06-13 18:35:57 +00:00
|
|
|
|
|
|
|
if @project.saved?
|
|
|
|
redirect_to(
|
|
|
|
project_path(@project),
|
2019-03-27 16:52:52 +00:00
|
|
|
notice: _("Project '%{project_name}' is being imported.") % { project_name: @project.name }
|
2016-06-13 18:35:57 +00:00
|
|
|
)
|
|
|
|
else
|
2016-07-07 13:34:45 +00:00
|
|
|
redirect_back_or_default(options: { alert: "Project could not be imported: #{@project.errors.full_messages.join(', ')}" })
|
2016-06-13 18:35:57 +00:00
|
|
|
end
|
2016-04-25 16:00:15 +00:00
|
|
|
end
|
|
|
|
|
2016-05-13 15:03:03 +00:00
|
|
|
private
|
2016-04-25 16:00:15 +00:00
|
|
|
|
|
|
|
def verify_gitlab_project_import_enabled
|
|
|
|
render_404 unless gitlab_project_import_enabled?
|
|
|
|
end
|
2016-04-26 15:12:50 +00:00
|
|
|
|
|
|
|
def project_params
|
2016-04-27 13:01:55 +00:00
|
|
|
params.permit(
|
2016-06-14 19:03:14 +00:00
|
|
|
:path, :namespace_id, :file
|
2016-04-26 15:12:50 +00:00
|
|
|
)
|
|
|
|
end
|
2018-01-15 15:21:04 +00:00
|
|
|
|
|
|
|
def whitelist_query_limiting
|
2019-09-18 14:02:45 +00:00
|
|
|
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-foss/issues/42437')
|
2018-01-15 15:21:04 +00:00
|
|
|
end
|
2016-04-25 16:00:15 +00:00
|
|
|
end
|