event_news/app/models/event_news_setting.rb

23 lines
970 B
Ruby
Raw Normal View History

2020-07-22 02:23:36 +00:00
class EventNewsSetting
include Mongoid::Document
include Mongoid::Timestamps
field :carousel_image_width, type: String, :default => "75%"
2020-07-22 02:23:36 +00:00
field :top_limit, type: Integer, :default => 0
field :pro_enabled, type: Boolean, :default => false
field :approvers, type: Array, :default => []
field :email_to, type: Array, :default => ["admins","managers","approvers"]
field :is_display_edit_only, type: Boolean, :default => false
field :only_manager_can_edit_status, type: Boolean, :default => false
has_many :event_news_status_settings, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :event_news_status_settings, :allow_destroy => true
def self.check_limit_for_user(user_id, b_id = nil)
limit = self.first.top_limit rescue 0
return true if limit == 0
count = Bulletin.where(:is_top => true, :create_user_id => user_id, :id.ne => b_id).count
return count < limit
end
def self.is_pro?
self.first.pro_enabled rescue false
end
end