summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-13 18:09:39 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-13 18:09:39 +0000
commit00fa950a34b1c94617110b150b8b2517d5241249 (patch)
tree8f2d8683879079da8f520f7867ebd49b8beaadef /lib
parentc36152ff8c41fad2f413f253eb7ac5c927e47c56 (diff)
downloadgitlab-ce-00fa950a34b1c94617110b150b8b2517d5241249.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/api/helpers/file_upload_helpers.rb5
-rw-r--r--lib/api/project_import.rb26
2 files changed, 8 insertions, 23 deletions
diff --git a/lib/api/helpers/file_upload_helpers.rb b/lib/api/helpers/file_upload_helpers.rb
index c5fb291a2b7..dd551ec2976 100644
--- a/lib/api/helpers/file_upload_helpers.rb
+++ b/lib/api/helpers/file_upload_helpers.rb
@@ -4,11 +4,12 @@ module API
module Helpers
module FileUploadHelpers
def file_is_valid?
- params[:file] && params[:file]['tempfile'].respond_to?(:read)
+ filename = params[:file]&.original_filename
+ filename && ImportExportUploader::EXTENSION_WHITELIST.include?(File.extname(filename).delete('.'))
end
def validate_file!
- render_api_error!('Uploaded file is invalid', 400) unless file_is_valid?
+ render_api_error!({ error: _('You need to upload a GitLab project export archive (ending in .gz).') }, 422) unless file_is_valid?
end
end
end
diff --git a/lib/api/project_import.rb b/lib/api/project_import.rb
index d2247aaee34..ffa9dd13754 100644
--- a/lib/api/project_import.rb
+++ b/lib/api/project_import.rb
@@ -21,10 +21,6 @@ module API
def rate_limiter
::Gitlab::ApplicationRateLimiter
end
-
- def with_workhorse_upload_acceleration?
- request.headers[Gitlab::Workhorse::INTERNAL_API_REQUEST_HEADER].present?
- end
end
before do
@@ -46,11 +42,7 @@ module API
params do
requires :path, type: String, desc: 'The new project path and name'
- # TODO: remove rubocop disable - https://gitlab.com/gitlab-org/gitlab/issues/14960
- # and mark WH fields as required (instead of optional) after the WH version including
- # https://gitlab.com/gitlab-org/gitlab-workhorse/-/merge_requests/459
- # is deployed and GITLAB_WORKHORSE_VERSION is updated accordingly.
- requires :file, types: [::API::Validations::Types::WorkhorseFile, File], desc: 'The project export file to be imported' # rubocop:disable Scalability/FileUploads
+ requires :file, type: ::API::Validations::Types::WorkhorseFile, desc: 'The project export file to be imported'
optional :name, type: String, desc: 'The name of the project to be imported. Defaults to the path of the project if not provided.'
optional :namespace, type: String, desc: "The ID or name of the namespace that the project will be imported into. Defaults to the current user's namespace."
optional :overwrite, type: Boolean, default: false, desc: 'If there is a project in the same namespace and with the same name overwrite it'
@@ -75,7 +67,7 @@ module API
success Entities::ProjectImportStatus
end
post 'import' do
- require_gitlab_workhorse! if with_workhorse_upload_acceleration?
+ require_gitlab_workhorse!
key = "project_import".to_sym
@@ -87,27 +79,19 @@ module API
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-foss/issues/42437')
+ validate_file!
+
namespace = if import_params[:namespace]
find_namespace!(import_params[:namespace])
else
current_user.namespace
end
- # TODO: remove the condition after the WH version including
- # https://gitlab.com/gitlab-org/gitlab-workhorse/-/merge_requests/459
- # is deployed and GITLAB_WORKHORSE_VERSION is updated accordingly.
- file = if with_workhorse_upload_acceleration?
- import_params[:file] || bad_request!('Unable to process project import file')
- else
- validate_file!
- import_params[:file]['tempfile']
- end
-
project_params = {
path: import_params[:path],
namespace_id: namespace.id,
name: import_params[:name],
- file: file,
+ file: import_params[:file],
overwrite: import_params[:overwrite]
}