annotate .svn/pristine/59/5957c73ec3e45b1dba5f2bd95614bcd541de4b15.svn-base @ 1464:261b3d9a4903 redmine-2.4

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