Skip to content
Browse files

Fixed nesting of without_access_control (#2)

  • Loading branch information...
1 parent e13ed8a commit 3b242073fd8d8b3881b166974ac8e70c64ca0b1e @stffn committed Jul 20, 2009
Showing with 34 additions and 8 deletions.
  1. +8 −8 lib/declarative_authorization/maintenance.rb
  2. +26 −0 test/maintenance_test.rb
View
16 lib/declarative_authorization/maintenance.rb
@@ -22,21 +22,21 @@ module Maintenance
# SomeModel.find(:first).save
# end
def without_access_control
- Authorization.ignore_access_control(true)
- yield
- ensure
- Authorization.ignore_access_control(false)
+ self.class.without_access_control
end
# A class method variant of without_access_control. Thus, one can call
# Authorization::Maintenance::without_access_control do
# ...
# end
def self.without_access_control
- Authorization.ignore_access_control(true)
- yield
- ensure
- Authorization.ignore_access_control(false)
+ previous_state = Authorization.ignore_access_control
+ begin
+ Authorization.ignore_access_control(true)
+ yield
+ ensure
+ Authorization.ignore_access_control(previous_state)
+ end
end
# Sets the current user for the declarative authorization plugin to the
View
26 test/maintenance_test.rb
@@ -12,4 +12,30 @@ def test_usages_by_controllers
include?(usage_test_controller)
end
+ def test_without_access_control
+ reader = Authorization::Reader::DSLReader.new
+ reader.parse %{
+ authorization do
+ role :test_role do
+ has_permission_on :permissions, :to => :test
+ end
+ end
+ }
+ engine = Authorization::Engine.new(reader)
+ assert !engine.permit?(:test_2, :context => :permissions,
+ :user => MockUser.new(:test_role))
+ Authorization::Maintenance::without_access_control do
+ assert engine.permit?(:test_2, :context => :permissions,
+ :user => MockUser.new(:test_role))
+ end
+ Authorization::Maintenance::without_access_control do
+ Authorization::Maintenance::without_access_control do
+ assert engine.permit?(:test_2, :context => :permissions,
+ :user => MockUser.new(:test_role))
+ end
+ assert engine.permit?(:test_2, :context => :permissions,
+ :user => MockUser.new(:test_role))
+ end
+ end
+
end

0 comments on commit 3b24207

Please sign in to comment.
Something went wrong with that request. Please try again.