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]
|
self[:internal_use]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def write_access?
|
||||||
|
self[:write_access]
|
||||||
|
end
|
||||||
|
|
||||||
def current_administrateur
|
def current_administrateur
|
||||||
unless self[:administrateur_id]
|
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 })
|
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
|
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)
|
def partition_instructeurs_by(instructeurs)
|
||||||
instructeurs
|
instructeurs
|
||||||
.partition { _1.id.present? }
|
.partition { _1.id.present? }
|
||||||
|
|
|
@ -19,7 +19,7 @@ module Mutations
|
||||||
{ dossier: }
|
{ dossier: }
|
||||||
end
|
end
|
||||||
|
|
||||||
def ready?(justificatif: nil, **args)
|
def authorized_before_load?(justificatif: nil, **args)
|
||||||
if justificatif.present?
|
if justificatif.present?
|
||||||
validate_blob(justificatif)
|
validate_blob(justificatif)
|
||||||
else
|
else
|
||||||
|
|
|
@ -19,7 +19,7 @@ module Mutations
|
||||||
{ dossier: }
|
{ dossier: }
|
||||||
end
|
end
|
||||||
|
|
||||||
def ready?(justificatif: nil, **args)
|
def authorized_before_load?(justificatif: nil, **args)
|
||||||
if justificatif.present?
|
if justificatif.present?
|
||||||
validate_blob(justificatif)
|
validate_blob(justificatif)
|
||||||
else
|
else
|
||||||
|
|
|
@ -20,7 +20,7 @@ module Mutations
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def ready?(attachment: nil, **args)
|
def authorized_before_load?(attachment: nil, **args)
|
||||||
if attachment.present?
|
if attachment.present?
|
||||||
validate_blob(attachment)
|
validate_blob(attachment)
|
||||||
else
|
else
|
||||||
|
|
|
@ -19,7 +19,7 @@ module Mutations
|
||||||
{ dossier: }
|
{ dossier: }
|
||||||
end
|
end
|
||||||
|
|
||||||
def ready?(justificatif: nil, **args)
|
def authorized_before_load?(justificatif: nil, **args)
|
||||||
if justificatif.present?
|
if justificatif.present?
|
||||||
validate_blob(justificatif)
|
validate_blob(justificatif)
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Reference in a new issue