summaryrefslogtreecommitdiff
path: root/app/uploaders
diff options
context:
space:
mode:
authorHannes Rosenögger <123haynes@gmail.com>2015-02-14 16:04:45 +0100
committerDouwe Maan <douwe@gitlab.com>2015-02-17 22:20:44 +0100
commit9bf8480b4a0d3ea6e284c4bd8bf26243f3f3f6f5 (patch)
tree2365d68b1905ddce4d20f226f9e888c29bc0dcf4 /app/uploaders
parent0da0d800f2a0db9d9c16cf5e2feb0dd80b528223 (diff)
downloadgitlab-ce-9bf8480b4a0d3ea6e284c4bd8bf26243f3f3f6f5.tar.gz
Generalize the image upload in markdown
This commit generalizes the image upload via drag and drop so it supports all files. It also adds access control for these files.
Diffstat (limited to 'app/uploaders')
-rw-r--r--app/uploaders/file_uploader.rb19
1 files changed, 18 insertions, 1 deletions
diff --git a/app/uploaders/file_uploader.rb b/app/uploaders/file_uploader.rb
index 0fa987c93f6..ac7bd5b27ec 100644
--- a/app/uploaders/file_uploader.rb
+++ b/app/uploaders/file_uploader.rb
@@ -21,7 +21,7 @@ class FileUploader < CarrierWave::Uploader::Base
end
def extension_white_list
- @allowed_extensions
+ @allowed_extensions || super
end
def store!(file)
@@ -38,4 +38,21 @@ class FileUploader < CarrierWave::Uploader::Base
def self.generate_dir
SecureRandom.hex(5)
end
+
+ def secure_url
+ Gitlab.config.gitlab.relative_url_root + "/files/#{@path}/#{@filename}"
+ end
+
+ def image?
+ img_ext = %w(png jpg jpeg gif bmp tiff)
+ if file.respond_to?(:extension)
+ img_ext.include?(file.extension.downcase)
+ else
+ # Not all CarrierWave storages respond to :extension
+ ext = file.path.split('.').last.downcase
+ img_ext.include?(ext)
+ end
+ rescue
+ false
+ end
end