feat(graphql): add read_only check to mutations

This commit is contained in:
Paul Chavard 2023-02-13 14:25:17 +01:00
parent 64f79bb6d8
commit 85d31632e3
6 changed files with 20 additions and 4 deletions

View file

@ -26,6 +26,10 @@ class API::V2::Context < GraphQL::Query::Context
self[:internal_use]
end
def write_access?
self[:write_access]
end
def current_administrateur
unless self[:administrateur_id]
raise GraphQL::ExecutionError.new("Pour effectuer cette opération, vous avez besoin dun jeton au nouveau format. Vous pouvez lobtenir dans votre interface administrateur.", extensions: { code: :deprecated_token })

View file

@ -4,6 +4,18 @@ module Mutations
delegate :current_administrateur, to: :context
def ready?(**args)
if context.write_access?
authorized_before_load?(**args)
else
return false, { errors: ['Le jeton utilisé est configuré seulement en lecture'] }
end
end
def authorized_before_load?(**args)
true
end
def partition_instructeurs_by(instructeurs)
instructeurs
.partition { _1.id.present? }

View file

@ -19,7 +19,7 @@ module Mutations
{ dossier: }
end
def ready?(justificatif: nil, **args)
def authorized_before_load?(justificatif: nil, **args)
if justificatif.present?
validate_blob(justificatif)
else

View file

@ -19,7 +19,7 @@ module Mutations
{ dossier: }
end
def ready?(justificatif: nil, **args)
def authorized_before_load?(justificatif: nil, **args)
if justificatif.present?
validate_blob(justificatif)
else

View file

@ -20,7 +20,7 @@ module Mutations
end
end
def ready?(attachment: nil, **args)
def authorized_before_load?(attachment: nil, **args)
if attachment.present?
validate_blob(attachment)
else

View file

@ -19,7 +19,7 @@ module Mutations
{ dossier: }
end
def ready?(justificatif: nil, **args)
def authorized_before_load?(justificatif: nil, **args)
if justificatif.present?
validate_blob(justificatif)
else