diff options
author | Micaël Bergeron <mbergeron@gitlab.com> | 2018-01-29 16:06:17 -0500 |
---|---|---|
committer | Micaël Bergeron <mbergeron@gitlab.com> | 2018-02-02 09:28:15 -0500 |
commit | 74ddc80590053b04b90c35ae3e1f46bfbd9d0d15 (patch) | |
tree | 145eaf19ac0a06a7bb8e5a0d85b97606ccaf77eb /app/uploaders/file_uploader.rb | |
parent | 54a575f1bbba44573ab92dc58a4242f1ee734c5d (diff) | |
download | gitlab-ce-74ddc80590053b04b90c35ae3e1f46bfbd9d0d15.tar.gz |
add the uploader context to the upload model
Diffstat (limited to 'app/uploaders/file_uploader.rb')
-rw-r--r-- | app/uploaders/file_uploader.rb | 28 |
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 |