Class: Avo::Services::AuthorizationClients::PunditClient
- Inherits:
-
Object
- Object
- Avo::Services::AuthorizationClients::PunditClient
- Defined in:
- lib/avo/services/authorization_clients/pundit_client.rb
Instance Method Summary collapse
- #apply_policy(user, model, policy_class: nil) ⇒ Object
- #authorize(user, record, action, policy_class: nil) ⇒ Object
- #policy(user, record) ⇒ Object
- #policy!(user, record) ⇒ Object
Instance Method Details
#apply_policy(user, model, policy_class: nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/avo/services/authorization_clients/pundit_client.rb', line 23 def apply_policy(user, model, policy_class: nil) # Try and figure out the scope from a given policy or auto-detected one scope_from_policy_class = scope_for_policy_class(policy_class) # If we discover one use it. # Else fallback to pundit. if scope_from_policy_class.present? scope_from_policy_class.new(user, model).resolve else Pundit.policy_scope!(user, model) end rescue Pundit::NotDefinedError => error raise NoPolicyError.new error. end |
#authorize(user, record, action, policy_class: nil) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/avo/services/authorization_clients/pundit_client.rb', line 5 def (user, record, action, policy_class: nil) Pundit.(user, record, action, policy_class: policy_class) rescue Pundit::NotDefinedError => error raise NoPolicyError.new error. rescue Pundit::NotAuthorizedError => error raise NotAuthorizedError.new error. end |
#policy(user, record) ⇒ Object
13 14 15 |
# File 'lib/avo/services/authorization_clients/pundit_client.rb', line 13 def policy(user, record) Pundit.policy(user, record) end |
#policy!(user, record) ⇒ Object
17 18 19 20 21 |
# File 'lib/avo/services/authorization_clients/pundit_client.rb', line 17 def policy!(user, record) Pundit.policy!(user, record) rescue Pundit::NotDefinedError => error raise NoPolicyError.new error. end |