Mercurial > hg > soundsoftware-site
comparison app/controllers/workflows_controller.rb @ 1115:433d4f72a19b redmine-2.2
Update to Redmine SVN revision 11137 on 2.2-stable branch
author | Chris Cannam |
---|---|
date | Mon, 07 Jan 2013 12:01:42 +0000 |
parents | cbb26bc654de |
children | 622f24f53b42 |
comparison
equal
deleted
inserted
replaced
929:5f33065ddc4b | 1115:433d4f72a19b |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | 2 # Copyright (C) 2006-2012 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 class WorkflowsController < ApplicationController | 18 class WorkflowsController < ApplicationController |
19 layout 'admin' | 19 layout 'admin' |
20 | 20 |
21 before_filter :require_admin | 21 before_filter :require_admin, :find_roles, :find_trackers |
22 before_filter :find_roles | |
23 before_filter :find_trackers | |
24 | 22 |
25 def index | 23 def index |
26 @workflow_counts = Workflow.count_by_tracker_and_role | 24 @workflow_counts = WorkflowTransition.count_by_tracker_and_role |
27 end | 25 end |
28 | 26 |
29 def edit | 27 def edit |
30 @role = Role.find_by_id(params[:role_id]) | 28 @role = Role.find_by_id(params[:role_id]) if params[:role_id] |
31 @tracker = Tracker.find_by_id(params[:tracker_id]) | 29 @tracker = Tracker.find_by_id(params[:tracker_id]) if params[:tracker_id] |
32 | 30 |
33 if request.post? | 31 if request.post? |
34 Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id]) | 32 WorkflowTransition.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id]) |
35 (params[:issue_status] || []).each { |status_id, transitions| | 33 (params[:issue_status] || []).each { |status_id, transitions| |
36 transitions.each { |new_status_id, options| | 34 transitions.each { |new_status_id, options| |
37 author = options.is_a?(Array) && options.include?('author') && !options.include?('always') | 35 author = options.is_a?(Array) && options.include?('author') && !options.include?('always') |
38 assignee = options.is_a?(Array) && options.include?('assignee') && !options.include?('always') | 36 assignee = options.is_a?(Array) && options.include?('assignee') && !options.include?('always') |
39 @role.workflows.build(:tracker_id => @tracker.id, :old_status_id => status_id, :new_status_id => new_status_id, :author => author, :assignee => assignee) | 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) |
40 } | 38 } |
41 } | 39 } |
42 if @role.save | 40 if @role.save |
43 flash[:notice] = l(:notice_successful_update) | 41 redirect_to :action => 'edit', :role_id => @role, :tracker_id => @tracker, :used_statuses_only => params[:used_statuses_only] |
44 redirect_to :action => 'edit', :role_id => @role, :tracker_id => @tracker | |
45 return | 42 return |
46 end | 43 end |
47 end | 44 end |
48 | 45 |
49 @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true) | 46 @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true) |
50 if @tracker && @used_statuses_only && @tracker.issue_statuses.any? | 47 if @tracker && @used_statuses_only && @tracker.issue_statuses.any? |
51 @statuses = @tracker.issue_statuses | 48 @statuses = @tracker.issue_statuses |
52 end | 49 end |
53 @statuses ||= IssueStatus.find(:all, :order => 'position') | 50 @statuses ||= IssueStatus.sorted.all |
54 | 51 |
55 if @tracker && @role && @statuses.any? | 52 if @tracker && @role && @statuses.any? |
56 workflows = Workflow.all(:conditions => {:role_id => @role.id, :tracker_id => @tracker.id}) | 53 workflows = WorkflowTransition.where(:role_id => @role.id, :tracker_id => @tracker.id).all |
57 @workflows = {} | 54 @workflows = {} |
58 @workflows['always'] = workflows.select {|w| !w.author && !w.assignee} | 55 @workflows['always'] = workflows.select {|w| !w.author && !w.assignee} |
59 @workflows['author'] = workflows.select {|w| w.author} | 56 @workflows['author'] = workflows.select {|w| w.author} |
60 @workflows['assignee'] = workflows.select {|w| w.assignee} | 57 @workflows['assignee'] = workflows.select {|w| w.assignee} |
58 end | |
59 end | |
60 | |
61 def permissions | |
62 @role = Role.find_by_id(params[:role_id]) if params[:role_id] | |
63 @tracker = Tracker.find_by_id(params[:tracker_id]) if params[:tracker_id] | |
64 | |
65 if request.post? && @role && @tracker | |
66 WorkflowPermission.replace_permissions(@tracker, @role, params[:permissions] || {}) | |
67 redirect_to :action => 'permissions', :role_id => @role, :tracker_id => @tracker, :used_statuses_only => params[:used_statuses_only] | |
68 return | |
69 end | |
70 | |
71 @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true) | |
72 if @tracker && @used_statuses_only && @tracker.issue_statuses.any? | |
73 @statuses = @tracker.issue_statuses | |
74 end | |
75 @statuses ||= IssueStatus.sorted.all | |
76 | |
77 if @role && @tracker | |
78 @fields = (Tracker::CORE_FIELDS_ALL - @tracker.disabled_core_fields).map {|field| [field, l("field_"+field.sub(/_id$/, ''))]} | |
79 @custom_fields = @tracker.custom_fields | |
80 | |
81 @permissions = WorkflowPermission.where(:tracker_id => @tracker.id, :role_id => @role.id).all.inject({}) do |h, w| | |
82 h[w.old_status_id] ||= {} | |
83 h[w.old_status_id][w.field_name] = w.rule | |
84 h | |
85 end | |
86 @statuses.each {|status| @permissions[status.id] ||= {}} | |
61 end | 87 end |
62 end | 88 end |
63 | 89 |
64 def copy | 90 def copy |
65 | 91 |
81 if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?) | 107 if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?) |
82 flash.now[:error] = l(:error_workflow_copy_source) | 108 flash.now[:error] = l(:error_workflow_copy_source) |
83 elsif @target_trackers.nil? || @target_roles.nil? | 109 elsif @target_trackers.nil? || @target_roles.nil? |
84 flash.now[:error] = l(:error_workflow_copy_target) | 110 flash.now[:error] = l(:error_workflow_copy_target) |
85 else | 111 else |
86 Workflow.copy(@source_tracker, @source_role, @target_trackers, @target_roles) | 112 WorkflowRule.copy(@source_tracker, @source_role, @target_trackers, @target_roles) |
87 flash[:notice] = l(:notice_successful_update) | 113 flash[:notice] = l(:notice_successful_update) |
88 redirect_to :action => 'copy', :source_tracker_id => @source_tracker, :source_role_id => @source_role | 114 redirect_to :action => 'copy', :source_tracker_id => @source_tracker, :source_role_id => @source_role |
89 end | 115 end |
90 end | 116 end |
91 end | 117 end |
92 | 118 |
93 private | 119 private |
94 | 120 |
95 def find_roles | 121 def find_roles |
96 @roles = Role.find(:all, :order => 'builtin, position') | 122 @roles = Role.sorted.all |
97 end | 123 end |
98 | 124 |
99 def find_trackers | 125 def find_trackers |
100 @trackers = Tracker.find(:all, :order => 'position') | 126 @trackers = Tracker.sorted.all |
101 end | 127 end |
102 end | 128 end |