diff options
author | Kamil Trzciński (OoO till 3th) <ayufan@ayufan.eu> | 2018-07-04 09:50:29 +0000 |
---|---|---|
committer | Kamil Trzciński (OoO till 3th) <ayufan@ayufan.eu> | 2018-07-04 09:50:29 +0000 |
commit | 34694c3afc8e3476f5f070fe1c97aef9119a921b (patch) | |
tree | 9a1c90f0bfc37d97aa5675cbfc1748cc0fce0f7d /lib/gitlab/middleware | |
parent | cda22d0780ea9bf598f82f51fffb7c50a4b4b1bc (diff) | |
parent | 249c24891a3a54d2fd6b9355244cad4e35d722f7 (diff) | |
download | gitlab-ce-34694c3afc8e3476f5f070fe1c97aef9119a921b.tar.gz |
Merge branch 'jprovazn-direct-upload' into 'master'
Add workhorse authorize method for project/group uploads
Closes #44663
See merge request gitlab-org/gitlab-ce!19717
Diffstat (limited to 'lib/gitlab/middleware')
-rw-r--r-- | lib/gitlab/middleware/multipart.rb | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/gitlab/middleware/multipart.rb b/lib/gitlab/middleware/multipart.rb index a5f5d719cc1..9753be6d5c3 100644 --- a/lib/gitlab/middleware/multipart.rb +++ b/lib/gitlab/middleware/multipart.rb @@ -42,10 +42,10 @@ module Gitlab key, value = parsed_field.first if value.nil? - value = open_file(tmp_path, @request.params["#{key}.name"]) + value = open_file(@request.params, key) @open_files << value else - value = decorate_params_value(value, @request.params[key], tmp_path) + value = decorate_params_value(value, @request.params[key]) end @request.update_param(key, value) @@ -57,7 +57,7 @@ module Gitlab end # This function calls itself recursively - def decorate_params_value(path_hash, value_hash, tmp_path) + def decorate_params_value(path_hash, value_hash) unless path_hash.is_a?(Hash) && path_hash.count == 1 raise "invalid path: #{path_hash.inspect}" end @@ -70,19 +70,21 @@ module Gitlab case path_value when nil - value_hash[path_key] = open_file(tmp_path, value_hash.dig(path_key, '.name')) + value_hash[path_key] = open_file(value_hash.dig(path_key), '') @open_files << value_hash[path_key] value_hash when Hash - decorate_params_value(path_value, value_hash[path_key], tmp_path) + decorate_params_value(path_value, value_hash[path_key]) value_hash else raise "unexpected path value: #{path_value.inspect}" end end - def open_file(path, name) - ::UploadedFile.new(path, filename: name || File.basename(path), content_type: 'application/octet-stream') + def open_file(params, key) + ::UploadedFile.from_params( + params, key, + Gitlab.config.uploads.storage_path) end end |