Class: GraphqlPundit::AuthorizationExtension
- Inherits:
-
GraphQL::Schema::FieldExtension
- Object
- GraphQL::Schema::FieldExtension
- GraphqlPundit::AuthorizationExtension
- Includes:
- Common
- Defined in:
- lib/graphql_pundit/authorization_extension.rb
Overview
Authorization methods to be included in the used Field class
Instance Attribute Summary collapse
-
#authorize ⇒ Object
readonly
Returns the value of attribute authorize.
-
#policy ⇒ Object
readonly
Returns the value of attribute policy.
-
#raise_unauthorized ⇒ Object
readonly
Returns the value of attribute raise_unauthorized.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
- #apply ⇒ Object
-
#initialize(field:, options:) ⇒ AuthorizationExtension
constructor
A new instance of AuthorizationExtension.
- #resolve(object:, arguments:, context:, **_rest) ⇒ Object
Methods included from Common
Constructor Details
#initialize(field:, options:) ⇒ AuthorizationExtension
Returns a new instance of AuthorizationExtension.
10 11 12 13 |
# File 'lib/graphql_pundit/authorization_extension.rb', line 10 def initialize(field:, options:) super @current_user = [:current_user] || :current_user end |
Instance Attribute Details
#authorize ⇒ Object (readonly)
Returns the value of attribute authorize.
8 9 10 |
# File 'lib/graphql_pundit/authorization_extension.rb', line 8 def @authorize end |
#policy ⇒ Object (readonly)
Returns the value of attribute policy.
8 9 10 |
# File 'lib/graphql_pundit/authorization_extension.rb', line 8 def policy @policy end |
#raise_unauthorized ⇒ Object (readonly)
Returns the value of attribute raise_unauthorized.
8 9 10 |
# File 'lib/graphql_pundit/authorization_extension.rb', line 8 def @raise_unauthorized end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
8 9 10 |
# File 'lib/graphql_pundit/authorization_extension.rb', line 8 def record @record end |
Instance Method Details
#apply ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/graphql_pundit/authorization_extension.rb', line 15 def apply @raise_unauthorized = field. @authorize = field. @record = field.record @policy = field.policy @method_sym = field.method_sym end |
#resolve(object:, arguments:, context:, **_rest) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/graphql_pundit/authorization_extension.rb', line 23 def resolve(object:, arguments:, context:, **_rest) # yield the current time as `memo` raise ::Pundit::NotAuthorizedError unless (object, arguments, context) yield(object, arguments) rescue ::Pundit::NotAuthorizedError raise GraphQL::ExecutionError, "You're not authorized to do this" if @raise_unauthorized end |