annotate .svn/pristine/49/49878bda812337dc45d145cb9d92b0edd7543552.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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