annotate .svn/pristine/2a/2a729c60b4face5ae26610fc483b9a2b1f7c2f71.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

Merge from branch "live"
author Chris Cannam
date Tue, 09 Sep 2014 09:34:53 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 class WorkflowsController < ApplicationController
Chris@909 19 layout 'admin'
Chris@909 20
Chris@909 21 before_filter :require_admin
Chris@909 22 before_filter :find_roles
Chris@909 23 before_filter :find_trackers
Chris@909 24
Chris@909 25 def index
Chris@909 26 @workflow_counts = Workflow.count_by_tracker_and_role
Chris@909 27 end
Chris@909 28
Chris@909 29 def edit
Chris@909 30 @role = Role.find_by_id(params[:role_id])
Chris@909 31 @tracker = Tracker.find_by_id(params[:tracker_id])
Chris@909 32
Chris@909 33 if request.post?
Chris@909 34 Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
Chris@909 35 (params[:issue_status] || []).each { |status_id, transitions|
Chris@909 36 transitions.each { |new_status_id, options|
Chris@909 37 author = options.is_a?(Array) && options.include?('author') && !options.include?('always')
Chris@909 38 assignee = options.is_a?(Array) && options.include?('assignee') && !options.include?('always')
Chris@909 39 @role.workflows.build(:tracker_id => @tracker.id, :old_status_id => status_id, :new_status_id => new_status_id, :author => author, :assignee => assignee)
Chris@909 40 }
Chris@909 41 }
Chris@909 42 if @role.save
Chris@909 43 flash[:notice] = l(:notice_successful_update)
Chris@909 44 redirect_to :action => 'edit', :role_id => @role, :tracker_id => @tracker
Chris@909 45 return
Chris@909 46 end
Chris@909 47 end
Chris@909 48
Chris@909 49 @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
Chris@909 50 if @tracker && @used_statuses_only && @tracker.issue_statuses.any?
Chris@909 51 @statuses = @tracker.issue_statuses
Chris@909 52 end
Chris@909 53 @statuses ||= IssueStatus.find(:all, :order => 'position')
Chris@909 54
Chris@909 55 if @tracker && @role && @statuses.any?
Chris@909 56 workflows = Workflow.all(:conditions => {:role_id => @role.id, :tracker_id => @tracker.id})
Chris@909 57 @workflows = {}
Chris@909 58 @workflows['always'] = workflows.select {|w| !w.author && !w.assignee}
Chris@909 59 @workflows['author'] = workflows.select {|w| w.author}
Chris@909 60 @workflows['assignee'] = workflows.select {|w| w.assignee}
Chris@909 61 end
Chris@909 62 end
Chris@909 63
Chris@909 64 def copy
Chris@909 65
Chris@909 66 if params[:source_tracker_id].blank? || params[:source_tracker_id] == 'any'
Chris@909 67 @source_tracker = nil
Chris@909 68 else
Chris@909 69 @source_tracker = Tracker.find_by_id(params[:source_tracker_id].to_i)
Chris@909 70 end
Chris@909 71 if params[:source_role_id].blank? || params[:source_role_id] == 'any'
Chris@909 72 @source_role = nil
Chris@909 73 else
Chris@909 74 @source_role = Role.find_by_id(params[:source_role_id].to_i)
Chris@909 75 end
Chris@909 76
Chris@909 77 @target_trackers = params[:target_tracker_ids].blank? ? nil : Tracker.find_all_by_id(params[:target_tracker_ids])
Chris@909 78 @target_roles = params[:target_role_ids].blank? ? nil : Role.find_all_by_id(params[:target_role_ids])
Chris@909 79
Chris@909 80 if request.post?
Chris@909 81 if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?)
Chris@909 82 flash.now[:error] = l(:error_workflow_copy_source)
Chris@909 83 elsif @target_trackers.nil? || @target_roles.nil?
Chris@909 84 flash.now[:error] = l(:error_workflow_copy_target)
Chris@909 85 else
Chris@909 86 Workflow.copy(@source_tracker, @source_role, @target_trackers, @target_roles)
Chris@909 87 flash[:notice] = l(:notice_successful_update)
Chris@909 88 redirect_to :action => 'copy', :source_tracker_id => @source_tracker, :source_role_id => @source_role
Chris@909 89 end
Chris@909 90 end
Chris@909 91 end
Chris@909 92
Chris@909 93 private
Chris@909 94
Chris@909 95 def find_roles
Chris@909 96 @roles = Role.find(:all, :order => 'builtin, position')
Chris@909 97 end
Chris@909 98
Chris@909 99 def find_trackers
Chris@909 100 @trackers = Tracker.find(:all, :order => 'position')
Chris@909 101 end
Chris@909 102 end