2013-01-08 08:58:01 +00:00
|
|
|
class Role < Attribute
|
2011-12-23 10:34:21 +00:00
|
|
|
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
|
|
|
|
field :key
|
|
|
|
field :built_in, :type => Boolean, :default => false
|
|
|
|
field :disabled, :type => Boolean, :default => false
|
2013-01-08 08:58:01 +00:00
|
|
|
|
2012-07-25 21:07:32 +00:00
|
|
|
field :title, localize: true
|
2011-12-23 10:34:21 +00:00
|
|
|
|
2012-01-24 07:12:06 +00:00
|
|
|
has_many :sub_roles, :autosave => true, :dependent => :destroy
|
2011-12-23 10:34:21 +00:00
|
|
|
has_many :users
|
2012-09-13 10:39:27 +00:00
|
|
|
has_many :statuses, :autosave => true, :dependent => :destroy
|
2013-01-08 08:58:01 +00:00
|
|
|
# has_many :attribute_fields, :autosave => true, :dependent => :destroy
|
2011-12-23 10:34:21 +00:00
|
|
|
accepts_nested_attributes_for :sub_roles, :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
|
|
|
|
|
2012-10-24 06:46:25 +00:00
|
|
|
def statuses_for_select
|
|
|
|
data = self.statuses.map do |t|
|
|
|
|
[t.id.to_s,t.title_translations]
|
|
|
|
end
|
|
|
|
Hash[data]
|
|
|
|
end
|
|
|
|
|
2011-12-23 10:34:21 +00:00
|
|
|
end
|