class Osso::GraphQL::Mutations::BaseMutation

Public Instance Methods

account_domain(id) click to toggle source
# File lib/osso/graphql/mutations/base_mutation.rb, line 55
def account_domain(id)
  return false unless id

  Osso::Models::EnterpriseAccount.find(id)&.domain
end
admin_ready?() click to toggle source
# File lib/osso/graphql/mutations/base_mutation.rb, line 41
def admin_ready?
  context[:scope] == 'admin'
end
domain_ready?(domain) click to toggle source
# File lib/osso/graphql/mutations/base_mutation.rb, line 51
def domain_ready?(domain)
  context[:email].split('@')[1] == domain
end
field_errors(errors) click to toggle source
# File lib/osso/graphql/mutations/base_mutation.rb, line 23
def field_errors(errors)
  errors.map do |attribute, messages|
    attribute = attribute.to_s.camelize(:lower)
    {
      attribute: attribute,
      message: messages,
    }
  end
end
internal_ready?() click to toggle source
# File lib/osso/graphql/mutations/base_mutation.rb, line 45
def internal_ready?
  return true if admin_ready?

  context[:scope] == 'internal'
end
provider_domain(id) click to toggle source
# File lib/osso/graphql/mutations/base_mutation.rb, line 61
def provider_domain(id)
  return false unless id

  Osso::Models::IdentityProvider.find(id)&.domain
end
ready?(**args) click to toggle source
# File lib/osso/graphql/mutations/base_mutation.rb, line 33
def ready?(**args)
  return true if internal_ready?

  return true if domain_ready?(args[:domain] || domain(**args))

  raise ::GraphQL::ExecutionError, 'This user lacks the permission to make the requested changes'
end
response_data(data) click to toggle source
# File lib/osso/graphql/mutations/base_mutation.rb, line 10
def response_data(data)
  data.merge(errors: [])
end
response_error(errors) click to toggle source
# File lib/osso/graphql/mutations/base_mutation.rb, line 14
def response_error(errors)
  raise ::GraphQL::ExecutionError.new(
    'Mutation error',
    extensions: {
      'errors' => field_errors(errors),
    },
  )
end