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