require admin context for demarchesPubliques field

This commit is contained in:
Christophe Robillard 2022-06-10 10:51:09 +02:00
parent 78d772441b
commit fa1cbdc848
2 changed files with 15 additions and 1 deletions

View file

@ -0,0 +1,12 @@
module Types
class BaseField < GraphQL::Schema::Field
def initialize(*args, require_admin: false, **kwargs, &block)
@require_admin = require_admin
super(*args, **kwargs, &block)
end
def visible?(ctx)
super && (@require_admin ? ctx[:admin] : true)
end
end
end

View file

@ -1,5 +1,7 @@
module Types
class QueryType < Types::BaseObject
field_class BaseField
field :demarche, DemarcheType, null: false, description: "Informations concernant une démarche." do
argument :number, Int, "Numéro de la démarche.", required: true
end
@ -12,7 +14,7 @@ module Types
argument :number, Int, "Numéro du groupe instructeur.", required: true
end
field :demarches_publiques, DemarcheDescriptorType.connection_type, null: false
field :demarches_publiques, DemarcheDescriptorType.connection_type, null: false, require_admin: true
def demarches_publiques
Procedure.publiques