diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-10-26 22:35:04 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-10-26 22:35:04 +0000 |
commit | bdbfe4f7ba36853f34a2b9db3c5ec8a294c5e2a2 (patch) | |
tree | 8bdf0299b6531313545f4edf8f60339ec1d05770 /app/models/issue_status.rb | |
parent | f33dfe92436eb06b1e7f0d5a2ed28790b8d29c9d (diff) | |
download | redmine-bdbfe4f7ba36853f34a2b9db3c5ec8a294c5e2a2.tar.gz redmine-bdbfe4f7ba36853f34a2b9db3c5ec8a294c5e2a2.zip |
Query IssueStatus model to prevent workflows instanciation.
git-svn-id: http://svn.redmine.org/redmine/trunk@13516 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/issue_status.rb')
-rw-r--r-- | app/models/issue_status.rb | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/app/models/issue_status.rb b/app/models/issue_status.rb index ba0624a04..b9fccdb99 100644 --- a/app/models/issue_status.rb +++ b/app/models/issue_status.rb @@ -18,6 +18,7 @@ class IssueStatus < ActiveRecord::Base before_destroy :check_integrity has_many :workflows, :class_name => 'WorkflowTransition', :foreign_key => "old_status_id" + has_many :workflow_transitions_as_new_status, :class_name => 'WorkflowTransition', :foreign_key => "new_status_id" acts_as_list before_destroy :delete_workflow_rules @@ -72,16 +73,19 @@ class IssueStatus < ActiveRecord::Base # More efficient than the previous method if called just once def find_new_statuses_allowed_to(roles, tracker, author=false, assignee=false) if roles.present? && tracker - conditions = "(author = :false AND assignee = :false)" - conditions << " OR author = :true" if author - conditions << " OR assignee = :true" if assignee - - workflows. - includes(:new_status). - where(["role_id IN (:role_ids) AND tracker_id = :tracker_id AND (#{conditions})", - {:role_ids => roles.collect(&:id), :tracker_id => tracker.id, :true => true, :false => false} - ]).to_a. - map(&:new_status).compact.sort + scope = IssueStatus. + joins(:workflow_transitions_as_new_status). + where(:workflows => {:old_status_id => id, :role_id => roles.map(&:id), :tracker_id => tracker.id}) + + unless author && assignee + if author || assignee + scope = scope.where("author = ? OR assignee = ?", author, assignee) + else + scope = scope.where("author = ? AND assignee = ?", false, false) + end + end + + scope.uniq.to_a.sort else [] end |