Sha256: fdb13dd5ba2f47dbf8a95f8ee8fa07eeb016e5aa90aebba873fe06e769b42a0a

Contents?: true

Size: 727 Bytes

Versions: 45

Compression:

Stored size: 727 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)

        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)

        true
      end
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
ibrain-core-0.5.15 app/graphql/ibrain/extentions/roles.rb
ibrain-core-0.5.13 app/graphql/ibrain/extentions/roles.rb
ibrain-core-0.5.12 app/graphql/ibrain/extentions/roles.rb
ibrain-core-0.5.10 app/graphql/ibrain/extentions/roles.rb
ibrain-core-0.5.9 app/graphql/ibrain/extentions/roles.rb
ibrain-core-0.5.8 app/graphql/ibrain/extentions/roles.rb
ibrain-core-0.5.7 app/graphql/ibrain/extentions/roles.rb
ibrain-core-0.5.6 app/graphql/ibrain/extentions/roles.rb
ibrain-core-0.5.5 app/graphql/ibrain/extentions/roles.rb
ibrain-core-0.5.4 app/graphql/ibrain/extentions/roles.rb
ibrain-core-0.5.3 app/graphql/ibrain/extentions/roles.rb
ibrain-core-0.5.2 app/graphql/ibrain/extentions/roles.rb
ibrain-core-0.5.1 app/graphql/ibrain/extentions/roles.rb
ibrain-core-0.5.0 app/graphql/ibrain/extentions/roles.rb
ibrain-core-0.4.9 app/graphql/ibrain/extentions/roles.rb
ibrain-core-0.4.8 app/graphql/ibrain/extentions/roles.rb
ibrain-core-0.4.7 app/graphql/ibrain/extentions/roles.rb
ibrain-core-0.4.5 app/graphql/ibrain/extentions/roles.rb
ibrain-core-0.4.4 app/graphql/ibrain/extentions/roles.rb
ibrain-core-0.4.3 app/graphql/ibrain/extentions/roles.rb