Module: Wallaby::Authorizable

Included in:
ResourcesConcern, ResourcesHelper
Defined in:
lib/concerns/wallaby/authorizable.rb

Overview

Authorizer related

Instance Method Summary collapse

Instance Method Details

#authorized?(action, subject) ⇒ true, false

Check if user is allowed to perform action on given subject

Parameters:

  • action (Symbol, String)
  • subject (Object, Class)

Returns:

  • (true)

    if allowed

  • (false)

    if not allowed

Since:

  • wallaby-5.2.0



23
24
25
26
27
28
# File 'lib/concerns/wallaby/authorizable.rb', line 23

def authorized?(action, subject)
  return false unless subject

  klass = subject.is_a?(Class) ? subject : subject.class
  authorizer_of(klass).authorized?(action, subject)
end

#current_authorizerModelAuthorizer

Model authorizer for current modal class.

Returns:

See Also:

  • #authorizer_of

Since:

  • wallaby-5.2.0



10
11
12
13
14
15
# File 'lib/concerns/wallaby/authorizable.rb', line 10

def current_authorizer
  @current_authorizer ||=
    authorizer_of(current_model_class).tap do |authorizer|
      Logger.debug %(Current authorizer: #{authorizer.try(:class)}), sourcing: false
    end
end

#unauthorized?(action, subject) ⇒ true, false

Check if user is allowed to perform action on given subject

Parameters:

  • action (Symbol, String)
  • subject (Object, Class)

Returns:

  • (true)

    if not allowed

  • (false)

    if allowed

Since:

  • wallaby-5.2.0



36
37
38
# File 'lib/concerns/wallaby/authorizable.rb', line 36

def unauthorized?(action, subject)
  !authorized?(action, subject)
end