| Class | Person |
| In: |
app/models/person.rb
|
| Parent: | Profile |
A person is the profile of an user holding all relationships with the rest of the system
# File app/models/person.rb, line 32
32: def self.conditions_for_profiles(conditions, person)
33: new_conditions = sanitize_sql(['role_assignments.accessor_id = ?', person])
34: new_conditions << ' AND ' + sanitize_sql(conditions) unless conditions.blank?
35: new_conditions
36: end
# File app/models/person.rb, line 17
17: def add_friend(friend, group = nil)
18: self.friendships.build(:friend => friend, :group => group).save!
19: end
# File app/models/person.rb, line 21
21: def already_request_friendship?(person)
22: person.tasks.find_by_requestor_id(self.id, :conditions => { :type => 'AddFriend' })
23: end
# File app/models/person.rb, line 52
52: def community_memberships
53: memberships(:type => Community.name)
54: end
# File app/models/person.rb, line 81
81: def default_set_of_blocks
82: [
83: [MainBlock],
84: [ProfileInfoBlock, RecentDocumentsBlock, TagsBlock],
85: [FriendsBlock, EnterprisesBlock, CommunitiesBlock]
86: ]
87: end
# File app/models/person.rb, line 104
104: def display_info_to?(user)
105: if friends.include?(user)
106: true
107: else
108: super
109: end
110: end
# File app/models/person.rb, line 61
61: def email
62: self.user.nil? ? nil : self.user.email
63: end
# File app/models/person.rb, line 65
65: def email= (email)
66: self.user.email = email if ! self.user.nil?
67: end
# File app/models/person.rb, line 99
99: def email_addresses
100: # TODO for now, only one e-mail address
101: ['%s@%s' % [self.identifier, self.environment.default_hostname(true) ] ]
102: end
# File app/models/person.rb, line 46
46: def enterprise_memberships
47: memberships(:type => Enterprise.name)
48: end
# File app/models/person.rb, line 13
13: def friend_groups
14: friendships.map { |item| item.group }.uniq
15: end
# File app/models/person.rb, line 73
73: def is_admin?
74: role_assignments.map{|ra|ra.role.permissions}.any? do |ps|
75: ps.any? do |p|
76: ActiveRecord::Base::PERMISSIONS['Environment'].keys.include?(p)
77: end
78: end
79: end
# File app/models/person.rb, line 38
38: def memberships(conditions = {})
39: Profile.find(
40: :all,
41: :conditions => self.class.conditions_for_profiles(conditions, self),
42: :joins => "LEFT JOIN role_assignments ON profiles.id = role_assignments.resource_id AND role_assignments.resource_type = \'#{Profile.base_class.name}\'",
43: :select => 'profiles.*').uniq
44: end
# File app/models/person.rb, line 89
89: def name
90: if !self[:name].blank?
91: self[:name]
92: else
93: self.user ? self.user.login : nil
94: end
95: end
# File app/models/person.rb, line 25
25: def remove_friend(friend)
26: friends.delete(friend)
27: end
# File app/models/person.rb, line 9
9: def suggested_friend_groups
10: (friend_groups + [ _('friends'), _('work'), _('school'), _('family') ]).map {|i| i if !i.empty?}.compact.uniq
11: end