2014-06-23 08:36:04 +00:00
|
|
|
# encoding: utf-8
|
2014-05-01 08:41:00 +00:00
|
|
|
class BulletinFile
|
|
|
|
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
|
|
|
|
mount_uploader :file, AssetUploader
|
|
|
|
|
|
|
|
field :description, localize: true
|
|
|
|
field :title, localize: true
|
2016-05-09 10:11:18 +00:00
|
|
|
field :choose_lang, :type => Array, :default => ["en","zh_tw"]
|
2020-12-19 10:28:18 +00:00
|
|
|
field :privacy_type, type: String, default: 'public'
|
2014-05-01 08:41:00 +00:00
|
|
|
belongs_to :bulletin
|
|
|
|
|
2021-03-24 10:05:19 +00:00
|
|
|
def file_title
|
|
|
|
if self.description.present?
|
|
|
|
return self.description
|
|
|
|
elsif self.title.present?
|
|
|
|
return self.title
|
|
|
|
else
|
|
|
|
return File.basename(self.file.path)
|
|
|
|
end
|
|
|
|
end
|
2016-05-09 10:11:18 +00:00
|
|
|
def enabled_for?(lang)
|
|
|
|
if lang.nil?
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return self.choose_lang.include?(lang)
|
|
|
|
end
|
|
|
|
end
|
2020-12-19 10:28:18 +00:00
|
|
|
def can_access?(user)
|
|
|
|
if user.nil? && self.privacy_type == 'logged_in'
|
|
|
|
return false
|
|
|
|
else
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
2014-05-01 08:41:00 +00:00
|
|
|
end
|