Class: Member
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Member
- Defined in:
- app/models/member.rb
Overview
Redmine - project management software Copyright (C) 2006-2009 Jean-Philippe Lang
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Class Method Summary
-
+ (Object) edit_membership(id, new_attributes, principal = nil)
Find or initilize a Member with an id, attributes, and for a Principal.
Instance Method Summary
- - (Object) <=>(member)
- - (Object) before_destroy
- - (Boolean) deletable?
- - (Boolean) include?(user)
- - (Object) name
- - (Object) role_ids(arg) (also: #base_role_ids=)
Methods inherited from ActiveRecord::Base
Class Method Details
+ (Object) edit_membership(id, new_attributes, principal = nil)
Find or initilize a Member with an id, attributes, and for a Principal
76 77 78 79 80 |
# File 'app/models/member.rb', line 76 def self.edit_membership(id, new_attributes, principal=nil) @membership = id.present? ? Member.find(id) : Member.new(:principal => principal) @membership.attributes = new_attributes @membership end |
Instance Method Details
- (Object) <=>(member)
51 52 53 54 |
# File 'app/models/member.rb', line 51 def <=>(member) a, b = roles.sort.first, member.roles.sort.first a == b ? (principal <=> member.principal) : (a <=> b) end |
- (Object) before_destroy
68 69 70 71 72 73 |
# File 'app/models/member.rb', line 68 def before_destroy if user # remove category based auto assignments for this member IssueCategory.update_all "assigned_to_id = NULL", ["project_id = ? AND assigned_to_id = ?", project.id, user.id] end end |
- (Boolean) deletable?
56 57 58 |
# File 'app/models/member.rb', line 56 def deletable? member_roles.detect {|mr| mr.inherited_from}.nil? end |
- (Boolean) include?(user)
60 61 62 63 64 65 66 |
# File 'app/models/member.rb', line 60 def include?(user) if principal.is_a?(Group) !user.nil? && user.groups.include?(principal) else self.user == user end end |
- (Object) name
30 31 32 |
# File 'app/models/member.rb', line 30 def name self.user.name end |
- (Object) role_ids=(arg) Also known as: base_role_ids=
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/member.rb', line 35 def role_ids=(arg) ids = (arg || []).collect(&:to_i) - [0] # Keep inherited roles ids += member_roles.select {|mr| !mr.inherited_from.nil?}.collect(&:role_id) new_role_ids = ids - role_ids # Add new roles new_role_ids.each {|id| member_roles << MemberRole.new(:role_id => id) } # Remove roles (Rails' #role_ids= will not trigger MemberRole#on_destroy) member_roles_to_destroy = member_roles.select {|mr| !ids.include?(mr.role_id)} if member_roles_to_destroy.any? member_roles_to_destroy.each(&:destroy) end end |