feat(graphql): add read_only check to mutations
This commit is contained in:
parent
64f79bb6d8
commit
85d31632e3
6 changed files with 20 additions and 4 deletions
|
@ -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 d’un jeton au nouveau format. Vous pouvez l’obtenir dans votre interface administrateur.", extensions: { code: :deprecated_token })
|
||||
|
|
|
@ -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? }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue