| 
									
										
										
										
											2010-03-04 08:33:26 +00:00
										 |  |  | class User | 
					
						
							| 
									
										
										
										
											2011-04-13 10:19:51 +00:00
										 |  |  |    | 
					
						
							|  |  |  |   include Mongoid::Document | 
					
						
							| 
									
										
										
										
											2011-03-08 09:25:46 +00:00
										 |  |  |   include Mongoid::Timestamps | 
					
						
							| 
									
										
										
										
											2010-03-04 08:33:26 +00:00
										 |  |  |   | 
					
						
							| 
									
										
										
										
											2011-04-13 10:19:51 +00:00
										 |  |  |   devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   mount_uploader :avatar, AvatarUploader | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2011-01-31 03:31:33 +00:00
										 |  |  |   field :admin, :type => Boolean, :default => true | 
					
						
							| 
									
										
										
										
											2011-11-18 08:43:14 +00:00
										 |  |  |   field :active_role | 
					
						
							| 
									
										
										
										
											2011-04-13 10:19:51 +00:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2011-12-10 10:12:39 +00:00
										 |  |  |   has_many :attribute_values, :autosave => true, :dependent => :destroy | 
					
						
							| 
									
										
										
										
											2011-12-20 08:47:17 +00:00
										 |  |  |   has_many :app_auths,as: :privilege_apps,:inverse_of => :privilege_lists | 
					
						
							|  |  |  |   has_many :blocked_apps,  :inverse_of => :blocked_users, :class_name => "AppAuth" | 
					
						
							|  |  |  |   has_many :privilege_apps,  :inverse_of => :privilege_users, :class_name => "AppAuth" | 
					
						
							| 
									
										
										
										
											2012-01-13 10:20:04 +00:00
										 |  |  |    | 
					
						
							|  |  |  |   has_many :managing_apps,:class_name => "AppManager" | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2011-12-10 10:12:39 +00:00
										 |  |  |   belongs_to :role | 
					
						
							| 
									
										
										
										
											2011-12-20 06:35:28 +00:00
										 |  |  |   has_and_belongs_to_many :sub_roles | 
					
						
							| 
									
										
										
										
											2011-12-10 10:12:39 +00:00
										 |  |  |   accepts_nested_attributes_for :attribute_values, :allow_destroy => true | 
					
						
							| 
									
										
										
										
											2011-04-13 10:19:51 +00:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2011-12-20 08:47:17 +00:00
										 |  |  |   def avb_apps | 
					
						
							| 
									
										
										
										
											2012-01-05 08:20:51 +00:00
										 |  |  |     sub_role_ids_ary=self.sub_roles.collect{|t| t.id} | 
					
						
							|  |  |  |     query1 = AppAuth.any_in({sub_role_ids: sub_role_ids_ary}).excludes(blocked_user_ids: self.id) | 
					
						
							|  |  |  |     query2 = AppAuth.any_of({all: true},{privilege_user_ids: self.id},{role_ids: self.role.id}).excludes(blocked_user_ids: self.id) | 
					
						
							|  |  |  |     (query1 + query2).uniq | 
					
						
							| 
									
										
										
										
											2011-12-20 08:47:17 +00:00
										 |  |  |   end | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2011-11-17 12:02:58 +00:00
										 |  |  |   def name | 
					
						
							| 
									
										
										
										
											2011-12-18 02:07:42 +00:00
										 |  |  |     info = Class::Info.first(:conditions => {:key => 'profile'}) | 
					
						
							|  |  |  |     if info | 
					
						
							|  |  |  |       first_name = get_attribute_values.detect {|value| value.key.to_s.eql?('first_name') }[I18n.locale.to_s] rescue nil | 
					
						
							|  |  |  |       last_name = get_attribute_values.detect {|value| value.key.to_s.eql?('last_name') }[I18n.locale.to_s] rescue nil | 
					
						
							| 
									
										
										
										
											2011-11-17 12:02:58 +00:00
										 |  |  |       return "#{first_name} #{last_name}" | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       return nil | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2011-12-18 02:07:42 +00:00
										 |  |  |   def get_attribute_values | 
					
						
							| 
									
										
										
										
											2011-12-20 06:35:28 +00:00
										 |  |  |     @attribute_values ||= self.attribute_values | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   def get_value_from_field_id(field_id) | 
					
						
							|  |  |  |     values = get_attribute_values | 
					
						
							|  |  |  |     value = values.detect {|value| value.attribute_field_id == field_id} rescue nil | 
					
						
							|  |  |  |     value ? value : self.attribute_values.build | 
					
						
							| 
									
										
										
										
											2011-12-18 02:07:42 +00:00
										 |  |  |   end | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2011-04-13 10:19:51 +00:00
										 |  |  | end |