summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-07-15 15:05:34 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-07-15 15:05:34 +0000
commit9e06942ef01ef21e58c8770ad026b100d491167a (patch)
tree7c3ba45506cd3441c1e43f9971ef37ba8eadffb1
parent02e702568527d7b9dcb06574e8d3da8d84961614 (diff)
downloadredmine-9e06942ef01ef21e58c8770ad026b100d491167a.tar.gz
redmine-9e06942ef01ef21e58c8770ad026b100d491167a.zip
Moved code for replacing permissions to WorkflowPermission model.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9987 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/workflows_controller.rb9
-rw-r--r--app/models/workflow_permission.rb16
2 files changed, 17 insertions, 8 deletions
diff --git a/app/controllers/workflows_controller.rb b/app/controllers/workflows_controller.rb
index 3c49de8d5..70932ebbc 100644
--- a/app/controllers/workflows_controller.rb
+++ b/app/controllers/workflows_controller.rb
@@ -66,14 +66,7 @@ class WorkflowsController < ApplicationController
if @role && @tracker
if request.post?
- WorkflowPermission.destroy_all({:role_id => @role.id, :tracker_id => @tracker.id})
- (params[:permissions] || {}).each { |field, rule_by_status_id|
- rule_by_status_id.each { |status_id, rule|
- if rule.present?
- WorkflowPermission.create(:role_id => @role.id, :tracker_id => @tracker.id, :old_status_id => status_id, :field_name => field, :rule => rule)
- end
- }
- }
+ WorkflowPermission.replace_permissions(@tracker, @role, params[:permissions] || {})
redirect_to :action => 'permissions', :role_id => @role, :tracker_id => @tracker
return
end
diff --git a/app/models/workflow_permission.rb b/app/models/workflow_permission.rb
index 72e95543f..75cc4e46c 100644
--- a/app/models/workflow_permission.rb
+++ b/app/models/workflow_permission.rb
@@ -19,6 +19,22 @@ class WorkflowPermission < WorkflowRule
validates_inclusion_of :rule, :in => %w(readonly required)
validate :validate_field_name
+ # Replaces the workflow permissions for the given tracker and role
+ #
+ # Example:
+ # WorkflowPermission.replace_permissions role, tracker, {'due_date' => {'1' => 'readonly', '2' => 'required'}}
+ def self.replace_permissions(tracker, role, permissions)
+ destroy_all(:tracker_id => tracker.id, :role_id => role.id)
+
+ permissions.each { |field, rule_by_status_id|
+ rule_by_status_id.each { |status_id, rule|
+ if rule.present?
+ WorkflowPermission.create(:role_id => role.id, :tracker_id => tracker.id, :old_status_id => status_id, :field_name => field, :rule => rule)
+ end
+ }
+ }
+ end
+
protected
def validate_field_name