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