1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-01-09 17:11:32 +00:00

Query IssueStatus model to prevent workflows instanciation.

git-svn-id: http://svn.redmine.org/redmine/trunk@13516 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2014-10-26 22:35:04 +00:00
parent f33dfe9243
commit bdbfe4f7ba

View File

@ -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
scope = IssueStatus.
joins(:workflow_transitions_as_new_status).
where(:workflows => {:old_status_id => id, :role_id => roles.map(&:id), :tracker_id => tracker.id})
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
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