forked from saurabh/orbit4-5
59 lines
1.3 KiB
Ruby
59 lines
1.3 KiB
Ruby
class Role
|
|
include Mongoid::Document
|
|
include Mongoid::Attributes::Dynamic
|
|
|
|
field :key, type: String
|
|
field :title, type: String, localize: true
|
|
field :built_in, type: Boolean, default: false
|
|
field :disabled, type: Boolean, default: false
|
|
|
|
has_and_belongs_to_many :member_profiles
|
|
has_many :authorizations
|
|
|
|
has_many :attribute_fields
|
|
accepts_nested_attributes_for :attribute_fields
|
|
|
|
has_many :role_statuses, dependent: :destroy
|
|
|
|
def is_built_in?
|
|
self.built_in
|
|
end
|
|
|
|
def is_disabled?
|
|
self.disabled
|
|
end
|
|
|
|
def approved_categories_for_module(module_app)
|
|
module_app_categories = module_app.categories
|
|
authorizations = Authorization.where(:role_id => self.id)
|
|
authorized_categories = []
|
|
authorizations.each do |auth|
|
|
cat = auth.category
|
|
authorized_categories << auth.category if !cat.nil?
|
|
end
|
|
(module_app_categories & authorized_categories)
|
|
end
|
|
|
|
def is_manager_for?(module_app)
|
|
a = self.authorizations.find_by(:module_app_id => module_app.id) rescue nil
|
|
if a.nil?
|
|
false
|
|
else
|
|
true
|
|
end
|
|
end
|
|
|
|
def is_sub_manager_for?(module_app)
|
|
if !self.is_manager_for?(module_app)
|
|
categories = self.approved_categories_for_module(module_app)
|
|
if categories.count > 0
|
|
true
|
|
else
|
|
false
|
|
end
|
|
else
|
|
false
|
|
end
|
|
end
|
|
end
|