diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-05-10 10:54:31 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-05-10 10:54:31 +0000 |
commit | 7dccf9fda6f30d8f4b0c5eaad9f6e2a1e67cd643 (patch) | |
tree | ba6a18abff6ca69af528b3d295263d049a22266f /app/models/member.rb | |
parent | 814e138c2a1105f8d9d10c4362a889dd71aff32d (diff) | |
download | redmine-7dccf9fda6f30d8f4b0c5eaad9f6e2a1e67cd643.tar.gz redmine-7dccf9fda6f30d8f4b0c5eaad9f6e2a1e67cd643.zip |
Allows multiple roles on the same project (#706). Prerequisite for user groups feature.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2726 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/member.rb')
-rw-r--r-- | app/models/member.rb | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/app/models/member.rb b/app/models/member.rb index 5228d1ffc..2dc91cba7 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -1,5 +1,5 @@ -# redMine - project management software -# Copyright (C) 2006 Jean-Philippe Lang +# 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 @@ -17,15 +17,12 @@ class Member < ActiveRecord::Base belongs_to :user - belongs_to :role + has_many :member_roles, :dependent => :delete_all + has_many :roles, :through => :member_roles belongs_to :project - validates_presence_of :role, :user, :project + validates_presence_of :user, :project validates_uniqueness_of :user_id, :scope => :project_id - - def validate - errors.add :role_id, :invalid if role && !role.member? - end def name self.user.name @@ -42,11 +39,18 @@ class Member < ActiveRecord::Base end def <=>(member) - role == member.role ? (user <=> member.user) : (role <=> member.role) + a, b = roles.sort.first, member.roles.sort.first + a == b ? (user <=> member.user) : (a <=> b) end def before_destroy # 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 + + protected + + def validate + errors.add_to_base "Role can't be blank" if roles.empty? + end end |