annotate app/controllers/workflows_controller.rb @ 1628:9c5f8e24dadc live tip

Quieten this cron script
author Chris Cannam
date Tue, 25 Aug 2020 11:38:49 +0100
parents dffacf8a6908
children
rev   line source
Chris@0 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@0 18 class WorkflowsController < ApplicationController
Chris@0 19 layout 'admin'
Chris@909 20
Chris@1115 21 before_filter :require_admin, :find_roles, :find_trackers
Chris@909 22
Chris@0 23 def index
Chris@1115 24 @workflow_counts = WorkflowTransition.count_by_tracker_and_role
Chris@0 25 end
Chris@909 26
Chris@0 27 def edit
Chris@1115 28 @role = Role.find_by_id(params[:role_id]) if params[:role_id]
Chris@1115 29 @tracker = Tracker.find_by_id(params[:tracker_id]) if params[:tracker_id]
Chris@909 30
Chris@0 31 if request.post?
Chris@1115 32 WorkflowTransition.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
Chris@245 33 (params[:issue_status] || []).each { |status_id, transitions|
Chris@245 34 transitions.each { |new_status_id, options|
Chris@245 35 author = options.is_a?(Array) && options.include?('author') && !options.include?('always')
Chris@245 36 assignee = options.is_a?(Array) && options.include?('assignee') && !options.include?('always')
Chris@1115 37 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)
Chris@0 38 }
Chris@0 39 }
Chris@0 40 if @role.save
Chris@1517 41 flash[:notice] = l(:notice_successful_update)
Chris@1464 42 redirect_to workflows_edit_path(:role_id => @role, :tracker_id => @tracker, :used_statuses_only => params[:used_statuses_only])
Chris@245 43 return
Chris@0 44 end
Chris@0 45 end
Chris@909 46
Chris@0 47 @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
Chris@0 48 if @tracker && @used_statuses_only && @tracker.issue_statuses.any?
Chris@0 49 @statuses = @tracker.issue_statuses
Chris@0 50 end
Chris@1115 51 @statuses ||= IssueStatus.sorted.all
Chris@909 52
Chris@245 53 if @tracker && @role && @statuses.any?
Chris@1115 54 workflows = WorkflowTransition.where(:role_id => @role.id, :tracker_id => @tracker.id).all
Chris@245 55 @workflows = {}
Chris@245 56 @workflows['always'] = workflows.select {|w| !w.author && !w.assignee}
Chris@245 57 @workflows['author'] = workflows.select {|w| w.author}
Chris@245 58 @workflows['assignee'] = workflows.select {|w| w.assignee}
Chris@245 59 end
Chris@0 60 end
Chris@909 61
Chris@1115 62 def permissions
Chris@1115 63 @role = Role.find_by_id(params[:role_id]) if params[:role_id]
Chris@1115 64 @tracker = Tracker.find_by_id(params[:tracker_id]) if params[:tracker_id]
Chris@1115 65
Chris@1115 66 if request.post? && @role && @tracker
Chris@1115 67 WorkflowPermission.replace_permissions(@tracker, @role, params[:permissions] || {})
Chris@1517 68 flash[:notice] = l(:notice_successful_update)
Chris@1464 69 redirect_to workflows_permissions_path(:role_id => @role, :tracker_id => @tracker, :used_statuses_only => params[:used_statuses_only])
Chris@1115 70 return
Chris@1115 71 end
Chris@1115 72
Chris@1115 73 @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
Chris@1115 74 if @tracker && @used_statuses_only && @tracker.issue_statuses.any?
Chris@1115 75 @statuses = @tracker.issue_statuses
Chris@1115 76 end
Chris@1115 77 @statuses ||= IssueStatus.sorted.all
Chris@1115 78
Chris@1115 79 if @role && @tracker
Chris@1115 80 @fields = (Tracker::CORE_FIELDS_ALL - @tracker.disabled_core_fields).map {|field| [field, l("field_"+field.sub(/_id$/, ''))]}
Chris@1115 81 @custom_fields = @tracker.custom_fields
Chris@1517 82 @permissions = WorkflowPermission.
Chris@1517 83 where(:tracker_id => @tracker.id, :role_id => @role.id).inject({}) do |h, w|
Chris@1115 84 h[w.old_status_id] ||= {}
Chris@1115 85 h[w.old_status_id][w.field_name] = w.rule
Chris@1115 86 h
Chris@1115 87 end
Chris@1115 88 @statuses.each {|status| @permissions[status.id] ||= {}}
Chris@1115 89 end
Chris@1115 90 end
Chris@1115 91
Chris@0 92 def copy
Chris@0 93 if params[:source_tracker_id].blank? || params[:source_tracker_id] == 'any'
Chris@0 94 @source_tracker = nil
Chris@0 95 else
Chris@0 96 @source_tracker = Tracker.find_by_id(params[:source_tracker_id].to_i)
Chris@0 97 end
Chris@0 98 if params[:source_role_id].blank? || params[:source_role_id] == 'any'
Chris@0 99 @source_role = nil
Chris@0 100 else
Chris@0 101 @source_role = Role.find_by_id(params[:source_role_id].to_i)
Chris@0 102 end
Chris@1517 103 @target_trackers = params[:target_tracker_ids].blank? ?
Chris@1517 104 nil : Tracker.where(:id => params[:target_tracker_ids]).all
Chris@1517 105 @target_roles = params[:target_role_ids].blank? ?
Chris@1517 106 nil : Role.where(:id => params[:target_role_ids]).all
Chris@0 107 if request.post?
Chris@0 108 if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?)
Chris@0 109 flash.now[:error] = l(:error_workflow_copy_source)
Chris@1464 110 elsif @target_trackers.blank? || @target_roles.blank?
Chris@0 111 flash.now[:error] = l(:error_workflow_copy_target)
Chris@0 112 else
Chris@1115 113 WorkflowRule.copy(@source_tracker, @source_role, @target_trackers, @target_roles)
Chris@0 114 flash[:notice] = l(:notice_successful_update)
Chris@1464 115 redirect_to workflows_copy_path(:source_tracker_id => @source_tracker, :source_role_id => @source_role)
Chris@0 116 end
Chris@0 117 end
Chris@0 118 end
Chris@0 119
Chris@0 120 private
Chris@0 121
Chris@0 122 def find_roles
Chris@1115 123 @roles = Role.sorted.all
Chris@0 124 end
Chris@909 125
Chris@0 126 def find_trackers
Chris@1115 127 @trackers = Tracker.sorted.all
Chris@0 128 end
Chris@0 129 end