Class UserGroup
In: app/models/user_group.rb
Parent: ActiveRecord::Base

Users can be members of UserGroups.

UserGroups are used to handle Restrictions, and they are seperate from PeerGroups.

Methods

Included Modules

HomePageModule

Public Class methods

[Source]

    # File app/models/user_group.rb, line 77
77:   def self.all_names
78:     self.find(:all, :select => 'name').collect {|u_g| u_g.name}
79:   end

Other

[Source]

    # File app/models/user_group.rb, line 71
71:   def self.paginate(options)
72:     paginate_by_sql('SELECT u_g.* FROM user_groups AS u_g' +
73:         ' LEFT JOIN users AS u ON u_g.id = u.personal_user_group_id' +
74:         ' WHERE u.id IS NULL', options)
75:   end

Returns the public user_group.

[Source]

    # File app/models/user_group.rb, line 65
65:   def self.public
66:     return GlobalConfig.public_user_group
67:   end

Returns the system user_group.

[Source]

    # File app/models/user_group.rb, line 59
59:   def self.system
60:     return GlobalConfig.system_user_group
61:   end

Public Instance methods

Returns the admin-user of this UserGroup.

[Source]

     # File app/models/user_group.rb, line 121
121:   def admin
122:     self.admin_membership.user
123:   end

Returns the membership of the admin of this UserGroup.

[Source]

     # File app/models/user_group.rb, line 127
127:   def admin_membership
128:     self.memberships.find_by_role(Const::UserGroupMembership::ADMIN)
129:   end

Checks if the given user has the admin-role.

[Source]

     # File app/models/user_group.rb, line 115
115:   def admin_permissions?(user)
116:     user == self.admin or user.admin?
117:   end

Returns the link to the user_groups homepage.

[Source]

     # File app/models/user_group.rb, line 133
133:   def home_page_link
134:     return self.home_page_link_for(Tag.user_group)
135:   end

Checks if the given user is a member.

[Source]

     # File app/models/user_group.rb, line 109
109:   def member?(user)
110:     self.memberships.detect_by_user(user)
111:   end

Returns the membership of this UserGroup for the given user.

If it doesn‘t exist yet it is built.

[Source]

     # File app/models/user_group.rb, line 99
 99:   def membership_for(user)
100:     membership = self.memberships.find_by_user_id(user.id)
101:     if membership.nil?
102:       membership = self.memberships.build(:user => user)
103:     end
104:     return membership
105:   end

Returns true if this is a personal usergroup.

[Source]

    # File app/models/user_group.rb, line 91
91:   def personal?
92:     return self.personal_user
93:   end

Returns true if this UserGroup is the public usergroup

[Source]

    # File app/models/user_group.rb, line 85
85:   def public?
86:     return self == UserGroup.public
87:   end

Protected Instance methods

Makes the current user or the personal_user admin.

[Source]

     # File app/models/user_group.rb, line 143
143:   def create_admin_membership_if_personal
144:     if self.personal?
145:       self.memberships.create(:user => self.personal_user,
146:           :role => Const::UserGroupMembership::ADMIN)
147:       self.admin.personal_user_group = self
148:     end
149:     return true
150:   end

Creates a home-page for this UserGroup.

[Source]

     # File app/models/user_group.rb, line 154
154:   def create_home_page
155:     if !self.personal?
156:       # see HomePageModule
157:       self.create_home_page_for(Tag.user_group, :creator => self.admin,
158:           :user_group => self,
159:           :title => t('m.user_group.home_title', :name => self.name),
160:           :body => '<p>' + t('m.user_group.home_body', :name => self.name) + 
161:               '</p>',
162:           :kind => Const::Logi::KINDS[:user_group])
163:     end
164:     return true
165:   end

Destroys the home page of the user_group.

[Source]

     # File app/models/user_group.rb, line 201
201:   def destroy_home_pages_if_not_personal
202:     if !self.personal?
203:       self.destroy_home_pages_for(Tag.user_group)
204:       # see the HomePageModule
205:     end
206:     return true
207:   end

Destroys all memberships.

[Source]

     # File app/models/user_group.rb, line 190
190:   def destroy_memberships_if_not_personal
191:     if !self.personal?
192:       self.memberships.each do |membership|
193:         membership.destroy
194:       end
195:     end
196:     return true
197:   end

Resets the user-groups of the associated logis to the public_user_group.

[Source]

     # File app/models/user_group.rb, line 180
180:   def reset_logis
181:     self.logis.each do |logi|
182:       logi.user_group = UserGroup.public
183:       logi.save
184:     end
185:     return true
186:   end

Sets the user_group back to the public_user_group

[Source]

     # File app/models/user_group.rb, line 169
169:   def reset_prefs_profiles
170:     self.prefs_profiles.each do |prefs_profile|
171:       prefs_profile.user_group = UserGroup.public
172:       prefs_profile.save
173:     end
174:     return true
175:   end

[Validate]