debian-mirror-gitlab/app/controllers/import/gitlab_projects_controller.rb

72 lines
2.1 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2016-06-22 15:30:34 +05:30
class Import::GitlabProjectsController < Import::BaseController
2020-04-08 14:13:33 +05:30
include WorkhorseRequest
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
2020-04-08 14:13:33 +05:30
skip_before_action :verify_authenticity_token, only: [:authorize]
before_action :verify_workhorse_api!, only: [:authorize]
2016-06-22 15:30:34 +05:30
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?
2019-07-07 11:18:12 +05:30
return redirect_back_or_default(options: { alert: _("You need to upload a GitLab project export archive (ending in .gz).") })
2016-06-22 15:30:34 +05:30
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),
2019-07-07 11:18:12 +05:30
notice: _("Project '%{project_name}' is being imported.") % { project_name: @project.name }
2016-06-22 15:30:34 +05:30
)
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
2020-04-08 14:13:33 +05:30
def authorize
set_workhorse_internal_api_content_type
authorized = ImportExportUploader.workhorse_authorize(
has_length: false,
maximum_size: Gitlab::CurrentSettings.max_attachment_size.megabytes.to_i)
render json: authorized
rescue SocketError
render json: _("Error uploading file"), status: :internal_server_error
end
2016-06-22 15:30:34 +05:30
private
def file_is_valid?
2020-04-22 19:07:51 +05:30
return false unless project_params[:file].is_a?(::UploadedFile)
2018-11-20 20:47:30 +05:30
filename = project_params[:file].original_filename
ImportExportUploader::EXTENSION_WHITELIST.include?(File.extname(filename).delete('.'))
2016-06-22 15:30:34 +05:30
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
2019-12-04 20:38:33 +05:30
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-foss/issues/42437')
2018-03-17 18:26:18 +05:30
end
2016-06-22 15:30:34 +05:30
end