Module: GraphQL::Pundit::Authorization
- Included in:
- Field
- Defined in:
- lib/graphql-pundit/authorization.rb
Overview
Authorization methods to be included in the used Field class
Class Method Summary collapse
Instance Method Summary collapse
- #authorize(*args, record: nil, policy: nil) ⇒ Object
- #authorize!(*args, record: nil, policy: nil) ⇒ Object
-
#initialize(*args, authorize: nil, record: nil, policy: nil, **kwargs, &block) ⇒ Object
rubocop:disable Metrics/ParameterLists.
- #resolve_field(obj, args, ctx) ⇒ Object
Class Method Details
Instance Method Details
#authorize(*args, record: nil, policy: nil) ⇒ Object
28 29 30 31 32 |
# File 'lib/graphql-pundit/authorization.rb', line 28 def (*args, record: nil, policy: nil) @authorize = args[0] || true @record = record if record @policy = policy if policy end |
#authorize!(*args, record: nil, policy: nil) ⇒ Object
34 35 36 37 |
# File 'lib/graphql-pundit/authorization.rb', line 34 def (*args, record: nil, policy: nil) @do_raise = true (*args, record: record, policy: policy) end |
#initialize(*args, authorize: nil, record: nil, policy: nil, **kwargs, &block) ⇒ Object
rubocop:disable Metrics/ParameterLists
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/graphql-pundit/authorization.rb', line 14 def initialize(*args, authorize: nil, record: nil, policy: nil, **kwargs, &block) # rubocop:enable Metrics/ParameterLists # authorize! is not a valid variable name = kwargs.delete(:authorize!) @record = record if record @policy = policy if policy @authorize = || @do_raise = !! super(*args, **kwargs, &block) end |
#resolve_field(obj, args, ctx) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/graphql-pundit/authorization.rb', line 39 def resolve_field(obj, args, ctx) raise ::Pundit::NotAuthorizedError unless (obj, args, ctx) super(obj, args, ctx) rescue ::Pundit::NotAuthorizedError if @do_raise raise GraphQL::ExecutionError, "You're not authorized to do this" end end |