2016-06-22 15:30:34 +05:30
|
|
|
class Import::GitlabProjectsController < Import::BaseController
|
2018-03-17 18:26:18 +05:30
|
|
|
before_action :whitelist_query_limiting, only: [:create]
|
2016-06-22 15:30:34 +05:30
|
|
|
before_action :verify_gitlab_project_import_enabled
|
|
|
|
|
|
|
|
def new
|
2016-11-03 12:29:30 +05:30
|
|
|
@namespace = Namespace.find(project_params[:namespace_id])
|
|
|
|
return render_404 unless current_user.can?(:create_projects, @namespace)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
@path = project_params[:path]
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
unless file_is_valid?
|
|
|
|
return redirect_back_or_default(options: { alert: "You need to upload a GitLab project export archive." })
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
@project = ::Projects::GitlabProjectsImportService.new(current_user, project_params).execute
|
2016-06-22 15:30:34 +05:30
|
|
|
|
|
|
|
if @project.saved?
|
|
|
|
redirect_to(
|
|
|
|
project_path(@project),
|
|
|
|
notice: "Project '#{@project.name}' is being imported."
|
|
|
|
)
|
|
|
|
else
|
2016-08-24 12:49:21 +05:30
|
|
|
redirect_back_or_default(options: { alert: "Project could not be imported: #{@project.errors.full_messages.join(', ')}" })
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def file_is_valid?
|
|
|
|
project_params[:file] && project_params[:file].respond_to?(:read)
|
|
|
|
end
|
|
|
|
|
|
|
|
def verify_gitlab_project_import_enabled
|
|
|
|
render_404 unless gitlab_project_import_enabled?
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_params
|
|
|
|
params.permit(
|
|
|
|
:path, :namespace_id, :file
|
|
|
|
)
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
def whitelist_query_limiting
|
|
|
|
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42437')
|
|
|
|
end
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|