Class: Wallaby::ModelAuthorizationProvider
- Inherits:
-
Object
- Object
- Wallaby::ModelAuthorizationProvider
- Defined in:
- lib/interfaces/wallaby/model_authorization_provider.rb
Overview
Model Authorizer interface.
Direct Known Subclasses
CancancanAuthorizationProvider, DefaultAuthorizationProvider, PunditAuthorizationProvider
Class Attribute Summary collapse
-
.provider_name ⇒ String/Symbol
This is the provider name (e.g. ‘:default`/`:cancancan`/`:pundit`) that can be set in ModelAuthorizer subclasses’s Wallaby::ModelAuthorizer.provider_name.
Instance Attribute Summary collapse
- #options ⇒ Hash readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#accessible_for(_action, _scope) ⇒ Object
This is the template method to restrict user’s access to certain scope.
-
#attributes_for(_action, _subject) ⇒ Object
This is the template method to restrict user’s modification to certain fields of given subject.
-
#authorize(_action, _subject) ⇒ Object
This is the template method to check user’s permission for given action on given subject.
-
#authorized?(_action, _subject) ⇒ Boolean
This is the template method to check if user has permission for given action on given subject.
-
#initialize(options = {}) ⇒ ModelAuthorizationProvider
constructor
A new instance of ModelAuthorizationProvider.
-
#permit_params(_action, _subject) ⇒ Object
This is the template method to restrict user’s mass assignment to certain fields of given subject.
-
#unauthorized?(action, subject) ⇒ Boolean
This is the template method to check if user has no permission for given action on given subject.
-
#user ⇒ Object?
User object.
Constructor Details
#initialize(options = {}) ⇒ ModelAuthorizationProvider
Returns a new instance of ModelAuthorizationProvider.
39 40 41 |
# File 'lib/interfaces/wallaby/model_authorization_provider.rb', line 39 def initialize( = {}) @options = || {} end |
Class Attribute Details
.provider_name ⇒ String/Symbol
This is the provider name (e.g. ‘:default`/`:cancancan`/`:pundit`) that can be set in Wallaby::ModelAuthorizer subclasses’s Wallaby::ModelAuthorizer.provider_name.
15 16 17 |
# File 'lib/interfaces/wallaby/model_authorization_provider.rb', line 15 def provider_name @provider_name ||= name.demodulize.gsub(/(Authorization)?Provider/, EMPTY_STRING).underscore end |
Instance Attribute Details
#options ⇒ Hash (readonly)
36 37 38 |
# File 'lib/interfaces/wallaby/model_authorization_provider.rb', line 36 def @options end |
Class Method Details
.available?(_context) ⇒ Boolean
Template method to check and see if current provider is in used.
22 23 24 |
# File 'lib/interfaces/wallaby/model_authorization_provider.rb', line 22 def available?(_context) raise NotImplemented end |
.options_from(_context) ⇒ Object
Template method to get the required data from context.
29 30 31 |
# File 'lib/interfaces/wallaby/model_authorization_provider.rb', line 29 def (_context) raise NotImplemented end |
Instance Method Details
#accessible_for(_action, _scope) ⇒ Object
It can be overridden in subclasses for customization purpose.
This is the template method to restrict user’s access to certain scope.
80 81 82 |
# File 'lib/interfaces/wallaby/model_authorization_provider.rb', line 80 def accessible_for(_action, _scope) raise NotImplemented end |
#attributes_for(_action, _subject) ⇒ Object
It can be overridden in subclasses for customization purpose.
This is the template method to restrict user’s modification to certain fields of given subject.
89 90 91 |
# File 'lib/interfaces/wallaby/model_authorization_provider.rb', line 89 def attributes_for(_action, _subject) raise NotImplemented end |
#authorize(_action, _subject) ⇒ Object
It can be overridden in subclasses for customization purpose.
This is the template method to check user’s permission for given action on given subject.
53 54 55 |
# File 'lib/interfaces/wallaby/model_authorization_provider.rb', line 53 def (_action, _subject) raise NotImplemented end |
#authorized?(_action, _subject) ⇒ Boolean
It can be overridden in subclasses for customization purpose.
This is the template method to check if user has permission for given action on given subject.
62 63 64 |
# File 'lib/interfaces/wallaby/model_authorization_provider.rb', line 62 def (_action, _subject) raise NotImplemented end |
#permit_params(_action, _subject) ⇒ Object
It can be overridden in subclasses for customization purpose.
This is the template method to restrict user’s mass assignment to certain fields of given subject.
98 99 100 |
# File 'lib/interfaces/wallaby/model_authorization_provider.rb', line 98 def permit_params(_action, _subject) raise NotImplemented end |
#unauthorized?(action, subject) ⇒ Boolean
It can be overridden in subclasses for customization purpose.
This is the template method to check if user has no permission for given action on given subject.
71 72 73 |
# File 'lib/interfaces/wallaby/model_authorization_provider.rb', line 71 def (action, subject) !(action, subject) end |
#user ⇒ Object?
Returns user object.
44 45 46 |
# File 'lib/interfaces/wallaby/model_authorization_provider.rb', line 44 def user [:user] end |