Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMicaël Bergeron <mbergeron@gitlab.com>2018-01-30 00:06:17 +0300
committerMicaël Bergeron <mbergeron@gitlab.com>2018-02-02 17:28:15 +0300
commit74ddc80590053b04b90c35ae3e1f46bfbd9d0d15 (patch)
tree145eaf19ac0a06a7bb8e5a0d85b97606ccaf77eb /app/uploaders/file_uploader.rb
parent54a575f1bbba44573ab92dc58a4242f1ee734c5d (diff)
add the uploader context to the upload model
Diffstat (limited to 'app/uploaders/file_uploader.rb')
-rw-r--r--app/uploaders/file_uploader.rb28
1 files changed, 21 insertions, 7 deletions
diff --git a/app/uploaders/file_uploader.rb b/app/uploaders/file_uploader.rb
index 85ae9863b13..cc4e7a38165 100644
--- a/app/uploaders/file_uploader.rb
+++ b/app/uploaders/file_uploader.rb
@@ -62,9 +62,11 @@ class FileUploader < GitlabUploader
attr_accessor :model
- def initialize(model, secret = nil)
+ def initialize(model, mounted_as = nil, **uploader_context)
+ super(model, nil, **uploader_context)
+
@model = model
- @secret = secret
+ apply_context!(uploader_context)
end
def base_dir
@@ -107,12 +109,12 @@ class FileUploader < GitlabUploader
self.file.filename
end
- # the upload does not hold the secret, but holds the path
- # which contains the secret: extract it
def upload=(value)
- if matches = DYNAMIC_PATH_PATTERN.match(value.path)
- @secret = matches[:secret]
- @identifier = matches[:identifier]
+ unless apply_context!(value.uploader_context)
+ if matches = DYNAMIC_PATH_PATTERN.match(value.path)
+ @secret = matches[:secret]
+ @identifier = matches[:identifier]
+ end
end
super
@@ -124,6 +126,18 @@ class FileUploader < GitlabUploader
private
+ def apply_context!(uploader_context)
+ @secret, @identifier = uploader_context.values_at(:secret, :identifier)
+
+ !!(@secret && @identifier)
+ end
+
+ def build_upload
+ super.tap do |upload|
+ upload.secret = secret
+ end
+ end
+
def markdown_name
(image_or_video? ? File.basename(filename, File.extname(filename)) : filename).gsub("]", "\\]")
end