Module: Authorizr::Controller::ClassMethods

Defined in:
lib/authorizr/controller.rb

Instance Method Summary collapse

Instance Method Details

#authorize(&block) ⇒ Object

these methods will be called from the Class level, not the instance level



30
31
32
# File 'lib/authorizr/controller.rb', line 30

def authorize &block
  @@authorization_blocks[self.to_s] = block unless block.nil?
end

#authorize_allObject



5
6
7
# File 'lib/authorizr/controller.rb', line 5

def authorize_all
  before_filter :authorize!
end

#create_authblock_catalogObject

build maintain a catalog of the auth/unauth blocks provided by the child controllers



39
40
41
42
# File 'lib/authorizr/controller.rb', line 39

def create_authblock_catalog
  @@authorization_blocks = {}
  @@failure_blocks = {}
end

#manually_authorize(params = {}) ⇒ Object

a hook for other object to authorize from outside the request object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/authorizr/controller.rb', line 10

def manually_authorize params={}
  params[:user]     ||= nil
  params[:resource] ||= nil
  params[:action]   ||= nil

  auth_block = @@authorization_blocks[self.to_s]
  if auth_block.nil?
    authorized = false
  else
    authorized = auth_block.call({
                   :user => params[:user],
                   :resource => params[:resource],
                   :action => params[:action],
                   :params => {},
                   :model => params[:resource].class
                 })
   end
end

#unauthorized(&block) ⇒ Object



34
35
36
# File 'lib/authorizr/controller.rb', line 34

def unauthorized &block
  @@failure_blocks[self.to_s] = block unless block.nil?
end