Application_Form/custom_announcement/app/models/custom_bulletin_file.rb

39 lines
823 B
Ruby
Raw Normal View History

# encoding: utf-8
class CustomBulletinFile
include Mongoid::Document
include Mongoid::Timestamps
mount_uploader :file, AssetUploader
field :description, localize: true
field :title, localize: true
field :choose_lang, :type => Array, :default => ["en","zh_tw"]
field :privacy_type, type: String, default: 'public'
belongs_to :custom_bulletin
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
def enabled_for?(lang)
if lang.nil?
return true
else
return self.choose_lang.include?(lang)
end
end
def can_access?(user)
if user.nil? && self.privacy_type == 'logged_in'
return false
else
return true
end
end
end