]> source.dussan.org Git - redmine.git/commitdiff
Moved code for replacing permissions to WorkflowPermission model.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 15 Jul 2012 15:05:34 +0000 (15:05 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 15 Jul 2012 15:05:34 +0000 (15:05 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9987 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/workflows_controller.rb
app/models/workflow_permission.rb

index 3c49de8d578ac4e534d51f0dc58b2452a7a796d9..70932ebbcf76305d4a8e040a56d989f853cb7323 100644 (file)
@@ -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
index 72e95543f252d639dcf3ff8d1dd72215a85b746a..75cc4e46c0c2a3a10436b41b3cb80c20d343f8fa 100644 (file)
@@ -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