##// END OF EJS Templates
Query IssueStatus model to prevent workflows instanciation....
Jean-Philippe Lang -
r13134:bdbfe4f7ba36
parent child
Show More
@@ -18,6 +18,7
18 18 class IssueStatus < ActiveRecord::Base
19 19 before_destroy :check_integrity
20 20 has_many :workflows, :class_name => 'WorkflowTransition', :foreign_key => "old_status_id"
21 has_many :workflow_transitions_as_new_status, :class_name => 'WorkflowTransition', :foreign_key => "new_status_id"
21 22 acts_as_list
22 23
23 24 before_destroy :delete_workflow_rules
@@ -72,16 +73,19 class IssueStatus < ActiveRecord::Base
72 73 # More efficient than the previous method if called just once
73 74 def find_new_statuses_allowed_to(roles, tracker, author=false, assignee=false)
74 75 if roles.present? && tracker
75 conditions = "(author = :false AND assignee = :false)"
76 conditions << " OR author = :true" if author
77 conditions << " OR assignee = :true" if assignee
78
79 workflows.
80 includes(:new_status).
81 where(["role_id IN (:role_ids) AND tracker_id = :tracker_id AND (#{conditions})",
82 {:role_ids => roles.collect(&:id), :tracker_id => tracker.id, :true => true, :false => false}
83 ]).to_a.
84 map(&:new_status).compact.sort
76 scope = IssueStatus.
77 joins(:workflow_transitions_as_new_status).
78 where(:workflows => {:old_status_id => id, :role_id => roles.map(&:id), :tracker_id => tracker.id})
79
80 unless author && assignee
81 if author || assignee
82 scope = scope.where("author = ? OR assignee = ?", author, assignee)
83 else
84 scope = scope.where("author = ? AND assignee = ?", false, false)
85 end
86 end
87
88 scope.uniq.to_a.sort
85 89 else
86 90 []
87 91 end
General Comments 0
You need to be logged in to leave comments. Login now