43 lines
1.2 KiB
Ruby
43 lines
1.2 KiB
Ruby
|
class Role < Attribute
|
||
|
|
||
|
include Mongoid::Document
|
||
|
include Mongoid::Timestamps
|
||
|
|
||
|
field :key
|
||
|
field :built_in, :type => Boolean, :default => false
|
||
|
field :disabled, :type => Boolean, :default => false
|
||
|
|
||
|
field :title, localize: true
|
||
|
|
||
|
has_many :sub_roles, :autosave => true, :dependent => :destroy
|
||
|
has_and_belongs_to_many :users
|
||
|
has_many :statuses, :autosave => true, :dependent => :destroy
|
||
|
# has_many :attribute_fields, :autosave => true, :dependent => :destroy
|
||
|
has_many :role_statuses, :autosave => true, :dependent => :destroy
|
||
|
has_many :role_categorys, :autosave => true, :dependent => :destroy
|
||
|
|
||
|
accepts_nested_attributes_for :sub_roles, :allow_destroy => true
|
||
|
accepts_nested_attributes_for :role_statuses, :allow_destroy => true
|
||
|
accepts_nested_attributes_for :role_categorys, :allow_destroy => true
|
||
|
|
||
|
def is_built_in?
|
||
|
self.built_in
|
||
|
end
|
||
|
|
||
|
def is_disabled?
|
||
|
self.disabled
|
||
|
end
|
||
|
|
||
|
# Get an role from key
|
||
|
def self.get_role_from_key(key)
|
||
|
self.first(:conditions => {:key => key})
|
||
|
end
|
||
|
|
||
|
def statuses_for_select
|
||
|
data = self.statuses.map do |t|
|
||
|
[t.id.to_s,t.title_translations]
|
||
|
end
|
||
|
Hash[data]
|
||
|
end
|
||
|
|
||
|
end
|