Sha256: 3fe09b67464ea28c642a1cdb2760b25dba72032a43c99fc278b853f6463590a9
Contents?: true
Size: 756 Bytes
Versions: 1
Compression:
Stored size: 756 Bytes
Contents
# frozen_string_literal: true module Ibrain module Extentions class Roles < GraphQL::Schema::FieldExtension def after_resolve(object:, value:, **_rest) raise IbrainErrors::PermissionError.new("You not have permission to access #{field&.name}") if is_invalid_role(object) # yield the current time as `memo` value end private def is_invalid_role(object) roles = options.try(:fetch, :roles, []) current_user = object.try(:context).try(:fetch, :current_user, nil) role = current_user.try(:role) || current_user.try(:graphql_role) return if roles.blank? return true if current_user.blank? return false if roles.include?(role) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ibrain-core-0.2.4 | app/graphql/ibrain/extentions/roles.rb |