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