2018-07-04 17:32:46 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-18 14:31:44 +00:00
|
|
|
class AvatarUploader < GitlabUploader
|
2015-11-14 18:29:58 +00:00
|
|
|
include UploaderHelper
|
2018-02-02 13:59:43 +00:00
|
|
|
include RecordsUploads::Concern
|
|
|
|
include ObjectStorage::Concern
|
|
|
|
prepend ObjectStorage::Extension::RecordsUploads
|
2020-01-02 21:07:38 +00:00
|
|
|
|
2020-03-12 18:09:28 +00:00
|
|
|
MIME_WHITELIST = %w[image/png image/jpeg image/gif image/bmp image/tiff image/vnd.microsoft.icon].freeze
|
2015-02-20 14:19:50 +00:00
|
|
|
|
2016-07-15 14:03:31 +00:00
|
|
|
def exists?
|
2017-09-19 14:34:10 +00:00
|
|
|
model.avatar.file && model.avatar.file.present?
|
2016-07-15 14:03:31 +00:00
|
|
|
end
|
2017-01-02 11:35:15 +00:00
|
|
|
|
|
|
|
def move_to_store
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def move_to_cache
|
|
|
|
false
|
|
|
|
end
|
2018-02-02 13:59:43 +00:00
|
|
|
|
2018-08-29 13:41:56 +00:00
|
|
|
def absolute_path
|
2019-10-03 00:05:59 +00:00
|
|
|
self.class.absolute_path(upload)
|
2018-08-29 13:41:56 +00:00
|
|
|
end
|
|
|
|
|
2020-02-12 18:09:21 +00:00
|
|
|
def mounted_as
|
|
|
|
super || 'avatar'
|
|
|
|
end
|
|
|
|
|
2020-03-12 18:09:28 +00:00
|
|
|
def content_type_whitelist
|
|
|
|
MIME_WHITELIST
|
|
|
|
end
|
|
|
|
|
2018-02-02 13:59:43 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def dynamic_segment
|
2019-05-11 12:06:44 +00:00
|
|
|
File.join(model.class.underscore, mounted_as.to_s, model.id.to_s)
|
2018-02-02 13:59:43 +00:00
|
|
|
end
|
2015-02-20 14:19:50 +00:00
|
|
|
end
|