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/issue_status.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/issue_status.rb')
-rw-r--r-- | app/models/issue_status.rb | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/app/models/issue_status.rb b/app/models/issue_status.rb index 16c7bce91..ca33d37d6 100644 --- a/app/models/issue_status.rb +++ b/app/models/issue_status.rb @@ -36,24 +36,34 @@ class IssueStatus < ActiveRecord::Base # Returns an array of all statuses the given role can switch to # Uses association cache when called more than one time - def new_statuses_allowed_to(role, tracker) - new_statuses = workflows.select {|w| w.role_id == role.id && w.tracker_id == tracker.id}.collect{|w| w.new_status} if role && tracker - new_statuses ? new_statuses.compact.sort{|x, y| x.position <=> y.position } : [] + def new_statuses_allowed_to(roles, tracker) + if roles && tracker + role_ids = roles.collect(&:id) + new_statuses = workflows.select {|w| role_ids.include?(w.role_id) && w.tracker_id == tracker.id}.collect{|w| w.new_status}.compact.sort + else + [] + end end # Same thing as above but uses a database query # More efficient than the previous method if called just once - def find_new_statuses_allowed_to(role, tracker) - new_statuses = workflows.find(:all, - :include => :new_status, - :conditions => ["role_id=? and tracker_id=?", role.id, tracker.id]).collect{ |w| w.new_status }.compact if role && tracker - new_statuses ? new_statuses.sort{|x, y| x.position <=> y.position } : [] + def find_new_statuses_allowed_to(roles, tracker) + if roles && tracker + workflows.find(:all, + :include => :new_status, + :conditions => { :role_id => roles.collect(&:id), + :tracker_id => tracker.id}).collect{ |w| w.new_status }.compact.sort + else + [] + end end - def new_status_allowed_to?(status, role, tracker) - status && role && tracker ? - !workflows.find(:first, :conditions => {:new_status_id => status.id, :role_id => role.id, :tracker_id => tracker.id}).nil? : + def new_status_allowed_to?(status, roles, tracker) + if status && roles && tracker + !workflows.find(:first, :conditions => {:new_status_id => status.id, :role_id => roles.collect(&:id), :tracker_id => tracker.id}).nil? + else false + end end def <=>(status) |