Class: Wallaby::DefaultAuthorizationProvider

Inherits:
ModelAuthorizationProvider show all
Defined in:
lib/authorizers/wallaby/default_authorization_provider.rb

Overview

Default authorization provider that allowlists everything.

Direct Known Subclasses

Custom::DefaultProvider

Instance Attribute Summary

Attributes inherited from ModelAuthorizationProvider

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ModelAuthorizationProvider

#initialize, #unauthorized?, #user

Constructor Details

This class inherits a constructor from Wallaby::ModelAuthorizationProvider

Class Method Details

.available?(_context) ⇒ false

It returns false so that it can be used as the last resort.

Parameters:

  • _context (ActionController::Base, ActionView::Base)

Returns:

  • (false)


9
10
11
# File 'lib/authorizers/wallaby/default_authorization_provider.rb', line 9

def self.available?(_context)
  false
end

.options_from(context) ⇒ Hash

It returns empty hash.

Parameters:

  • context (ActionController::Base, ActionView::Base)

Returns:

  • (Hash)


16
17
18
19
20
# File 'lib/authorizers/wallaby/default_authorization_provider.rb', line 16

def self.options_from(context)
  {
    user: context.try(:wallaby_user)
  }
end

Instance Method Details

#accessible_for(_action, scope) ⇒ Object

Do nothing

Parameters:

  • _action (Symbol, String)
  • scope (Object)


40
41
42
# File 'lib/authorizers/wallaby/default_authorization_provider.rb', line 40

def accessible_for(_action, scope)
  scope
end

#attributes_for(_action, _subject) ⇒ Hash

Return empty attributes

Parameters:

  • _action (Symbol, String)
  • _subject (Object)

Returns:

  • (Hash)

    empty hash



48
49
50
# File 'lib/authorizers/wallaby/default_authorization_provider.rb', line 48

def attributes_for(_action, _subject)
  {}
end

#authorize(_action, subject) ⇒ Object

Do nothing

Parameters:

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


25
26
27
# File 'lib/authorizers/wallaby/default_authorization_provider.rb', line 25

def authorize(_action, subject)
  subject
end

#authorized?(_action, _subject) ⇒ true

Always return true

Parameters:

  • _action (Symbol, String)
  • _subject (Object, Class)

Returns:

  • (true)


33
34
35
# File 'lib/authorizers/wallaby/default_authorization_provider.rb', line 33

def authorized?(_action, _subject)
  true
end

#permit_params(_action, _subject) ⇒ nil

Note:

Please make sure to return nil when the authorization provider doesn’t support this feature.

Parameters:

  • _action (Symbol, String)
  • _subject (Object)

Returns:

  • (nil)


56
57
58
# File 'lib/authorizers/wallaby/default_authorization_provider.rb', line 56

def permit_params(_action, _subject)
  # Do nothing
end