Module: Authorization::Base::ControllerInstanceMethods

Includes:
EvalParser
Defined in:
lib/rails-authorization-plugin/lib/authorization.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.


58
59
60
61
62
63
64
65
66
67
# File 'lib/rails-authorization-plugin/lib/authorization.rb', line 58

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)

48
49
50
51
52
53
# File 'lib/rails-authorization-plugin/lib/authorization.rb', line 48

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