Change role structure
Still needs to: change the views and create sub_roles in the dev.rake
This commit is contained in:
1 parent
e0cdedfa2e
commit
b7ac5478b4
45 files changed
+608
-492
No files matched your search
+4
-37
@@ -10,43 +10,10 @@ class User
|
||||
field :admin, :type => Boolean, :default => true
|
||||
field :active_role
|
||||
|
||||
has_many :user_attributes
|
||||
has_many :user_roles
|
||||
has_many :user_infos
|
||||
|
||||
# Update or create the user_role records
|
||||
def user_roles=(*attrs)
|
||||
attrs[0].each do |roles|
|
||||
if roles[:id].blank?
|
||||
user_roles.build(roles)
|
||||
else
|
||||
user_role = user_roles.detect {|a| a.id.to_s == roles[:id].to_s }
|
||||
user_role.update_attributes(roles)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Update or create the user_info records
|
||||
def user_infos=(*attrs)
|
||||
attrs[0].each do |infos|
|
||||
if infos[:id].blank?
|
||||
user_infos.build(infos)
|
||||
else
|
||||
user_info = user_infos.detect {|a| a.id.to_s == infos[:id].to_s }
|
||||
user_info.update_attributes(infos)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Get an user_info from model key
|
||||
def get_info_from_model_key(key)
|
||||
self.user_infos.detect {|a| a.key.to_s == key.to_s }
|
||||
end
|
||||
|
||||
# Get an user_role from model key
|
||||
def get_role_from_model_key(key)
|
||||
self.user_roles.detect {|a| a.key.to_s == key.to_s }
|
||||
end
|
||||
has_many :attribute_values, :autosave => true, :dependent => :destroy
|
||||
belongs_to :role
|
||||
belongs_to :sub_role
|
||||
accepts_nested_attributes_for :attribute_values, :allow_destroy => true
|
||||
|
||||
def name
|
||||
infos = self.user_infos.detect {|info| info.key.to_s.eql?('profile') }
|
||||
|
||||
Reference in new issue
Block a user