Sha256: 330abc4e4ce62f1ff90f8a66976757b43efbc294b7af60dae632abeddc8385c1
Contents?: true
Size: 784 Bytes
Versions: 1
Compression:
Stored size: 784 Bytes
Contents
# frozen_string_literal: true module Ibrain module Extentions class Roles < GraphQL::Schema::FieldExtension def after_resolve(object:, arguments:, **rest) raise IbrainErrors::PermissionError.new("You not have permission to access #{field&.name}") if is_invalid_role(object) # yield the current time as `memo` yield(object, arguments, rest) 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.3 | app/graphql/ibrain/extentions/roles.rb |