class FunWithJsonApi::SchemaValidators::CheckResourceIsAuthorised

Attributes

deserializer[R]
resource[R]
resource_id[R]
resource_pointer[R]

Public Class Methods

call(...) click to toggle source
# File lib/fun_with_json_api/schema_validators/check_resource_is_authorized.rb, line 6
def self.call(...)
  new(...).call
end
new(resource, resource_id, deserializer, resource_pointer: '/data') click to toggle source
# File lib/fun_with_json_api/schema_validators/check_resource_is_authorized.rb, line 15
def initialize(resource, resource_id, deserializer, resource_pointer: '/data')
  @resource = resource
  @resource_id = resource_id
  @deserializer = deserializer
  @resource_pointer = resource_pointer
end

Public Instance Methods

call() click to toggle source
# File lib/fun_with_json_api/schema_validators/check_resource_is_authorized.rb, line 22
def call
  unless deserializer.resource_authorizer.call(resource)
    raise Exceptions::UnauthorizedResource.new(
      "resource_authorizer method for '#{deserializer.type}' returned a false value",
      ExceptionPayload.new(
        pointer: resource_pointer,
        detail: unauthorized_resource_message
      )
    )
  end
end
resource_type() click to toggle source
# File lib/fun_with_json_api/schema_validators/check_resource_is_authorized.rb, line 34
def resource_type
  deserializer.type
end

Private Instance Methods

unauthorized_resource_message() click to toggle source
# File lib/fun_with_json_api/schema_validators/check_resource_is_authorized.rb, line 40
def unauthorized_resource_message
  I18n.t(
    :unauthorized_resource,
    resource: resource_type,
    resource_id: resource_id,
    scope: 'fun_with_json_api.find_resource_from_document'
  )
end