2014-04-10 09:55:24 +00:00
|
|
|
class Category
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
|
|
|
|
field :disable, type: Boolean, default: false
|
|
|
|
field :title, localize: true
|
|
|
|
|
|
|
|
belongs_to :module_app
|
2014-05-01 07:14:16 +00:00
|
|
|
has_many :authorizations
|
2014-04-10 09:55:24 +00:00
|
|
|
|
|
|
|
scope :enabled, ->{ where(:disable.in => [false, nil, ''])}
|
2014-05-01 07:14:16 +00:00
|
|
|
|
2014-07-17 03:54:00 +00:00
|
|
|
validates :title, presence: true
|
|
|
|
|
2014-05-01 07:14:16 +00:00
|
|
|
def category_sub_managers
|
|
|
|
Authorization.category_authorized_users(self).pluck(:user_id)
|
|
|
|
end
|
2014-07-30 13:40:02 +00:00
|
|
|
|
|
|
|
def self.authorized(user)
|
2014-08-05 13:51:05 +00:00
|
|
|
module_app_categories = self.each{|c| c}.to_a rescue []
|
|
|
|
authorized_categories = user.approved_categories
|
|
|
|
intersection = (module_app_categories & authorized_categories)
|
|
|
|
intersection
|
2014-07-30 13:40:02 +00:00
|
|
|
end
|
2014-04-10 09:55:24 +00:00
|
|
|
end
|