mirror of
https://github.com/redmine/redmine.git
synced 2025-11-09 14:56:01 +01:00
Bulk edit workflows for multiple trackers/roles (#16164).
git-svn-id: http://svn.redmine.org/redmine/trunk@12924 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -36,4 +36,69 @@ class WorkflowTransition < WorkflowRule
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
def self.replace_transitions(trackers, roles, transitions)
|
||||
trackers = Array.wrap trackers
|
||||
roles = Array.wrap roles
|
||||
|
||||
transaction do
|
||||
records = WorkflowTransition.where(:tracker_id => trackers.map(&:id), :role_id => roles.map(&:id)).all
|
||||
|
||||
transitions.each do |old_status_id, transitions_by_new_status|
|
||||
transitions_by_new_status.each do |new_status_id, transition_by_rule|
|
||||
transition_by_rule.each do |rule, transition|
|
||||
trackers.each do |tracker|
|
||||
roles.each do |role|
|
||||
w = records.select {|r|
|
||||
r.old_status_id == old_status_id.to_i &&
|
||||
r.new_status_id == new_status_id.to_i &&
|
||||
r.tracker_id == tracker.id &&
|
||||
r.role_id == role.id &&
|
||||
!r.destroyed?
|
||||
}
|
||||
|
||||
if rule == 'always'
|
||||
w = w.select {|r| !r.author && !r.assignee}
|
||||
else
|
||||
w = w.select {|r| r.author || r.assignee}
|
||||
end
|
||||
if w.size > 1
|
||||
w[1..-1].each(&:destroy)
|
||||
end
|
||||
w = w.first
|
||||
|
||||
if transition == "1" || transition == true
|
||||
unless w
|
||||
w = WorkflowTransition.new(:old_status_id => old_status_id, :new_status_id => new_status_id, :tracker_id => tracker.id, :role_id => role.id)
|
||||
records << w
|
||||
end
|
||||
w.author = true if rule == "author"
|
||||
w.assignee = true if rule == "assignee"
|
||||
w.save if w.changed?
|
||||
elsif w
|
||||
if rule == 'always'
|
||||
w.destroy
|
||||
elsif rule == 'author'
|
||||
if w.assignee
|
||||
w.author = false
|
||||
w.save if w.changed?
|
||||
else
|
||||
w.destroy
|
||||
end
|
||||
elsif rule == 'assignee'
|
||||
if w.author
|
||||
w.assignee = false
|
||||
w.save if w.changed?
|
||||
else
|
||||
w.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user