2016-04-26 04:59:00 -04:00
|
|
|
class Import::GitlabProjectsController < Import::BaseController
|
2018-01-15 10:21:04 -05:00
|
|
|
before_action :whitelist_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
|
2016-06-13 14:35:57 -04:00
|
|
|
unless file_is_valid?
|
|
|
|
return redirect_back_or_default(options: { alert: "You need to upload a GitLab project export archive." })
|
|
|
|
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),
|
|
|
|
notice: "Project '#{@project.name}' is being imported."
|
|
|
|
)
|
|
|
|
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
|
|
|
|
2016-06-13 14:35:57 -04:00
|
|
|
def file_is_valid?
|
2016-06-15 11:31:00 -04:00
|
|
|
project_params[:file] && project_params[:file].respond_to?(:read)
|
2016-06-13 14:35:57 -04:00
|
|
|
end
|
|
|
|
|
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
|
|
|
|
|
|
|
def whitelist_query_limiting
|
|
|
|
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42437')
|
|
|
|
end
|
2016-04-25 12:00:15 -04:00
|
|
|
end
|