Modifications of the user model
This commit is contained in:
1 parent
1909edbe2a
commit
509c106b3e
7 files changed
+64
-19
No files matched your search
@@ -0,0 +1,10 @@
|
||||
class AttributeValue
|
||||
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
field :key
|
||||
|
||||
belongs_to :user_attribute
|
||||
|
||||
end
|
||||
+14
-2
@@ -10,8 +10,8 @@ class User
|
||||
field :admin, :type => Boolean, :default => true
|
||||
field :active_roles, :type => Array
|
||||
|
||||
embeds_many :user_roles
|
||||
embeds_many :user_infos
|
||||
has_many :user_roles
|
||||
has_many :user_infos
|
||||
before_save :clean_active_roles
|
||||
|
||||
# Update or create the user_role records
|
||||
@@ -26,6 +26,18 @@ class User
|
||||
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 }
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
class UserAttribute
|
||||
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
field :key
|
||||
has_many :attribute_values
|
||||
|
||||
# Update or create the attribute_value records
|
||||
def attributes=(*args)
|
||||
args[0].each do |value|
|
||||
if value[:id].blank?
|
||||
attribute_values.build(value)
|
||||
else
|
||||
attribute_value = attribute_values.detect {|a| a.id.to_s == value[:id].to_s }
|
||||
attribute_value.update_attributes(value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,10 +1,5 @@
|
||||
class UserInfo
|
||||
class UserInfo < UserAttribute
|
||||
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
field :key
|
||||
|
||||
embedded_in :user, :inverse_of => :user_infos
|
||||
belongs_to :user
|
||||
|
||||
end
|
||||
@@ -1,10 +1,5 @@
|
||||
class UserRole
|
||||
class UserRole < UserAttribute
|
||||
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
field :key
|
||||
|
||||
embedded_in :user, :inverse_of => :user_roles
|
||||
belongs_to :user
|
||||
|
||||
end
|
||||
Reference in new issue
Block a user