Class: Osso::GraphQL::Types::BaseObject

Inherits:
GraphQL::Schema::Object
  • Object
show all
Defined in:
lib/osso/graphql/types/base_object.rb

Class Method Summary collapse

Class Method Details

.admin_authorized?(context) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/osso/graphql/types/base_object.rb', line 14

def self.admin_authorized?(context)
  context[:scope] == 'admin'
end

.authorized?(object, context) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
# File 'lib/osso/graphql/types/base_object.rb', line 28

def self.authorized?(object, context)
  # we first receive the payload object as a hash, but can depend on the
  # return type to hide the actual objects non-admins shouldn't see
  return true if object.instance_of?(Hash)

  internal_authorized?(context) || enterprise_authorized?(context, object&.domain)
end

.enterprise_authorized?(context, domain) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/osso/graphql/types/base_object.rb', line 22

def self.enterprise_authorized?(context, domain)
  return false unless domain

  context[:email].split('@')[1] == domain
end

.internal_authorized?(context) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/osso/graphql/types/base_object.rb', line 18

def self.internal_authorized?(context)
  %w[admin internal].include?(context[:scope])
end