Module: Authorization::Maintenance

Included in:
TestHelper
Defined in:
lib/declarative_authorization/maintenance.rb

Overview

Provides a few maintenance methods for modifying data without enforcing authorization.

Defined Under Namespace

Modules: Usage

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.with_user(user) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/declarative_authorization/maintenance.rb', line 43

def self.with_user (user)
  prev_user = Authorization.current_user
  Authorization.current_user = user
  yield
ensure
  Authorization.current_user = prev_user
end

.without_access_controlObject

A class method variant of without_access_control. Thus, one can call

Authorization::Maintenance::without_access_control do
  ...
end


26
27
28
29
30
31
32
33
34
# File 'lib/declarative_authorization/maintenance.rb', line 26

def self.without_access_control
  previous_state = Authorization.ignore_access_control
  begin
    Authorization.ignore_access_control(true)
    yield
  ensure
    Authorization.ignore_access_control(previous_state)
  end
end

Instance Method Details

#with_user(user, &block) ⇒ Object

Sets the current user for the declarative authorization plugin to the given one for the execution of the supplied block. Suitable for tests on certain users.



39
40
41
# File 'lib/declarative_authorization/maintenance.rb', line 39

def with_user (user, &block)
  Authorization::Maintenance.with_user(user, &block)
end

#without_access_control(&block) ⇒ Object

Disables access control for the given block. Appropriate for maintenance operation at the Rails console or in test case setup.

For use in the Rails console:

require "vendor/plugins/declarative_authorization/lib/maintenance"
include Authorization::Maintenance

without_access_control do
  SomeModel.find(:first).save
end


18
19
20
# File 'lib/declarative_authorization/maintenance.rb', line 18

def without_access_control (&block)
  Authorization::Maintenance.without_access_control(&block)
end