@@ -1,132 +1,125 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 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. | |
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 |
|
21 | before_filter :require_admin | |
22 | before_filter :find_roles |
|
22 | before_filter :find_roles | |
23 | before_filter :find_trackers |
|
23 | before_filter :find_trackers | |
24 |
|
24 | |||
25 | def index |
|
25 | def index | |
26 | @workflow_counts = WorkflowTransition.count_by_tracker_and_role |
|
26 | @workflow_counts = WorkflowTransition.count_by_tracker_and_role | |
27 | end |
|
27 | end | |
28 |
|
28 | |||
29 | def edit |
|
29 | def edit | |
30 | @role = Role.find_by_id(params[:role_id]) |
|
30 | @role = Role.find_by_id(params[:role_id]) | |
31 | @tracker = Tracker.find_by_id(params[:tracker_id]) |
|
31 | @tracker = Tracker.find_by_id(params[:tracker_id]) | |
32 |
|
32 | |||
33 | if request.post? |
|
33 | if request.post? | |
34 | WorkflowTransition.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id]) |
|
34 | WorkflowTransition.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id]) | |
35 | (params[:issue_status] || []).each { |status_id, transitions| |
|
35 | (params[:issue_status] || []).each { |status_id, transitions| | |
36 | transitions.each { |new_status_id, options| |
|
36 | transitions.each { |new_status_id, options| | |
37 | author = options.is_a?(Array) && options.include?('author') && !options.include?('always') |
|
37 | author = options.is_a?(Array) && options.include?('author') && !options.include?('always') | |
38 | assignee = options.is_a?(Array) && options.include?('assignee') && !options.include?('always') |
|
38 | assignee = options.is_a?(Array) && options.include?('assignee') && !options.include?('always') | |
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) |
|
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 | if @role.save |
|
42 | if @role.save | |
43 | redirect_to :action => 'edit', :role_id => @role, :tracker_id => @tracker |
|
43 | redirect_to :action => 'edit', :role_id => @role, :tracker_id => @tracker | |
44 | return |
|
44 | return | |
45 | end |
|
45 | end | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true) |
|
48 | @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true) | |
49 | if @tracker && @used_statuses_only && @tracker.issue_statuses.any? |
|
49 | if @tracker && @used_statuses_only && @tracker.issue_statuses.any? | |
50 | @statuses = @tracker.issue_statuses |
|
50 | @statuses = @tracker.issue_statuses | |
51 | end |
|
51 | end | |
52 | @statuses ||= IssueStatus.find(:all, :order => 'position') |
|
52 | @statuses ||= IssueStatus.find(:all, :order => 'position') | |
53 |
|
53 | |||
54 | if @tracker && @role && @statuses.any? |
|
54 | if @tracker && @role && @statuses.any? | |
55 | workflows = WorkflowTransition.all(:conditions => {:role_id => @role.id, :tracker_id => @tracker.id}) |
|
55 | workflows = WorkflowTransition.all(:conditions => {:role_id => @role.id, :tracker_id => @tracker.id}) | |
56 | @workflows = {} |
|
56 | @workflows = {} | |
57 | @workflows['always'] = workflows.select {|w| !w.author && !w.assignee} |
|
57 | @workflows['always'] = workflows.select {|w| !w.author && !w.assignee} | |
58 | @workflows['author'] = workflows.select {|w| w.author} |
|
58 | @workflows['author'] = workflows.select {|w| w.author} | |
59 | @workflows['assignee'] = workflows.select {|w| w.assignee} |
|
59 | @workflows['assignee'] = workflows.select {|w| w.assignee} | |
60 | end |
|
60 | end | |
61 | end |
|
61 | end | |
62 |
|
62 | |||
63 | def permissions |
|
63 | def permissions | |
64 | @role = Role.find_by_id(params[:role_id]) |
|
64 | @role = Role.find_by_id(params[:role_id]) | |
65 | @tracker = Tracker.find_by_id(params[:tracker_id]) |
|
65 | @tracker = Tracker.find_by_id(params[:tracker_id]) | |
66 |
|
66 | |||
67 | if @role && @tracker |
|
67 | if @role && @tracker | |
68 | if request.post? |
|
68 | if request.post? | |
69 | WorkflowPermission.destroy_all({:role_id => @role.id, :tracker_id => @tracker.id}) |
|
69 | WorkflowPermission.replace_permissions(@tracker, @role, params[:permissions] || {}) | |
70 | (params[:permissions] || {}).each { |field, rule_by_status_id| |
|
|||
71 | rule_by_status_id.each { |status_id, rule| |
|
|||
72 | if rule.present? |
|
|||
73 | WorkflowPermission.create(:role_id => @role.id, :tracker_id => @tracker.id, :old_status_id => status_id, :field_name => field, :rule => rule) |
|
|||
74 | end |
|
|||
75 | } |
|
|||
76 | } |
|
|||
77 | redirect_to :action => 'permissions', :role_id => @role, :tracker_id => @tracker |
|
70 | redirect_to :action => 'permissions', :role_id => @role, :tracker_id => @tracker | |
78 | return |
|
71 | return | |
79 | end |
|
72 | end | |
80 |
|
73 | |||
81 | @statuses = @tracker.issue_statuses |
|
74 | @statuses = @tracker.issue_statuses | |
82 | @fields = (Tracker::CORE_FIELDS_ALL - @tracker.disabled_core_fields).map {|field| [field, l("field_"+field.sub(/_id$/, ''))]} |
|
75 | @fields = (Tracker::CORE_FIELDS_ALL - @tracker.disabled_core_fields).map {|field| [field, l("field_"+field.sub(/_id$/, ''))]} | |
83 | @custom_fields = @tracker.custom_fields |
|
76 | @custom_fields = @tracker.custom_fields | |
84 |
|
77 | |||
85 | @permissions = WorkflowPermission.where(:tracker_id => @tracker.id, :role_id => @role.id).all.inject({}) do |h, w| |
|
78 | @permissions = WorkflowPermission.where(:tracker_id => @tracker.id, :role_id => @role.id).all.inject({}) do |h, w| | |
86 | h[w.old_status_id] ||= {} |
|
79 | h[w.old_status_id] ||= {} | |
87 | h[w.old_status_id][w.field_name] = w.rule |
|
80 | h[w.old_status_id][w.field_name] = w.rule | |
88 | h |
|
81 | h | |
89 | end |
|
82 | end | |
90 | @statuses.each {|status| @permissions[status.id] ||= {}} |
|
83 | @statuses.each {|status| @permissions[status.id] ||= {}} | |
91 | end |
|
84 | end | |
92 | end |
|
85 | end | |
93 |
|
86 | |||
94 | def copy |
|
87 | def copy | |
95 |
|
88 | |||
96 | if params[:source_tracker_id].blank? || params[:source_tracker_id] == 'any' |
|
89 | if params[:source_tracker_id].blank? || params[:source_tracker_id] == 'any' | |
97 | @source_tracker = nil |
|
90 | @source_tracker = nil | |
98 | else |
|
91 | else | |
99 | @source_tracker = Tracker.find_by_id(params[:source_tracker_id].to_i) |
|
92 | @source_tracker = Tracker.find_by_id(params[:source_tracker_id].to_i) | |
100 | end |
|
93 | end | |
101 | if params[:source_role_id].blank? || params[:source_role_id] == 'any' |
|
94 | if params[:source_role_id].blank? || params[:source_role_id] == 'any' | |
102 | @source_role = nil |
|
95 | @source_role = nil | |
103 | else |
|
96 | else | |
104 | @source_role = Role.find_by_id(params[:source_role_id].to_i) |
|
97 | @source_role = Role.find_by_id(params[:source_role_id].to_i) | |
105 | end |
|
98 | end | |
106 |
|
99 | |||
107 | @target_trackers = params[:target_tracker_ids].blank? ? nil : Tracker.find_all_by_id(params[:target_tracker_ids]) |
|
100 | @target_trackers = params[:target_tracker_ids].blank? ? nil : Tracker.find_all_by_id(params[:target_tracker_ids]) | |
108 | @target_roles = params[:target_role_ids].blank? ? nil : Role.find_all_by_id(params[:target_role_ids]) |
|
101 | @target_roles = params[:target_role_ids].blank? ? nil : Role.find_all_by_id(params[:target_role_ids]) | |
109 |
|
102 | |||
110 | if request.post? |
|
103 | if request.post? | |
111 | if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?) |
|
104 | if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?) | |
112 | flash.now[:error] = l(:error_workflow_copy_source) |
|
105 | flash.now[:error] = l(:error_workflow_copy_source) | |
113 | elsif @target_trackers.nil? || @target_roles.nil? |
|
106 | elsif @target_trackers.nil? || @target_roles.nil? | |
114 | flash.now[:error] = l(:error_workflow_copy_target) |
|
107 | flash.now[:error] = l(:error_workflow_copy_target) | |
115 | else |
|
108 | else | |
116 | WorkflowRule.copy(@source_tracker, @source_role, @target_trackers, @target_roles) |
|
109 | WorkflowRule.copy(@source_tracker, @source_role, @target_trackers, @target_roles) | |
117 | flash[:notice] = l(:notice_successful_update) |
|
110 | flash[:notice] = l(:notice_successful_update) | |
118 | redirect_to :action => 'copy', :source_tracker_id => @source_tracker, :source_role_id => @source_role |
|
111 | redirect_to :action => 'copy', :source_tracker_id => @source_tracker, :source_role_id => @source_role | |
119 | end |
|
112 | end | |
120 | end |
|
113 | end | |
121 | end |
|
114 | end | |
122 |
|
115 | |||
123 | private |
|
116 | private | |
124 |
|
117 | |||
125 | def find_roles |
|
118 | def find_roles | |
126 | @roles = Role.find(:all, :order => 'builtin, position') |
|
119 | @roles = Role.find(:all, :order => 'builtin, position') | |
127 | end |
|
120 | end | |
128 |
|
121 | |||
129 | def find_trackers |
|
122 | def find_trackers | |
130 | @trackers = Tracker.find(:all, :order => 'position') |
|
123 | @trackers = Tracker.find(:all, :order => 'position') | |
131 | end |
|
124 | end | |
132 | end |
|
125 | end |
@@ -1,29 +1,45 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 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. | |
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 WorkflowPermission < WorkflowRule |
|
18 | class WorkflowPermission < WorkflowRule | |
19 | validates_inclusion_of :rule, :in => %w(readonly required) |
|
19 | validates_inclusion_of :rule, :in => %w(readonly required) | |
20 | validate :validate_field_name |
|
20 | validate :validate_field_name | |
21 |
|
21 | |||
|
22 | # Replaces the workflow permissions for the given tracker and role | |||
|
23 | # | |||
|
24 | # Example: | |||
|
25 | # WorkflowPermission.replace_permissions role, tracker, {'due_date' => {'1' => 'readonly', '2' => 'required'}} | |||
|
26 | def self.replace_permissions(tracker, role, permissions) | |||
|
27 | destroy_all(:tracker_id => tracker.id, :role_id => role.id) | |||
|
28 | ||||
|
29 | permissions.each { |field, rule_by_status_id| | |||
|
30 | rule_by_status_id.each { |status_id, rule| | |||
|
31 | if rule.present? | |||
|
32 | WorkflowPermission.create(:role_id => role.id, :tracker_id => tracker.id, :old_status_id => status_id, :field_name => field, :rule => rule) | |||
|
33 | end | |||
|
34 | } | |||
|
35 | } | |||
|
36 | end | |||
|
37 | ||||
22 | protected |
|
38 | protected | |
23 |
|
39 | |||
24 | def validate_field_name |
|
40 | def validate_field_name | |
25 | unless Tracker::CORE_FIELDS_ALL.include?(field_name) || field_name.to_s.match(/^\d+$/) |
|
41 | unless Tracker::CORE_FIELDS_ALL.include?(field_name) || field_name.to_s.match(/^\d+$/) | |
26 | errors.add :field_name, :invalid |
|
42 | errors.add :field_name, :invalid | |
27 | end |
|
43 | end | |
28 | end |
|
44 | end | |
29 | end |
|
45 | end |
General Comments 0
You need to be logged in to leave comments.
Login now