Merge pull request #8124 from tchak/graphql-demarche-publique
feat(graphql): make demarche schema public
This commit is contained in:
commit
907f3da3cf
6 changed files with 108 additions and 6 deletions
|
@ -60,8 +60,10 @@ class API::V2::GraphqlController < API::V2::BaseController
|
||||||
else
|
else
|
||||||
{}
|
{}
|
||||||
end
|
end
|
||||||
when Hash, ActionController::Parameters
|
when Hash
|
||||||
ambiguous_param
|
ambiguous_param
|
||||||
|
when ActionController::Parameters
|
||||||
|
ambiguous_param.to_unsafe_h
|
||||||
when nil
|
when nil
|
||||||
{}
|
{}
|
||||||
else
|
else
|
||||||
|
|
|
@ -177,6 +177,16 @@ class API::V2::StoredQuery
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
query getDemarcheDescriptor(
|
||||||
|
$demarche: FindDemarcheInput!
|
||||||
|
$includeRevision: Boolean = false
|
||||||
|
$includeService: Boolean = false
|
||||||
|
) {
|
||||||
|
demarcheDescriptor(demarche: $demarche) {
|
||||||
|
...DemarcheDescriptorFragment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fragment ServiceFragment on Service {
|
fragment ServiceFragment on Service {
|
||||||
nom
|
nom
|
||||||
siret
|
siret
|
||||||
|
|
|
@ -1495,6 +1495,18 @@ type File {
|
||||||
url: URL!
|
url: URL!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input FindDemarcheInput @oneOf {
|
||||||
|
"""
|
||||||
|
ID de la démarche.
|
||||||
|
"""
|
||||||
|
id: ID
|
||||||
|
|
||||||
|
"""
|
||||||
|
Numero de la démarche.
|
||||||
|
"""
|
||||||
|
number: Int
|
||||||
|
}
|
||||||
|
|
||||||
interface GeoArea {
|
interface GeoArea {
|
||||||
description: String
|
description: String
|
||||||
geometry: GeoJSON!
|
geometry: GeoJSON!
|
||||||
|
@ -2045,6 +2057,12 @@ type Query {
|
||||||
"""
|
"""
|
||||||
number: Int!
|
number: Int!
|
||||||
): Demarche!
|
): Demarche!
|
||||||
|
demarcheDescriptor(
|
||||||
|
"""
|
||||||
|
La démarche.
|
||||||
|
"""
|
||||||
|
demarche: FindDemarcheInput!
|
||||||
|
): DemarcheDescriptor
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Informations sur un dossier d’une démarche.
|
Informations sur un dossier d’une démarche.
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
module Types
|
module Types
|
||||||
class DemarcheDescriptorType < Types::BaseObject
|
class DemarcheDescriptorType < Types::BaseObject
|
||||||
field_class BaseField
|
field_class BaseField
|
||||||
|
|
||||||
|
class FindDemarcheInput < Types::BaseInputObject
|
||||||
|
one_of
|
||||||
|
argument :number, Int, "Numero de la démarche.", required: false
|
||||||
|
argument :id, ID, "ID de la démarche.", required: false
|
||||||
|
end
|
||||||
|
|
||||||
description "Une démarche (métadonnées)
|
description "Une démarche (métadonnées)
|
||||||
Ceci est une version abrégée du type `Demarche`, qui n’expose que les métadonnées.
|
Ceci est une version abrégée du type `Demarche`, qui n’expose que les métadonnées.
|
||||||
Cela évite l’accès récursif aux dossiers."
|
Cela évite l’accès récursif aux dossiers."
|
||||||
|
@ -87,11 +94,8 @@ Cela évite l’accès récursif aux dossiers."
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.authorized?(object, context)
|
def self.authorized?(object, context)
|
||||||
if object.is_a?(ProcedureRevision)
|
procedure = object.is_a?(ProcedureRevision) ? object.procedure : object
|
||||||
context.authorized_demarche?(object.procedure)
|
procedure.opendata? || context.authorized_demarche?(procedure)
|
||||||
else
|
|
||||||
context.authorized_demarche?(object)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -14,12 +14,23 @@ module Types
|
||||||
argument :number, Int, "Numéro du groupe instructeur.", required: true
|
argument :number, Int, "Numéro du groupe instructeur.", required: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
field :demarche_descriptor, DemarcheDescriptorType, null: true do
|
||||||
|
argument :demarche, DemarcheDescriptorType::FindDemarcheInput, "La démarche.", required: true
|
||||||
|
end
|
||||||
|
|
||||||
field :demarches_publiques, DemarcheDescriptorType.connection_type, null: false, internal: true
|
field :demarches_publiques, DemarcheDescriptorType.connection_type, null: false, internal: true
|
||||||
|
|
||||||
def demarches_publiques
|
def demarches_publiques
|
||||||
Procedure.opendata.includes(draft_revision: :procedure, published_revision: :procedure)
|
Procedure.opendata.includes(draft_revision: :procedure, published_revision: :procedure)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def demarche_descriptor(demarche:)
|
||||||
|
demarche_number = demarche.number.presence || ApplicationRecord.id_from_typed_id(demarche.id)
|
||||||
|
Procedure
|
||||||
|
.includes(draft_revision: :procedure, published_revision: :procedure)
|
||||||
|
.find_by(id: demarche_number)
|
||||||
|
end
|
||||||
|
|
||||||
def demarche(number:)
|
def demarche(number:)
|
||||||
Procedure.for_api_v2.find(number)
|
Procedure.for_api_v2.find(number)
|
||||||
rescue => e
|
rescue => e
|
||||||
|
|
|
@ -902,6 +902,63 @@ describe API::V2::GraphqlController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'getDemarcheDescriptor' do
|
||||||
|
let(:operation_name) { 'getDemarcheDescriptor' }
|
||||||
|
|
||||||
|
context 'find by number' do
|
||||||
|
let(:variables) { { demarche: { number: procedure.id } } }
|
||||||
|
|
||||||
|
it {
|
||||||
|
expect(gql_errors).to be_nil
|
||||||
|
expect(gql_data[:demarcheDescriptor][:id]).to eq(procedure.to_typed_id)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'find by id' do
|
||||||
|
let(:variables) { { demarche: { id: procedure.to_typed_id } } }
|
||||||
|
|
||||||
|
it {
|
||||||
|
expect(gql_errors).to be_nil
|
||||||
|
expect(gql_data[:demarcheDescriptor][:id]).to eq(procedure.to_typed_id)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'not opendata' do
|
||||||
|
let(:variables) { { demarche: { id: procedure.to_typed_id } } }
|
||||||
|
|
||||||
|
before { procedure.update(opendata: false) }
|
||||||
|
|
||||||
|
it {
|
||||||
|
expect(gql_errors).to be_nil
|
||||||
|
expect(gql_data[:demarcheDescriptor][:id]).to eq(procedure.to_typed_id)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'without authorization token' do
|
||||||
|
let(:authorization_header) { nil }
|
||||||
|
|
||||||
|
context 'opendata' do
|
||||||
|
let(:variables) { { demarche: { id: procedure.to_typed_id } } }
|
||||||
|
|
||||||
|
it {
|
||||||
|
expect(gql_errors).to be_nil
|
||||||
|
expect(gql_data[:demarcheDescriptor][:id]).to eq(procedure.to_typed_id)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'not opendata' do
|
||||||
|
let(:variables) { { demarche: { id: procedure.to_typed_id } } }
|
||||||
|
|
||||||
|
before { procedure.update(opendata: false) }
|
||||||
|
|
||||||
|
it {
|
||||||
|
expect(gql_errors).not_to be_nil
|
||||||
|
expect(gql_errors.first[:message]).to eq('An object of type DemarcheDescriptor was hidden due to permissions')
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'mutation' do
|
context 'mutation' do
|
||||||
let(:query_id) { 'ds-mutation-v2' }
|
let(:query_id) { 'ds-mutation-v2' }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue