##// END OF EJS Templates
add missing Relation#all at WorkflowsController#copy of r12583...
Toshi MARUYAMA -
r12310:3fcd5d529cfe
parent child
Show More
@@ -1,127 +1,127
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 redirect_to workflows_edit_path(:role_id => @role, :tracker_id => @tracker, :used_statuses_only => params[:used_statuses_only])
41 redirect_to workflows_edit_path(:role_id => @role, :tracker_id => @tracker, :used_statuses_only => params[:used_statuses_only])
42 return
42 return
43 end
43 end
44 end
44 end
45
45
46 @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
46 @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
47 if @tracker && @used_statuses_only && @tracker.issue_statuses.any?
47 if @tracker && @used_statuses_only && @tracker.issue_statuses.any?
48 @statuses = @tracker.issue_statuses
48 @statuses = @tracker.issue_statuses
49 end
49 end
50 @statuses ||= IssueStatus.sorted.all
50 @statuses ||= IssueStatus.sorted.all
51
51
52 if @tracker && @role && @statuses.any?
52 if @tracker && @role && @statuses.any?
53 workflows = WorkflowTransition.where(:role_id => @role.id, :tracker_id => @tracker.id).all
53 workflows = WorkflowTransition.where(:role_id => @role.id, :tracker_id => @tracker.id).all
54 @workflows = {}
54 @workflows = {}
55 @workflows['always'] = workflows.select {|w| !w.author && !w.assignee}
55 @workflows['always'] = workflows.select {|w| !w.author && !w.assignee}
56 @workflows['author'] = workflows.select {|w| w.author}
56 @workflows['author'] = workflows.select {|w| w.author}
57 @workflows['assignee'] = workflows.select {|w| w.assignee}
57 @workflows['assignee'] = workflows.select {|w| w.assignee}
58 end
58 end
59 end
59 end
60
60
61 def permissions
61 def permissions
62 @role = Role.find_by_id(params[:role_id]) if params[:role_id]
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]
63 @tracker = Tracker.find_by_id(params[:tracker_id]) if params[:tracker_id]
64
64
65 if request.post? && @role && @tracker
65 if request.post? && @role && @tracker
66 WorkflowPermission.replace_permissions(@tracker, @role, params[:permissions] || {})
66 WorkflowPermission.replace_permissions(@tracker, @role, params[:permissions] || {})
67 redirect_to workflows_permissions_path(:role_id => @role, :tracker_id => @tracker, :used_statuses_only => params[:used_statuses_only])
67 redirect_to workflows_permissions_path(:role_id => @role, :tracker_id => @tracker, :used_statuses_only => params[:used_statuses_only])
68 return
68 return
69 end
69 end
70
70
71 @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
71 @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
72 if @tracker && @used_statuses_only && @tracker.issue_statuses.any?
72 if @tracker && @used_statuses_only && @tracker.issue_statuses.any?
73 @statuses = @tracker.issue_statuses
73 @statuses = @tracker.issue_statuses
74 end
74 end
75 @statuses ||= IssueStatus.sorted.all
75 @statuses ||= IssueStatus.sorted.all
76
76
77 if @role && @tracker
77 if @role && @tracker
78 @fields = (Tracker::CORE_FIELDS_ALL - @tracker.disabled_core_fields).map {|field| [field, l("field_"+field.sub(/_id$/, ''))]}
78 @fields = (Tracker::CORE_FIELDS_ALL - @tracker.disabled_core_fields).map {|field| [field, l("field_"+field.sub(/_id$/, ''))]}
79 @custom_fields = @tracker.custom_fields
79 @custom_fields = @tracker.custom_fields
80
80
81 @permissions = WorkflowPermission.where(:tracker_id => @tracker.id, :role_id => @role.id).all.inject({}) do |h, w|
81 @permissions = WorkflowPermission.where(:tracker_id => @tracker.id, :role_id => @role.id).all.inject({}) do |h, w|
82 h[w.old_status_id] ||= {}
82 h[w.old_status_id] ||= {}
83 h[w.old_status_id][w.field_name] = w.rule
83 h[w.old_status_id][w.field_name] = w.rule
84 h
84 h
85 end
85 end
86 @statuses.each {|status| @permissions[status.id] ||= {}}
86 @statuses.each {|status| @permissions[status.id] ||= {}}
87 end
87 end
88 end
88 end
89
89
90 def copy
90 def copy
91 if params[:source_tracker_id].blank? || params[:source_tracker_id] == 'any'
91 if params[:source_tracker_id].blank? || params[:source_tracker_id] == 'any'
92 @source_tracker = nil
92 @source_tracker = nil
93 else
93 else
94 @source_tracker = Tracker.find_by_id(params[:source_tracker_id].to_i)
94 @source_tracker = Tracker.find_by_id(params[:source_tracker_id].to_i)
95 end
95 end
96 if params[:source_role_id].blank? || params[:source_role_id] == 'any'
96 if params[:source_role_id].blank? || params[:source_role_id] == 'any'
97 @source_role = nil
97 @source_role = nil
98 else
98 else
99 @source_role = Role.find_by_id(params[:source_role_id].to_i)
99 @source_role = Role.find_by_id(params[:source_role_id].to_i)
100 end
100 end
101 @target_trackers = params[:target_tracker_ids].blank? ?
101 @target_trackers = params[:target_tracker_ids].blank? ?
102 nil : Tracker.where(:id => params[:target_tracker_ids]).all
102 nil : Tracker.where(:id => params[:target_tracker_ids]).all
103 @target_roles = params[:target_role_ids].blank? ?
103 @target_roles = params[:target_role_ids].blank? ?
104 nil : Role.where(:id => params[:target_role_ids])
104 nil : Role.where(:id => params[:target_role_ids]).all
105 if request.post?
105 if request.post?
106 if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?)
106 if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?)
107 flash.now[:error] = l(:error_workflow_copy_source)
107 flash.now[:error] = l(:error_workflow_copy_source)
108 elsif @target_trackers.blank? || @target_roles.blank?
108 elsif @target_trackers.blank? || @target_roles.blank?
109 flash.now[:error] = l(:error_workflow_copy_target)
109 flash.now[:error] = l(:error_workflow_copy_target)
110 else
110 else
111 WorkflowRule.copy(@source_tracker, @source_role, @target_trackers, @target_roles)
111 WorkflowRule.copy(@source_tracker, @source_role, @target_trackers, @target_roles)
112 flash[:notice] = l(:notice_successful_update)
112 flash[:notice] = l(:notice_successful_update)
113 redirect_to workflows_copy_path(:source_tracker_id => @source_tracker, :source_role_id => @source_role)
113 redirect_to workflows_copy_path(:source_tracker_id => @source_tracker, :source_role_id => @source_role)
114 end
114 end
115 end
115 end
116 end
116 end
117
117
118 private
118 private
119
119
120 def find_roles
120 def find_roles
121 @roles = Role.sorted.all
121 @roles = Role.sorted.all
122 end
122 end
123
123
124 def find_trackers
124 def find_trackers
125 @trackers = Tracker.sorted.all
125 @trackers = Tracker.sorted.all
126 end
126 end
127 end
127 end
General Comments 0
You need to be logged in to leave comments. Login now