diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-10 21:08:17 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-10 21:08:17 +0300 |
commit | 219eead23f9feb5da9ec378c451d773aea2dfe61 (patch) | |
tree | eec14421a05ca8eb79f3cc782abe99532bb6070c /app/controllers/import | |
parent | 7c38405be9e79099f399aa429503ea7b463bbf5a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/controllers/import')
-rw-r--r-- | app/controllers/import/gitlab_projects_controller.rb | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/app/controllers/import/gitlab_projects_controller.rb b/app/controllers/import/gitlab_projects_controller.rb index c9c487cec26..6b8436d766c 100644 --- a/app/controllers/import/gitlab_projects_controller.rb +++ b/app/controllers/import/gitlab_projects_controller.rb @@ -1,9 +1,14 @@ # frozen_string_literal: true class Import::GitlabProjectsController < Import::BaseController + include WorkhorseRequest + before_action :whitelist_query_limiting, only: [:create] before_action :verify_gitlab_project_import_enabled + skip_before_action :verify_authenticity_token, only: [:authorize] + before_action :verify_workhorse_api!, only: [:authorize] + def new @namespace = Namespace.find(project_params[:namespace_id]) return render_404 unless current_user.can?(:create_projects, @namespace) @@ -28,10 +33,29 @@ class Import::GitlabProjectsController < Import::BaseController end end + 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 + private def file_is_valid? - return false unless project_params[:file] && project_params[:file].respond_to?(:read) + # TODO: remove the condition and the private method after the WH version including + # https://gitlab.com/gitlab-org/gitlab-workhorse/-/merge_requests/470 + # is released and GITLAB_WORKHORSE_VERSION is updated accordingly. + if with_workhorse_upload_acceleration? + return false unless project_params[:file].is_a?(::UploadedFile) + else + return false unless project_params[:file] && project_params[:file].respond_to?(:read) + end filename = project_params[:file].original_filename @@ -51,4 +75,8 @@ class Import::GitlabProjectsController < Import::BaseController def whitelist_query_limiting Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-foss/issues/42437') end + + def with_workhorse_upload_acceleration? + request.headers[Gitlab::Workhorse::INTERNAL_API_REQUEST_HEADER].present? + end end |