# Redmine - project management software
-# Copyright (C) 2006-2009 Jean-Philippe Lang
+# Copyright (C) 2006-2011 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.
validates_uniqueness_of :user_id, :scope => :project_id
after_destroy :unwatch_from_permission_change
-
+
def name
self.user.name
end
-
+
alias :base_role_ids= :role_ids=
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) }
unwatch_from_permission_change
end
end
-
+
def <=>(member)
a, b = roles.sort.first, member.roles.sort.first
a == b ? (principal <=> member.principal) : (a <=> b)
end
-
+
def deletable?
member_roles.detect {|mr| mr.inherited_from}.nil?
end
-
+
def include?(user)
if principal.is_a?(Group)
!user.nil? && user.groups.include?(principal)
self.user == user
end
end
-
+
def before_destroy
if user
# remove category based auto assignments for this member
@membership.attributes = new_attributes
@membership
end
-
+
protected
-
+
def validate
errors.add_on_empty :role if member_roles.empty? && roles.empty?
end
-
+
private
-
+
# Unwatch things that the user is no longer allowed to view inside project
def unwatch_from_permission_change
if user