annotate .svn/pristine/be/be8e6e4ab944ad41015bb9c64ecc1842cecaa059.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

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