Module: GraphQR::Policies::AuthorizeGraphQL
- Included in:
- BaseResolver
- Defined in:
- lib/graphqr/policies/authorize_graphql.rb
Overview
The AuthorizeGraphQL module defines a way of running the PolicyProvider authorization with a specific action
Constant Summary collapse
- DEFAULT_AUTHORIZATION_ERROR =
'You are not authorized to perform this action'
Instance Method Summary collapse
-
#authorize_graphql(record, action, policy_class: nil) ⇒ Object
This method is a wrapper around the Pundit authorize, receiving the same arguments.
- #policy_provider ⇒ Object
Instance Method Details
#authorize_graphql(record, action, policy_class: nil) ⇒ Object
This method is a wrapper around the Pundit authorize, receiving the same arguments. The only difference is that it turns the Pundit::NotAuthorizedError into a GraphQL::ExecutionError
### Example:
“‘ authorize_graphql User, :index? “`
19 20 21 22 |
# File 'lib/graphqr/policies/authorize_graphql.rb', line 19 def (record, action, policy_class: nil) args = { record: record, action: action, policy_class: policy_class } raise GraphQL::ExecutionError, DEFAULT_AUTHORIZATION_ERROR unless policy_provider.allowed?(args) end |
#policy_provider ⇒ Object
24 25 26 |
# File 'lib/graphqr/policies/authorize_graphql.rb', line 24 def policy_provider context[:policy_provider] end |