Module: Constellation::Authorization::Base::ControllerInstanceMethods

Includes:
EvalParser
Defined in:
lib/constellation/authorization/base.rb

Instance Method Summary collapse

Methods included from EvalParser

#parse_authorization_expression, #process_role, #process_role_of_model, #replace_role, #replace_role_of_model, #replace_temporarily_role_of_model

Instance Method Details

#permit(authorization_expression, *args) ⇒ Object

Allow method-level authorization checks. permit (without a question mark ending) calls redirect on denial by default. Specify :redirect => false to turn off redirection.



45
46
47
48
49
50
51
52
53
54
# File 'lib/constellation/authorization/base.rb', line 45

def permit(authorization_expression, *args)
  @options = { :allow_guests => false, :redirect => true }
  @options.merge!(args.last.is_a?(Hash) ? args.last : {})

  if has_permission?(authorization_expression)
    yield if block_given?
  elsif @options[:redirect]
    handle_redirection
  end
end

#permit?(authorization_expression, *args) ⇒ Boolean

Permit? turns off redirection by default and takes no blocks

Returns:

  • (Boolean)


35
36
37
38
39
40
# File 'lib/constellation/authorization/base.rb', line 35

def permit?(authorization_expression, *args)
  @options = { :allow_guests => false, :redirect => false }
  @options.merge!(args.last.is_a?(Hash) ? args.last : {})

  has_permission?(authorization_expression)
end