@@ -58,8 +58,7 class IssueStatus < ActiveRecord::Base | |||||
58 | transitions = workflows.select do |w| |
|
58 | transitions = workflows.select do |w| | |
59 | role_ids.include?(w.role_id) && |
|
59 | role_ids.include?(w.role_id) && | |
60 | w.tracker_id == tracker.id && |
|
60 | w.tracker_id == tracker.id && | |
61 | (author || !w.author) && |
|
61 | ((!w.author && !w.assignee) || (author && w.author) || (assignee && w.assignee)) | |
62 | (assignee || !w.assignee) |
|
|||
63 | end |
|
62 | end | |
64 | transitions.collect{|w| w.new_status}.compact.sort |
|
63 | transitions.collect{|w| w.new_status}.compact.sort | |
65 | else |
|
64 | else | |
@@ -70,14 +69,17 class IssueStatus < ActiveRecord::Base | |||||
70 | # Same thing as above but uses a database query |
|
69 | # Same thing as above but uses a database query | |
71 | # More efficient than the previous method if called just once |
|
70 | # More efficient than the previous method if called just once | |
72 | def find_new_statuses_allowed_to(roles, tracker, author=false, assignee=false) |
|
71 | def find_new_statuses_allowed_to(roles, tracker, author=false, assignee=false) | |
73 | if roles && tracker |
|
72 | if roles.present? && tracker | |
74 | conditions = {:role_id => roles.collect(&:id), :tracker_id => tracker.id} |
|
73 | conditions = "(author = :false AND assignee = :false)" | |
75 | conditions[:author] = false unless author |
|
74 | conditions << " OR author = :true" if author | |
76 | conditions[:assignee] = false unless assignee |
|
75 | conditions << " OR assignee = :true" if assignee | |
77 |
|
76 | |||
78 | workflows.find(:all, |
|
77 | workflows.find(:all, | |
79 |
|
|
78 | :include => :new_status, | |
80 | :conditions => conditions).collect{|w| w.new_status}.compact.sort |
|
79 | :conditions => ["role_id IN (:role_ids) AND tracker_id = :tracker_id AND (#{conditions})", | |
|
80 | {:role_ids => roles.collect(&:id), :tracker_id => tracker.id, :true => true, :false => false} | |||
|
81 | ] | |||
|
82 | ).collect{|w| w.new_status}.compact.sort | |||
81 | else |
|
83 | else | |
82 | [] |
|
84 | [] | |
83 | end |
|
85 | end |
@@ -83,11 +83,11 class IssueStatusTest < ActiveSupport::TestCase | |||||
83 | assert_equal [2], status.new_statuses_allowed_to([role], tracker, false, false).map(&:id) |
|
83 | assert_equal [2], status.new_statuses_allowed_to([role], tracker, false, false).map(&:id) | |
84 | assert_equal [2], status.find_new_statuses_allowed_to([role], tracker, false, false).map(&:id) |
|
84 | assert_equal [2], status.find_new_statuses_allowed_to([role], tracker, false, false).map(&:id) | |
85 |
|
85 | |||
86 | assert_equal [2, 3], status.new_statuses_allowed_to([role], tracker, true, false).map(&:id) |
|
86 | assert_equal [2, 3, 5], status.new_statuses_allowed_to([role], tracker, true, false).map(&:id) | |
87 | assert_equal [2, 3], status.find_new_statuses_allowed_to([role], tracker, true, false).map(&:id) |
|
87 | assert_equal [2, 3, 5], status.find_new_statuses_allowed_to([role], tracker, true, false).map(&:id) | |
88 |
|
88 | |||
89 | assert_equal [2, 4], status.new_statuses_allowed_to([role], tracker, false, true).map(&:id) |
|
89 | assert_equal [2, 4, 5], status.new_statuses_allowed_to([role], tracker, false, true).map(&:id) | |
90 | assert_equal [2, 4], status.find_new_statuses_allowed_to([role], tracker, false, true).map(&:id) |
|
90 | assert_equal [2, 4, 5], status.find_new_statuses_allowed_to([role], tracker, false, true).map(&:id) | |
91 |
|
91 | |||
92 | assert_equal [2, 3, 4, 5], status.new_statuses_allowed_to([role], tracker, true, true).map(&:id) |
|
92 | assert_equal [2, 3, 4, 5], status.new_statuses_allowed_to([role], tracker, true, true).map(&:id) | |
93 | assert_equal [2, 3, 4, 5], status.find_new_statuses_allowed_to([role], tracker, true, true).map(&:id) |
|
93 | assert_equal [2, 3, 4, 5], status.find_new_statuses_allowed_to([role], tracker, true, true).map(&:id) |
General Comments 0
You need to be logged in to leave comments.
Login now