| 25 |
25 |
roles = Array.wrap roles
|
| 26 |
26 |
|
| 27 |
27 |
transaction do
|
| 28 |
|
records = WorkflowTransition.where(:tracker_id => trackers.map(&:id), :role_id => roles.map(&:id)).to_a
|
|
28 |
records_by_status_and_scope =
|
|
29 |
WorkflowTransition.where(:tracker_id => trackers.map(&:id), :role_id => roles.map(&:id))
|
|
30 |
.to_a
|
|
31 |
.group_by {|r| [r.old_status_id, r.new_status_id, r.tracker_id, r.role_id]}
|
| 29 |
32 |
|
| 30 |
33 |
transitions.each do |old_status_id, transitions_by_new_status|
|
| 31 |
34 |
transitions_by_new_status.each do |new_status_id, transition_by_rule|
|
|
35 |
old_status_id = old_status_id.to_i
|
|
36 |
new_status_id = new_status_id.to_i
|
|
37 |
|
| 32 |
38 |
transition_by_rule.each do |rule, transition|
|
| 33 |
39 |
trackers.each do |tracker|
|
| 34 |
40 |
roles.each do |role|
|
| 35 |
|
w = records.select do |r|
|
| 36 |
|
r.old_status_id == old_status_id.to_i &&
|
| 37 |
|
r.new_status_id == new_status_id.to_i &&
|
| 38 |
|
r.tracker_id == tracker.id &&
|
| 39 |
|
r.role_id == role.id &&
|
| 40 |
|
!r.destroyed?
|
| 41 |
|
end
|
|
41 |
key = [old_status_id, new_status_id, tracker.id, role.id]
|
|
42 |
w = records_by_status_and_scope[key].to_a
|
|
43 |
w = w.select {|r| !r.destroyed?}
|
| 42 |
44 |
if rule == 'always'
|
| 43 |
45 |
w = w.select {|r| !r.author && !r.assignee}
|
| 44 |
46 |
else
|
| ... | ... | |
| 58 |
60 |
:tracker_id => tracker.id,
|
| 59 |
61 |
:role_id => role.id
|
| 60 |
62 |
)
|
| 61 |
|
records << w
|
|
63 |
records_by_status_and_scope[key] ||= []
|
|
64 |
records_by_status_and_scope[key] << w
|
| 62 |
65 |
end
|
| 63 |
66 |
w.author = true if rule == "author"
|
| 64 |
67 |
w.assignee = true if rule == "assignee"
|