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
# 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