summaryrefslogtreecommitdiffstats
path: root/app/controllers/workflows_controller.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2014-02-25 02:54:47 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2014-02-25 02:54:47 +0000
commitb6c794d16b47bf353a1a2dfc00e9cbd078525ee8 (patch)
tree7dec97be4c38b4e3b6321f7c55b81697ca6f5ee2 /app/controllers/workflows_controller.rb
parentc6f71f727bc73188ce7285c6e19bf50553246ec7 (diff)
downloadredmine-b6c794d16b47bf353a1a2dfc00e9cbd078525ee8.tar.gz
redmine-b6c794d16b47bf353a1a2dfc00e9cbd078525ee8.zip
Bulk edit workflows for multiple trackers/roles (#16164).
git-svn-id: http://svn.redmine.org/redmine/trunk@12924 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers/workflows_controller.rb')
-rw-r--r--app/controllers/workflows_controller.rb103
1 files changed, 57 insertions, 46 deletions
diff --git a/app/controllers/workflows_controller.rb b/app/controllers/workflows_controller.rb
index 596462cbd..0a9600cba 100644
--- a/app/controllers/workflows_controller.rb
+++ b/app/controllers/workflows_controller.rb
@@ -18,40 +18,30 @@
class WorkflowsController < ApplicationController
layout 'admin'
- before_filter :require_admin, :find_roles, :find_trackers
+ before_filter :require_admin
def index
@workflow_counts = WorkflowTransition.count_by_tracker_and_role
end
def edit
- @role = Role.find_by_id(params[:role_id]) if params[:role_id]
- @tracker = Tracker.find_by_id(params[:tracker_id]) if params[:tracker_id]
+ find_trackers_roles_and_statuses_for_edit
- if request.post?
- WorkflowTransition.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
- (params[:issue_status] || []).each { |status_id, transitions|
- transitions.each { |new_status_id, options|
- author = options.is_a?(Array) && options.include?('author') && !options.include?('always')
- assignee = options.is_a?(Array) && options.include?('assignee') && !options.include?('always')
- WorkflowTransition.create(:role_id => @role.id, :tracker_id => @tracker.id, :old_status_id => status_id, :new_status_id => new_status_id, :author => author, :assignee => assignee)
- }
- }
- if @role.save
- flash[:notice] = l(:notice_successful_update)
- redirect_to workflows_edit_path(:role_id => @role, :tracker_id => @tracker, :used_statuses_only => params[:used_statuses_only])
- return
+ if request.post? && @roles && @trackers && params[:transitions]
+ transitions = params[:transitions].deep_dup
+ 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.reject! {|rule, transition| transition == 'no_change'}
+ end
end
+ WorkflowTransition.replace_transitions(@trackers, @roles, transitions)
+ flash[:notice] = l(:notice_successful_update)
+ redirect_to_referer_or workflows_edit_path
+ return
end
- @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
- if @tracker && @used_statuses_only && @tracker.issue_statuses.any?
- @statuses = @tracker.issue_statuses
- end
- @statuses ||= IssueStatus.sorted.all
-
- if @tracker && @role && @statuses.any?
- workflows = WorkflowTransition.where(:role_id => @role.id, :tracker_id => @tracker.id).all
+ if @trackers && @roles && @statuses.any?
+ workflows = WorkflowTransition.where(:role_id => @roles.map(&:id), :tracker_id => @trackers.map(&:id)).all
@workflows = {}
@workflows['always'] = workflows.select {|w| !w.author && !w.assignee}
@workflows['author'] = workflows.select {|w| w.author}
@@ -60,36 +50,31 @@ class WorkflowsController < ApplicationController
end
def permissions
- @role = Role.find_by_id(params[:role_id]) if params[:role_id]
- @tracker = Tracker.find_by_id(params[:tracker_id]) if params[:tracker_id]
+ find_trackers_roles_and_statuses_for_edit
- if request.post? && @role && @tracker
- WorkflowPermission.replace_permissions(@tracker, @role, params[:permissions] || {})
+ if request.post? && @roles && @trackers && params[:permissions]
+ permissions = params[:permissions].deep_dup
+ permissions.each { |field, rule_by_status_id|
+ rule_by_status_id.reject! {|status_id, rule| rule == 'no_change'}
+ }
+ WorkflowPermission.replace_permissions(@trackers, @roles, permissions)
flash[:notice] = l(:notice_successful_update)
- redirect_to workflows_permissions_path(:role_id => @role, :tracker_id => @tracker, :used_statuses_only => params[:used_statuses_only])
+ redirect_to_referer_or workflows_permissions_path
return
end
- @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
- if @tracker && @used_statuses_only && @tracker.issue_statuses.any?
- @statuses = @tracker.issue_statuses
- end
- @statuses ||= IssueStatus.sorted.all
-
- if @role && @tracker
- @fields = (Tracker::CORE_FIELDS_ALL - @tracker.disabled_core_fields).map {|field| [field, l("field_"+field.sub(/_id$/, ''))]}
- @custom_fields = @tracker.custom_fields
- @permissions = WorkflowPermission.
- where(:tracker_id => @tracker.id, :role_id => @role.id).inject({}) do |h, w|
- h[w.old_status_id] ||= {}
- h[w.old_status_id][w.field_name] = w.rule
- h
- end
+ if @roles && @trackers
+ @fields = (Tracker::CORE_FIELDS_ALL - @trackers.map(&:disabled_core_fields).reduce(:&)).map {|field| [field, l("field_"+field.sub(/_id$/, ''))]}
+ @custom_fields = @trackers.map(&:custom_fields).flatten.uniq.sort
+ @permissions = WorkflowPermission.rules_by_status_id(@trackers, @roles)
@statuses.each {|status| @permissions[status.id] ||= {}}
end
end
def copy
+ @roles = Role.sorted
+ @trackers = Tracker.sorted
+
if params[:source_tracker_id].blank? || params[:source_tracker_id] == 'any'
@source_tracker = nil
else
@@ -119,11 +104,37 @@ class WorkflowsController < ApplicationController
private
+ def find_trackers_roles_and_statuses_for_edit
+ find_roles
+ find_trackers
+ find_statuses
+ end
+
def find_roles
- @roles = Role.sorted.all
+ ids = Array.wrap(params[:role_id])
+ if ids == ['all']
+ @roles = Role.sorted.all
+ elsif ids.present?
+ @roles = Role.where(:id => ids).all
+ end
+ @roles = nil if @roles.blank?
end
def find_trackers
- @trackers = Tracker.sorted.all
+ ids = Array.wrap(params[:tracker_id])
+ if ids == ['all']
+ @trackers = Tracker.sorted.all
+ elsif ids.present?
+ @trackers = Tracker.where(:id => ids).all
+ end
+ @trackers = nil if @trackers.blank?
+ end
+
+ def find_statuses
+ @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
+ if @trackers && @used_statuses_only
+ @statuses = @trackers.map(&:issue_statuses).flatten.uniq.sort.presence
+ end
+ @statuses ||= IssueStatus.sorted.all
end
end