annotate app/controllers/workflows_controller.rb @ 1466:834828a14f2b bug_598

Close obsolete branch bug_598
author Chris Cannam
date Fri, 21 Jun 2013 14:51:55 +0100
parents 433d4f72a19b
children 622f24f53b42
rev   line source
Chris@0 1 # Redmine - project management software
Chris@1115 2 # Copyright (C) 2006-2012 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@1115 41 redirect_to :action => 'edit', :role_id => @role, :tracker_id => @tracker, :used_statuses_only => params[:used_statuses_only]
Chris@245 42 return
Chris@0 43 end
Chris@0 44 end
Chris@909 45
Chris@0 46 @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
Chris@0 47 if @tracker && @used_statuses_only && @tracker.issue_statuses.any?
Chris@0 48 @statuses = @tracker.issue_statuses
Chris@0 49 end
Chris@1115 50 @statuses ||= IssueStatus.sorted.all
Chris@909 51
Chris@245 52 if @tracker && @role && @statuses.any?
Chris@1115 53 workflows = WorkflowTransition.where(:role_id => @role.id, :tracker_id => @tracker.id).all
Chris@245 54 @workflows = {}
Chris@245 55 @workflows['always'] = workflows.select {|w| !w.author && !w.assignee}
Chris@245 56 @workflows['author'] = workflows.select {|w| w.author}
Chris@245 57 @workflows['assignee'] = workflows.select {|w| w.assignee}
Chris@245 58 end
Chris@0 59 end
Chris@909 60
Chris@1115 61 def permissions
Chris@1115 62 @role = Role.find_by_id(params[:role_id]) if params[:role_id]
Chris@1115 63 @tracker = Tracker.find_by_id(params[:tracker_id]) if params[:tracker_id]
Chris@1115 64
Chris@1115 65 if request.post? && @role && @tracker
Chris@1115 66 WorkflowPermission.replace_permissions(@tracker, @role, params[:permissions] || {})
Chris@1115 67 redirect_to :action => 'permissions', :role_id => @role, :tracker_id => @tracker, :used_statuses_only => params[:used_statuses_only]
Chris@1115 68 return
Chris@1115 69 end
Chris@1115 70
Chris@1115 71 @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
Chris@1115 72 if @tracker && @used_statuses_only && @tracker.issue_statuses.any?
Chris@1115 73 @statuses = @tracker.issue_statuses
Chris@1115 74 end
Chris@1115 75 @statuses ||= IssueStatus.sorted.all
Chris@1115 76
Chris@1115 77 if @role && @tracker
Chris@1115 78 @fields = (Tracker::CORE_FIELDS_ALL - @tracker.disabled_core_fields).map {|field| [field, l("field_"+field.sub(/_id$/, ''))]}
Chris@1115 79 @custom_fields = @tracker.custom_fields
Chris@1115 80
Chris@1115 81 @permissions = WorkflowPermission.where(:tracker_id => @tracker.id, :role_id => @role.id).all.inject({}) do |h, w|
Chris@1115 82 h[w.old_status_id] ||= {}
Chris@1115 83 h[w.old_status_id][w.field_name] = w.rule
Chris@1115 84 h
Chris@1115 85 end
Chris@1115 86 @statuses.each {|status| @permissions[status.id] ||= {}}
Chris@1115 87 end
Chris@1115 88 end
Chris@1115 89
Chris@0 90 def copy
Chris@909 91
Chris@0 92 if params[:source_tracker_id].blank? || params[:source_tracker_id] == 'any'
Chris@0 93 @source_tracker = nil
Chris@0 94 else
Chris@0 95 @source_tracker = Tracker.find_by_id(params[:source_tracker_id].to_i)
Chris@0 96 end
Chris@0 97 if params[:source_role_id].blank? || params[:source_role_id] == 'any'
Chris@0 98 @source_role = nil
Chris@0 99 else
Chris@0 100 @source_role = Role.find_by_id(params[:source_role_id].to_i)
Chris@0 101 end
Chris@909 102
Chris@0 103 @target_trackers = params[:target_tracker_ids].blank? ? nil : Tracker.find_all_by_id(params[:target_tracker_ids])
Chris@0 104 @target_roles = params[:target_role_ids].blank? ? nil : Role.find_all_by_id(params[:target_role_ids])
Chris@909 105
Chris@0 106 if request.post?
Chris@0 107 if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?)
Chris@0 108 flash.now[:error] = l(:error_workflow_copy_source)
Chris@0 109 elsif @target_trackers.nil? || @target_roles.nil?
Chris@0 110 flash.now[:error] = l(:error_workflow_copy_target)
Chris@0 111 else
Chris@1115 112 WorkflowRule.copy(@source_tracker, @source_role, @target_trackers, @target_roles)
Chris@0 113 flash[:notice] = l(:notice_successful_update)
Chris@0 114 redirect_to :action => 'copy', :source_tracker_id => @source_tracker, :source_role_id => @source_role
Chris@0 115 end
Chris@0 116 end
Chris@0 117 end
Chris@0 118
Chris@0 119 private
Chris@0 120
Chris@0 121 def find_roles
Chris@1115 122 @roles = Role.sorted.all
Chris@0 123 end
Chris@909 124
Chris@0 125 def find_trackers
Chris@1115 126 @trackers = Tracker.sorted.all
Chris@0 127 end
Chris@0 128 end