diff --git a/app/graphql/api/v2/context.rb b/app/graphql/api/v2/context.rb index b8ebb2c30..b555453ab 100644 --- a/app/graphql/api/v2/context.rb +++ b/app/graphql/api/v2/context.rb @@ -22,11 +22,15 @@ class API::V2::Context < GraphQL::Query::Context Administrateur.find(self[:administrateur_id]) end - def authorized_demarche?(demarche) + def authorized_demarche?(demarche, opendata: false) if internal_use? return true end + if opendata && demarche.opendata? + return true + end + # We are caching authorization logic because it is called for each node # of the requested graph and can be expensive. Context is reset per request so it is safe. self[:authorized] ||= Hash.new do |hash, demarche_id| diff --git a/app/graphql/api/v2/schema.rb b/app/graphql/api/v2/schema.rb index 08614aff9..2b1b50d5b 100644 --- a/app/graphql/api/v2/schema.rb +++ b/app/graphql/api/v2/schema.rb @@ -75,7 +75,42 @@ class API::V2::Schema < GraphQL::Schema Types::GeoAreas::ParcelleCadastraleType, Types::GeoAreas::SelectionUtilisateurType, Types::PersonneMoraleType, - Types::PersonnePhysiqueType + Types::PersonnePhysiqueType, + Types::Champs::Descriptor::AddressChampDescriptorType, + Types::Champs::Descriptor::AnnuaireEducationChampDescriptorType, + Types::Champs::Descriptor::CarteChampDescriptorType, + Types::Champs::Descriptor::CheckboxChampDescriptorType, + Types::Champs::Descriptor::CiviliteChampDescriptorType, + Types::Champs::Descriptor::CnafChampDescriptorType, + Types::Champs::Descriptor::CommuneChampDescriptorType, + Types::Champs::Descriptor::DateChampDescriptorType, + Types::Champs::Descriptor::DatetimeChampDescriptorType, + Types::Champs::Descriptor::DecimalNumberChampDescriptorType, + Types::Champs::Descriptor::DepartementChampDescriptorType, + Types::Champs::Descriptor::DgfipChampDescriptorType, + Types::Champs::Descriptor::DossierLinkChampDescriptorType, + Types::Champs::Descriptor::DropDownListChampDescriptorType, + Types::Champs::Descriptor::EmailChampDescriptorType, + Types::Champs::Descriptor::ExplicationChampDescriptorType, + Types::Champs::Descriptor::HeaderSectionChampDescriptorType, + Types::Champs::Descriptor::IbanChampDescriptorType, + Types::Champs::Descriptor::IntegerNumberChampDescriptorType, + Types::Champs::Descriptor::LinkedDropDownListChampDescriptorType, + Types::Champs::Descriptor::MesriChampDescriptorType, + Types::Champs::Descriptor::MultipleDropDownListChampDescriptorType, + Types::Champs::Descriptor::NumberChampDescriptorType, + Types::Champs::Descriptor::PaysChampDescriptorType, + Types::Champs::Descriptor::PhoneChampDescriptorType, + Types::Champs::Descriptor::PieceJustificativeChampDescriptorType, + Types::Champs::Descriptor::PoleEmploiChampDescriptorType, + Types::Champs::Descriptor::RegionChampDescriptorType, + Types::Champs::Descriptor::RepetitionChampDescriptorType, + Types::Champs::Descriptor::RNAChampDescriptorType, + Types::Champs::Descriptor::SiretChampDescriptorType, + Types::Champs::Descriptor::TextChampDescriptorType, + Types::Champs::Descriptor::TextareaChampDescriptorType, + Types::Champs::Descriptor::TitreIdentiteChampDescriptorType, + Types::Champs::Descriptor::YesNoChampDescriptorType def self.unauthorized_object(error) # Add a top-level error to the response instead of returning nil: diff --git a/app/graphql/api/v2/stored_query.rb b/app/graphql/api/v2/stored_query.rb index 80177c1d3..ab473ae72 100644 --- a/app/graphql/api/v2/stored_query.rb +++ b/app/graphql/api/v2/stored_query.rb @@ -50,7 +50,7 @@ class API::V2::StoredQuery declarative dateCreation dateFermeture - publishedRevision @include(if: $includeRevision) { + activeRevision @include(if: $includeRevision) { ...RevisionFragment } groupeInstructeurs @include(if: $includeGroupeInstructeurs) { @@ -305,25 +305,65 @@ class API::V2::StoredQuery datePublication champDescriptors { ...ChampDescriptorFragment - champDescriptors { - ...ChampDescriptorFragment + ... on RepetitionChampDescriptor { + champDescriptors { + ...ChampDescriptorFragment + } } } annotationDescriptors { ...ChampDescriptorFragment - champDescriptors { - ...ChampDescriptorFragment + ... on RepetitionChampDescriptor { + champDescriptors { + ...ChampDescriptorFragment + } } } } fragment ChampDescriptorFragment on ChampDescriptor { + __typename id - type label description required - options + ... on DropDownListChampDescriptor { + options + otherOption + } + ... on MultipleDropDownListChampDescriptor { + options + } + ... on LinkedDropDownListChampDescriptor { + options + } + ... on PieceJustificativeChampDescriptor { + fileTemplate { + ...FileFragment + } + } + ... on ExplicationChampDescriptor { + collapsibleExplanationEnabled + collapsibleExplanationText + } + ... on PaysChampDescriptor { + options { + name + code + } + } + ... on RegionChampDescriptor { + options { + name + code + } + } + ... on DepartementChampDescriptor { + options { + name + code + } + } } fragment AvisFragment on Avis { diff --git a/app/graphql/extensions/attachment.rb b/app/graphql/extensions/attachment.rb index 987c61f31..72462da35 100644 --- a/app/graphql/extensions/attachment.rb +++ b/app/graphql/extensions/attachment.rb @@ -3,7 +3,7 @@ module Extensions class Attachment < GraphQL::Schema::FieldExtension - attr_reader :attachment_assoc + attr_reader :attachment_assoc, :root def apply # Here we try to define the ActiveRecord association name: @@ -18,13 +18,14 @@ module Extensions attachment = field.original_name.to_s.sub(/_url$/, "") "#{attachment}_attachment" end + @root = options&.dig(:root) || :object end # This method resolves (as it states) the field itself # (it's the same as defining a method within a type) def resolve(object:, **_rest) Loaders::Association.for( - object.object.class, + object.public_send(root).class, attachment_assoc => :blob ).load(object.object) end diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index 41fce971b..1bf7e53f1 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -80,6 +80,39 @@ type AddressChamp implements Champ { stringValue: String } +type AddressChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + enum AddressType { """ numéro « à la plaque » @@ -102,6 +135,39 @@ enum AddressType { street } +type AnnuaireEducationChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + type Association { dateCreation: ISO8601Date dateDeclaration: ISO8601Date @@ -145,25 +211,11 @@ type CarteChamp implements Champ { stringValue: String } -interface Champ { - id: ID! - - """ - Libellé du champ. - """ - label: String! - - """ - La valeur du champ sous forme texte. - """ - stringValue: String -} - -type ChampDescriptor { +type CarteChampDescriptor implements ChampDescriptor { """ Description des champs d’un bloc répétable. """ - champDescriptors: [ChampDescriptor!] + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") """ Description du champ. @@ -179,7 +231,7 @@ type ChampDescriptor { """ List des options d’un champ avec selection. """ - options: [String!] + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") """ Est-ce que le champ est obligatoire ? @@ -189,7 +241,54 @@ type ChampDescriptor { """ Type de la valeur du champ. """ - type: TypeDeChamp! + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + +interface Champ { + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + La valeur du champ sous forme texte. + """ + stringValue: String +} + +interface ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") } type CheckboxChamp implements Champ { @@ -207,6 +306,39 @@ type CheckboxChamp implements Champ { value: Boolean! } +type CheckboxChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + enum Civilite { """ Monsieur @@ -234,6 +366,72 @@ type CiviliteChamp implements Champ { value: Civilite } +type CiviliteChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + +type CnafChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + type Commune { """ Le code INSEE @@ -258,6 +456,39 @@ type CommuneChamp implements Champ { stringValue: String } +type CommuneChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + """ GeoJSON coordinates """ @@ -332,6 +563,39 @@ type DateChamp implements Champ { value: ISO8601DateTime @deprecated(reason: "Utilisez le champ `date` ou le fragment `DatetimeChamp` à la place.") } +type DateChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + type DatetimeChamp implements Champ { """ La valeur du champ formaté en ISO8601 (DateTime). @@ -350,6 +614,39 @@ type DatetimeChamp implements Champ { stringValue: String } +type DatetimeChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + type DecimalNumberChamp implements Champ { id: ID! @@ -365,6 +662,39 @@ type DecimalNumberChamp implements Champ { value: Float } +type DecimalNumberChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + """ Un dossier supprimé """ @@ -633,7 +963,7 @@ Ceci est une version abrégée du type `Demarche`, qui n’expose que les métad Cela évite l’accès récursif aux dossiers. """ type DemarcheDescriptor { - cadreJuridique: String + cadreJuridiqueUrl: String """ Date de la création. @@ -664,30 +994,44 @@ type DemarcheDescriptor { Pour une démarche déclarative, état cible des dossiers à valider automatiquement """ declarative: DossierDeclarativeState - deliberation: String + deliberation: File + demarcheUrl: String """ Description de la démarche. """ description: String! + dpoUrl: String + + """ + Durée de conservation des dossiers en mois. + """ + dureeConservationDossiers: Int! id: ID! + logo: File + notice: File + noticeUrl: String """ Numero de la démarche. """ number: Int! + opendata: Boolean! revision: Revision! service: Service + siteWebUrl: String """ État de la démarche. """ state: DemarcheState! + tags: [String!]! """ Titre de la démarche. """ title: String! + zones: [String!]! } enum DemarcheState { @@ -732,6 +1076,72 @@ type DepartementChamp implements Champ { stringValue: String } +type DepartementChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des departements. + """ + options: [Departement!] + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + +type DgfipChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + """ Represents direct upload credentials """ @@ -1074,6 +1484,39 @@ type DossierLinkChamp implements Champ { stringValue: String } +type DossierLinkChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + """ Autogenerated input type of DossierModifierAnnotationAjouterLigne """ @@ -1484,11 +1927,82 @@ enum DossierState { sans_suite } +type DropDownListChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] + + """ + La selection contien l’option "Autre". + """ + otherOption: Boolean + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + type Effectif { nb: Float! periode: String! } +type EmailChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + type Entreprise { attestationFiscaleAttachment: File attestationSocialeAttachment: File @@ -1534,6 +2048,41 @@ enum EntrepriseEtatAdministratif { Ferme } +type ExplicationChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + collapsibleExplanationEnabled: Boolean + collapsibleExplanationText: String + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + type File { byteSize: Int! @deprecated(reason: "Utilisez le champ `byteSizeBigInt` à la place.") byteSizeBigInt: BigInt! @@ -1878,6 +2427,39 @@ type GroupeInstructeurWithDossiers { number: Int! } +type HeaderSectionChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + """ An ISO 8601-encoded date """ @@ -1888,6 +2470,39 @@ An ISO 8601-encoded datetime """ scalar ISO8601DateTime +type IbanChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + type IntegerNumberChamp implements Champ { id: ID! @@ -1903,6 +2518,39 @@ type IntegerNumberChamp implements Champ { value: BigInt } +type IntegerNumberChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + type LinkedDropDownListChamp implements Champ { id: ID! @@ -1919,6 +2567,72 @@ type LinkedDropDownListChamp implements Champ { stringValue: String } +type LinkedDropDownListChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + +type MesriChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + type Message { attachment: File @deprecated(reason: "Utilisez le champ `attachments` à la place.") attachments: [File!]! @@ -1943,6 +2657,39 @@ type MultipleDropDownListChamp implements Champ { values: [String!]! } +type MultipleDropDownListChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + type Mutation { """ File information required to prepare a direct upload @@ -2151,6 +2898,39 @@ type Mutation { ): GroupeInstructeurSupprimerInstructeursPayload } +type NumberChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + enum Order { """ L’ordre ascendant. @@ -2227,6 +3007,39 @@ type PaysChamp implements Champ { stringValue: String } +type PaysChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des pays. + """ + options: [Pays!] + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + type PersonneMorale implements Demandeur { address: Address! adresse: String! @deprecated(reason: "Utilisez le champ `address.label` à la place.") @@ -2254,6 +3067,39 @@ type PersonnePhysique implements Demandeur { prenom: String! } +type PhoneChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + type PieceJustificativeChamp implements Champ { file: File @deprecated(reason: "Utilisez le champ `files` à la place.") files: [File!]! @@ -2270,6 +3116,77 @@ type PieceJustificativeChamp implements Champ { stringValue: String } +type PieceJustificativeChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + + """ + Modèle de la pièce justificative. + """ + fileTemplate: File + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + +type PoleEmploiChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + type Profile { email: String! id: ID! @@ -2325,6 +3242,39 @@ type Query { ): GroupeInstructeurWithDossiers! } +type RNAChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + type Region { code: String! name: String! @@ -2345,6 +3295,39 @@ type RegionChamp implements Champ { stringValue: String } +type RegionChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des regions. + """ + options: [Region!] + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + type RepetitionChamp implements Champ { champs: [Champ!]! @deprecated(reason: "Utilisez le champ `rows` à la place.") id: ID! @@ -2361,6 +3344,39 @@ type RepetitionChamp implements Champ { stringValue: String } +type RepetitionChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + type Revision { annotationDescriptors: [ChampDescriptor!]! champDescriptors: [ChampDescriptor!]! @@ -2412,6 +3428,39 @@ type SiretChamp implements Champ { stringValue: String } +type SiretChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + type TextChamp implements Champ { id: ID! @@ -2427,6 +3476,72 @@ type TextChamp implements Champ { value: String } +type TextChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + +type TextareaChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + type TitreIdentiteChamp implements Champ { filled: Boolean! grantType: TitreIdentiteGrantType! @@ -2443,6 +3558,39 @@ type TitreIdentiteChamp implements Champ { stringValue: String } +type TitreIdentiteChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} + enum TitreIdentiteGrantType { """ Françe Connect @@ -2701,3 +3849,36 @@ type WarningMessage { """ message: String! } + +type YesNoChampDescriptor implements ChampDescriptor { + """ + Description des champs d’un bloc répétable. + """ + champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.") + + """ + Description du champ. + """ + description: String + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + List des options d’un champ avec selection. + """ + options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + + """ + Est-ce que le champ est obligatoire ? + """ + required: Boolean! + + """ + Type de la valeur du champ. + """ + type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") +} diff --git a/app/graphql/types/champ_descriptor_type.rb b/app/graphql/types/champ_descriptor_type.rb index 6aaff96b1..dbac1c088 100644 --- a/app/graphql/types/champ_descriptor_type.rb +++ b/app/graphql/types/champ_descriptor_type.rb @@ -1,5 +1,7 @@ module Types - class ChampDescriptorType < Types::BaseObject + module ChampDescriptorType + include Types::BaseInterface + class TypeDeChampType < Types::BaseEnum TypeDeChamp.type_champs.each do |symbol_name, string_name| value(string_name, @@ -9,24 +11,107 @@ module Types end global_id_field :id - field :type, TypeDeChampType, "Type de la valeur du champ.", null: false, method: :type_champ field :label, String, "Libellé du champ.", null: false, method: :libelle field :description, String, "Description du champ.", null: true field :required, Boolean, "Est-ce que le champ est obligatoire ?", null: false, method: :mandatory? - field :champ_descriptors, [Types::ChampDescriptorType], "Description des champs d’un bloc répétable.", null: true - field :options, [String], "List des options d’un champ avec selection.", null: true + field :options, [String], "List des options d’un champ avec selection.", null: true, deprecation_reason: 'Utilisez le champ `DropDownListChampDescriptor.options` à la place.' + field :champ_descriptors, [Types::ChampDescriptorType], "Description des champs d’un bloc répétable.", null: true, deprecation_reason: 'Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.' + field :type, TypeDeChampType, "Type de la valeur du champ.", null: false, method: :type_champ, deprecation_reason: 'Utilisez le champ `__typename` à la place.' + + definition_methods do + def resolve_type(object, context) + case object.type_champ + when TypeDeChamp.type_champs.fetch(:text) + Types::Champs::Descriptor::TextChampDescriptorType + when TypeDeChamp.type_champs.fetch(:textarea) + Types::Champs::Descriptor::TextareaChampDescriptorType + when TypeDeChamp.type_champs.fetch(:date) + Types::Champs::Descriptor::DateChampDescriptorType + when TypeDeChamp.type_champs.fetch(:datetime) + Types::Champs::Descriptor::DatetimeChampDescriptorType + when TypeDeChamp.type_champs.fetch(:number) + Types::Champs::Descriptor::NumberChampDescriptorType + when TypeDeChamp.type_champs.fetch(:decimal_number) + Types::Champs::Descriptor::DecimalNumberChampDescriptorType + when TypeDeChamp.type_champs.fetch(:integer_number) + Types::Champs::Descriptor::IntegerNumberChampDescriptorType + when TypeDeChamp.type_champs.fetch(:checkbox) + Types::Champs::Descriptor::CheckboxChampDescriptorType + when TypeDeChamp.type_champs.fetch(:civilite) + Types::Champs::Descriptor::CiviliteChampDescriptorType + when TypeDeChamp.type_champs.fetch(:email) + Types::Champs::Descriptor::EmailChampDescriptorType + when TypeDeChamp.type_champs.fetch(:phone) + Types::Champs::Descriptor::PhoneChampDescriptorType + when TypeDeChamp.type_champs.fetch(:address) + Types::Champs::Descriptor::AddressChampDescriptorType + when TypeDeChamp.type_champs.fetch(:yes_no) + Types::Champs::Descriptor::YesNoChampDescriptorType + when TypeDeChamp.type_champs.fetch(:drop_down_list) + Types::Champs::Descriptor::DropDownListChampDescriptorType + when TypeDeChamp.type_champs.fetch(:multiple_drop_down_list) + Types::Champs::Descriptor::MultipleDropDownListChampDescriptorType + when TypeDeChamp.type_champs.fetch(:linked_drop_down_list) + Types::Champs::Descriptor::LinkedDropDownListChampDescriptorType + when TypeDeChamp.type_champs.fetch(:communes) + Types::Champs::Descriptor::CommuneChampDescriptorType + when TypeDeChamp.type_champs.fetch(:departements) + Types::Champs::Descriptor::DepartementChampDescriptorType + when TypeDeChamp.type_champs.fetch(:regions) + Types::Champs::Descriptor::RegionChampDescriptorType + when TypeDeChamp.type_champs.fetch(:pays) + Types::Champs::Descriptor::PaysChampDescriptorType + when TypeDeChamp.type_champs.fetch(:header_section) + Types::Champs::Descriptor::HeaderSectionChampDescriptorType + when TypeDeChamp.type_champs.fetch(:explication) + Types::Champs::Descriptor::ExplicationChampDescriptorType + when TypeDeChamp.type_champs.fetch(:dossier_link) + Types::Champs::Descriptor::DossierLinkChampDescriptorType + when TypeDeChamp.type_champs.fetch(:piece_justificative) + Types::Champs::Descriptor::PieceJustificativeChampDescriptorType + when TypeDeChamp.type_champs.fetch(:rna) + Types::Champs::Descriptor::RNAChampDescriptorType + when TypeDeChamp.type_champs.fetch(:carte) + Types::Champs::Descriptor::CarteChampDescriptorType + when TypeDeChamp.type_champs.fetch(:repetition) + Types::Champs::Descriptor::RepetitionChampDescriptorType + when TypeDeChamp.type_champs.fetch(:titre_identite) + Types::Champs::Descriptor::TitreIdentiteChampDescriptorType + when TypeDeChamp.type_champs.fetch(:iban) + Types::Champs::Descriptor::IbanChampDescriptorType + when TypeDeChamp.type_champs.fetch(:siret) + Types::Champs::Descriptor::SiretChampDescriptorType + when TypeDeChamp.type_champs.fetch(:annuaire_education) + Types::Champs::Descriptor::AnnuaireEducationChampDescriptorType + when TypeDeChamp.type_champs.fetch(:cnaf) + Types::Champs::Descriptor::CnafChampDescriptorType + when TypeDeChamp.type_champs.fetch(:dgfip) + Types::Champs::Descriptor::DgfipChampDescriptorType + when TypeDeChamp.type_champs.fetch(:pole_emploi) + Types::Champs::Descriptor::PoleEmploiChampDescriptorType + when TypeDeChamp.type_champs.fetch(:mesri) + Types::Champs::Descriptor::MesriChampDescriptorType + end + end + end def champ_descriptors - if object.type_de_champ.block? + if type_de_champ.block? Loaders::Association.for(object.class, revision_types_de_champ: :type_de_champ).load(object) end end def options - if object.type_de_champ.drop_down_list? - object.type_de_champ.drop_down_list_options.reject(&:empty?) + if type_de_champ.drop_down_list? + type_de_champ.drop_down_list_options.reject(&:empty?) end end + + private + + def type_de_champ + object.type_de_champ + end end end diff --git a/app/graphql/types/champs/descriptor/address_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/address_champ_descriptor_type.rb new file mode 100644 index 000000000..913e96014 --- /dev/null +++ b/app/graphql/types/champs/descriptor/address_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class AddressChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/annuaire_education_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/annuaire_education_champ_descriptor_type.rb new file mode 100644 index 000000000..e804ba55b --- /dev/null +++ b/app/graphql/types/champs/descriptor/annuaire_education_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class AnnuaireEducationChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/carte_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/carte_champ_descriptor_type.rb new file mode 100644 index 000000000..aba9d3f67 --- /dev/null +++ b/app/graphql/types/champs/descriptor/carte_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class CarteChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/checkbox_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/checkbox_champ_descriptor_type.rb new file mode 100644 index 000000000..4e53692dc --- /dev/null +++ b/app/graphql/types/champs/descriptor/checkbox_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class CheckboxChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/civilite_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/civilite_champ_descriptor_type.rb new file mode 100644 index 000000000..1e507d010 --- /dev/null +++ b/app/graphql/types/champs/descriptor/civilite_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class CiviliteChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/cnaf_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/cnaf_champ_descriptor_type.rb new file mode 100644 index 000000000..9009db823 --- /dev/null +++ b/app/graphql/types/champs/descriptor/cnaf_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class CnafChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/commune_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/commune_champ_descriptor_type.rb new file mode 100644 index 000000000..1acc59644 --- /dev/null +++ b/app/graphql/types/champs/descriptor/commune_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class CommuneChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/date_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/date_champ_descriptor_type.rb new file mode 100644 index 000000000..f938278af --- /dev/null +++ b/app/graphql/types/champs/descriptor/date_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class DateChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/datetime_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/datetime_champ_descriptor_type.rb new file mode 100644 index 000000000..cff001222 --- /dev/null +++ b/app/graphql/types/champs/descriptor/datetime_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class DatetimeChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/decimal_number__champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/decimal_number__champ_descriptor_type.rb new file mode 100644 index 000000000..22564eb01 --- /dev/null +++ b/app/graphql/types/champs/descriptor/decimal_number__champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class DecimalNumberChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/departement_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/departement_champ_descriptor_type.rb new file mode 100644 index 000000000..f1fac4ff9 --- /dev/null +++ b/app/graphql/types/champs/descriptor/departement_champ_descriptor_type.rb @@ -0,0 +1,11 @@ +module Types::Champs::Descriptor + class DepartementChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + + field :options, [Types::Champs::DepartementChampType::DepartementType], "List des departements.", null: true + + def options + APIGeoService.departements + end + end +end diff --git a/app/graphql/types/champs/descriptor/dgfip_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/dgfip_champ_descriptor_type.rb new file mode 100644 index 000000000..60b57d638 --- /dev/null +++ b/app/graphql/types/champs/descriptor/dgfip_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class DgfipChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/dossier_link_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/dossier_link_champ_descriptor_type.rb new file mode 100644 index 000000000..2d17cbcc7 --- /dev/null +++ b/app/graphql/types/champs/descriptor/dossier_link_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class DossierLinkChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/drop_down_list_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/drop_down_list_champ_descriptor_type.rb new file mode 100644 index 000000000..227a70b9a --- /dev/null +++ b/app/graphql/types/champs/descriptor/drop_down_list_champ_descriptor_type.rb @@ -0,0 +1,16 @@ +module Types::Champs::Descriptor + class DropDownListChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + + field :options, [String], "List des options d’un champ avec selection.", null: true + field :other_option, Boolean, "La selection contien l’option \"Autre\".", null: true + + def other_option + object.type_de_champ.drop_down_other? + end + + def options + object.type_de_champ.drop_down_list_options.reject(&:empty?) + end + end +end diff --git a/app/graphql/types/champs/descriptor/email_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/email_champ_descriptor_type.rb new file mode 100644 index 000000000..af957f2a3 --- /dev/null +++ b/app/graphql/types/champs/descriptor/email_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class EmailChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/explication_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/explication_champ_descriptor_type.rb new file mode 100644 index 000000000..329cd0df0 --- /dev/null +++ b/app/graphql/types/champs/descriptor/explication_champ_descriptor_type.rb @@ -0,0 +1,16 @@ +module Types::Champs::Descriptor + class ExplicationChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + + field :collapsible_explanation_enabled, Boolean, null: true + field :collapsible_explanation_text, String, null: true + + def collapsible_explanation_enabled + object.type_de_champ.collapsible_explanation_enabled? + end + + def collapsible_explanation_text + object.type_de_champ.collapsible_explanation_text + end + end +end diff --git a/app/graphql/types/champs/descriptor/header_section_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/header_section_champ_descriptor_type.rb new file mode 100644 index 000000000..8e8881e74 --- /dev/null +++ b/app/graphql/types/champs/descriptor/header_section_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class HeaderSectionChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/iban_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/iban_champ_descriptor_type.rb new file mode 100644 index 000000000..b6418a612 --- /dev/null +++ b/app/graphql/types/champs/descriptor/iban_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class IbanChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/integer_number_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/integer_number_champ_descriptor_type.rb new file mode 100644 index 000000000..3e921ea1d --- /dev/null +++ b/app/graphql/types/champs/descriptor/integer_number_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class IntegerNumberChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/linked_drop_down_list_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/linked_drop_down_list_champ_descriptor_type.rb new file mode 100644 index 000000000..2794d1146 --- /dev/null +++ b/app/graphql/types/champs/descriptor/linked_drop_down_list_champ_descriptor_type.rb @@ -0,0 +1,11 @@ +module Types::Champs::Descriptor + class LinkedDropDownListChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + + field :options, [String], "List des options d’un champ avec selection.", null: true + + def options + object.type_de_champ.drop_down_list_options.reject(&:empty?) + end + end +end diff --git a/app/graphql/types/champs/descriptor/mesri_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/mesri_champ_descriptor_type.rb new file mode 100644 index 000000000..61ac75f1a --- /dev/null +++ b/app/graphql/types/champs/descriptor/mesri_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class MesriChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/multiple_drop_down_list_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/multiple_drop_down_list_champ_descriptor_type.rb new file mode 100644 index 000000000..0bc83759d --- /dev/null +++ b/app/graphql/types/champs/descriptor/multiple_drop_down_list_champ_descriptor_type.rb @@ -0,0 +1,11 @@ +module Types::Champs::Descriptor + class MultipleDropDownListChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + + field :options, [String], "List des options d’un champ avec selection.", null: true + + def options + object.type_de_champ.drop_down_list_options.reject(&:empty?) + end + end +end diff --git a/app/graphql/types/champs/descriptor/number_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/number_champ_descriptor_type.rb new file mode 100644 index 000000000..cda88d61f --- /dev/null +++ b/app/graphql/types/champs/descriptor/number_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class NumberChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/pays_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/pays_champ_descriptor_type.rb new file mode 100644 index 000000000..0da7b47a3 --- /dev/null +++ b/app/graphql/types/champs/descriptor/pays_champ_descriptor_type.rb @@ -0,0 +1,11 @@ +module Types::Champs::Descriptor + class PaysChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + + field :options, [Types::Champs::PaysChampType::PaysType], "List des pays.", null: true + + def options + APIGeoService.countries + end + end +end diff --git a/app/graphql/types/champs/descriptor/phone_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/phone_champ_descriptor_type.rb new file mode 100644 index 000000000..dc126f7d7 --- /dev/null +++ b/app/graphql/types/champs/descriptor/phone_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class PhoneChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/piece_justificative_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/piece_justificative_champ_descriptor_type.rb new file mode 100644 index 000000000..f4d1bb4af --- /dev/null +++ b/app/graphql/types/champs/descriptor/piece_justificative_champ_descriptor_type.rb @@ -0,0 +1,9 @@ +module Types::Champs::Descriptor + class PieceJustificativeChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + + field :file_template, Types::File, "Modèle de la pièce justificative.", null: true, extensions: [ + { Extensions::Attachment => { attachment: :piece_justificative_template, root: :type_de_champ } } + ] + end +end diff --git a/app/graphql/types/champs/descriptor/pole_emploi_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/pole_emploi_champ_descriptor_type.rb new file mode 100644 index 000000000..1d22146c8 --- /dev/null +++ b/app/graphql/types/champs/descriptor/pole_emploi_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class PoleEmploiChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/region_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/region_champ_descriptor_type.rb new file mode 100644 index 000000000..0adf119ac --- /dev/null +++ b/app/graphql/types/champs/descriptor/region_champ_descriptor_type.rb @@ -0,0 +1,11 @@ +module Types::Champs::Descriptor + class RegionChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + + field :options, [Types::Champs::RegionChampType::RegionType], "List des regions.", null: true + + def options + APIGeoService.regions + end + end +end diff --git a/app/graphql/types/champs/descriptor/repetition_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/repetition_champ_descriptor_type.rb new file mode 100644 index 000000000..17862e2de --- /dev/null +++ b/app/graphql/types/champs/descriptor/repetition_champ_descriptor_type.rb @@ -0,0 +1,11 @@ +module Types::Champs::Descriptor + class RepetitionChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + + field :champ_descriptors, [Types::ChampDescriptorType], "Description des champs d’un bloc répétable.", null: true + + def champ_descriptors + Loaders::Association.for(object.class, revision_types_de_champ: :type_de_champ).load(object) + end + end +end diff --git a/app/graphql/types/champs/descriptor/rna_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/rna_champ_descriptor_type.rb new file mode 100644 index 000000000..0a227bd6f --- /dev/null +++ b/app/graphql/types/champs/descriptor/rna_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class RNAChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/siret_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/siret_champ_descriptor_type.rb new file mode 100644 index 000000000..c64ea8832 --- /dev/null +++ b/app/graphql/types/champs/descriptor/siret_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class SiretChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/text_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/text_champ_descriptor_type.rb new file mode 100644 index 000000000..140d7e736 --- /dev/null +++ b/app/graphql/types/champs/descriptor/text_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class TextChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/textarea_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/textarea_champ_descriptor_type.rb new file mode 100644 index 000000000..61dcbeaa3 --- /dev/null +++ b/app/graphql/types/champs/descriptor/textarea_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class TextareaChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/titre_identite_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/titre_identite_champ_descriptor_type.rb new file mode 100644 index 000000000..fbb3d3184 --- /dev/null +++ b/app/graphql/types/champs/descriptor/titre_identite_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class TitreIdentiteChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/champs/descriptor/yes_no_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/yes_no_champ_descriptor_type.rb new file mode 100644 index 000000000..779e9309b --- /dev/null +++ b/app/graphql/types/champs/descriptor/yes_no_champ_descriptor_type.rb @@ -0,0 +1,5 @@ +module Types::Champs::Descriptor + class YesNoChampDescriptorType < Types::BaseObject + implements Types::ChampDescriptorType + end +end diff --git a/app/graphql/types/demarche_descriptor_type.rb b/app/graphql/types/demarche_descriptor_type.rb index 4d89076d0..847ce7e6a 100644 --- a/app/graphql/types/demarche_descriptor_type.rb +++ b/app/graphql/types/demarche_descriptor_type.rb @@ -25,11 +25,24 @@ Cela évite l’accès récursif aux dossiers." field :date_depublication, GraphQL::Types::ISO8601DateTime, "Date de la dépublication.", null: true field :date_fermeture, GraphQL::Types::ISO8601DateTime, "Date de la fermeture.", null: true + field :duree_conservation_dossiers, Int, "Durée de conservation des dossiers en mois.", null: false + + field :demarche_url, String, null: true + field :site_web_url, String, null: true + field :dpo_url, String, null: true + field :notice_url, String, null: true + field :cadre_juridique_url, String, null: true + + field :opendata, Boolean, null: false + field :tags, [String], null: false + field :zones, [String], null: false + field :revision, Types::RevisionType, null: false field :service, Types::ServiceType, null: true - field :cadre_juridique, String, null: true - field :deliberation, String, null: true + field :logo, Types::File, null: true, extensions: [{ Extensions::Attachment => { root: :procedure } }] + field :notice, Types::File, null: true, extensions: [{ Extensions::Attachment => { root: :procedure } }] + field :deliberation, Types::File, null: true, extensions: [{ Extensions::Attachment => { root: :procedure } }] field :dossiers_count, Int, null: false, internal: true @@ -38,25 +51,51 @@ Cela évite l’accès récursif aux dossiers." end def revision - object.is_a?(ProcedureRevision) ? object : object.active_revision + if object.is_a?(ProcedureRevision) + object + else + object.active_revision + end + end + + def procedure + if object.is_a?(ProcedureRevision) + object.procedure + else + object + end end def dossiers_count - object.dossiers.count - end - - def deliberation - Rails.application.routes.url_helpers.url_for(procedure.deliberation) if procedure.deliberation.attached? + procedure.dossiers.visible_by_administration.count end def state procedure.aasm.current_state end - def cadre_juridique + delegate :description, :opendata, :tags, to: :procedure + + def demarche_url + procedure.lien_demarche + end + + def dpo_url + procedure.lien_dpo + end + + def notice_url + procedure.lien_notice + end + + def cadre_juridique_url procedure.cadre_juridique end + def site_web_url + procedure.lien_site_web + end + def number procedure.id end @@ -65,10 +104,6 @@ Cela évite l’accès récursif aux dossiers." procedure.libelle end - def description - procedure.description - end - def declarative procedure.declarative_with_state end @@ -93,15 +128,17 @@ Cela évite l’accès récursif aux dossiers." procedure.closed_at end - def self.authorized?(object, context) - procedure = object.is_a?(ProcedureRevision) ? object.procedure : object - procedure.opendata? || context.authorized_demarche?(procedure) + def duree_conservation_dossiers + procedure.duree_conservation_dossiers_dans_ds end - private + def zones + procedure.zones.map(&:current_label) + end - def procedure - revision.procedure + def self.authorized?(object, context) + procedure = object.is_a?(ProcedureRevision) ? object.procedure : object + context.authorized_demarche?(procedure, opendata: true) end end end diff --git a/app/graphql/types/revision_type.rb b/app/graphql/types/revision_type.rb index 01189351c..8998c383b 100644 --- a/app/graphql/types/revision_type.rb +++ b/app/graphql/types/revision_type.rb @@ -12,7 +12,11 @@ module Types end def annotation_descriptors - Loaders::Association.for(object.class, revision_types_de_champ_private: :type_de_champ).load(object) + if context.authorized_demarche?(object.procedure, opendata: true) + Loaders::Association.for(object.class, revision_types_de_champ_private: :type_de_champ).load(object) + else + [] + end end end end diff --git a/app/services/serializer_service.rb b/app/services/serializer_service.rb index d7f35f5b5..0a49f4f05 100644 --- a/app/services/serializer_service.rb +++ b/app/services/serializer_service.rb @@ -303,16 +303,18 @@ class SerializerService } fragment ChampDescriptorFragment on ChampDescriptor { - type + __typename label description required - options - champDescriptors { - type - label - description - required + ... on DropDownListChampDescriptor { + options + otherOption + } + ... on MultipleDropDownListChampDescriptor { + options + } + ... on LinkedDropDownListChampDescriptor { options } } @@ -321,13 +323,28 @@ class SerializerService number title description + tags + zones datePublication service { nom organisme typeOrganisme } - cadreJuridique - deliberation + demarcheUrl + dpoUrl + noticeUrl + siteWebUrl + cadreJuridiqueUrl + logo { ...FileFragment } + notice { ...FileFragment } + deliberation { ...FileFragment } dossiersCount revision { - champDescriptors { ...ChampDescriptorFragment } + champDescriptors { + ...ChampDescriptorFragment + ... on RepetitionChampDescriptor { + champDescriptors { + ...ChampDescriptorFragment + } + } + } } } GRAPHQL diff --git a/spec/controllers/api/v2/graphql_controller_spec.rb b/spec/controllers/api/v2/graphql_controller_spec.rb index ef4a9602a..f51609339 100644 --- a/spec/controllers/api/v2/graphql_controller_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_spec.rb @@ -67,7 +67,7 @@ describe API::V2::GraphqlController do publishedRevision { id champDescriptors { - type + __typename } } service { @@ -76,16 +76,26 @@ describe API::V2::GraphqlController do organisme } champDescriptors { + __typename id - type label description required - champDescriptors { - id - type + ... on RepetitionChampDescriptor { + champDescriptors { + __typename + id + } + } + ... on DropDownListChampDescriptor { + options + } + ... on MultipleDropDownListChampDescriptor { + options + } + ... on LinkedDropDownListChampDescriptor { + options } - options } dossiers { nodes { @@ -157,9 +167,13 @@ describe API::V2::GraphqlController do describe "query a demarche" do let(:procedure) { create(:procedure, :published, :for_individual, :with_service, :with_all_champs, :with_all_annotations, administrateurs: [admin]) } + def format_type_champ(type_champ) + "#{type_champ.gsub('regions', 'region').gsub('departements', 'departement').gsub('communes', 'commune').camelcase}ChampDescriptor" + end + it "returns the demarche" do expect(gql_errors).to eq(nil) - expect(gql_data).to eq(demarche: { + expect(gql_data).to include(demarche: { id: procedure.to_typed_id, number: procedure.id, title: procedure.libelle, @@ -174,15 +188,11 @@ describe API::V2::GraphqlController do label: "défaut" } ], - revisions: procedure.revisions.map { |revision| { id: revision.to_typed_id } }, + revisions: procedure.revisions.map { { id: _1.to_typed_id } }, draftRevision: { id: procedure.draft_revision.to_typed_id }, publishedRevision: { id: procedure.published_revision.to_typed_id, - champDescriptors: procedure.published_revision.types_de_champ_public.map do |tdc| - { - type: tdc.type_champ - } - end + champDescriptors: procedure.published_revision.types_de_champ_public.map { { __typename: format_type_champ(_1.type_champ) } } }, service: { nom: procedure.service.nom, @@ -193,15 +203,15 @@ describe API::V2::GraphqlController do { id: tdc.to_typed_id, label: tdc.libelle, - type: tdc.type_champ, + __typename: format_type_champ(tdc.type_champ), description: tdc.description, required: tdc.mandatory?, - champDescriptors: tdc.repetition? ? procedure.active_revision.children_of(tdc.reload).map { |tdc| { id: tdc.to_typed_id, type: tdc.type_champ } } : nil, + champDescriptors: tdc.repetition? ? procedure.active_revision.children_of(tdc.reload).map { { id: _1.to_typed_id, __typename: format_type_champ(_1.type_champ) } } : nil, options: tdc.drop_down_list? ? tdc.drop_down_list_options.reject(&:empty?) : nil - } + }.compact end, dossiers: { - nodes: dossiers.map { |dossier| { id: dossier.to_typed_id } } + nodes: dossiers.map { { id: _1.to_typed_id } } } }) end diff --git a/spec/controllers/api/v2/graphql_controller_stored_queries_spec.rb b/spec/controllers/api/v2/graphql_controller_stored_queries_spec.rb index 9dfcf0330..37bba16e0 100644 --- a/spec/controllers/api/v2/graphql_controller_stored_queries_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_stored_queries_spec.rb @@ -79,6 +79,16 @@ describe API::V2::GraphqlController do expect(gql_data[:demarche][:dossiers][:nodes].size).to eq(1) } end + + context 'include Revision' do + let(:variables) { { demarcheNumber: procedure.id, includeRevision: true } } + + it { + expect(gql_errors).to be_nil + expect(gql_data[:demarche][:id]).to eq(procedure.to_typed_id) + expect(gql_data[:demarche][:activeRevision]).not_to be_nil + } + end end context 'getGroupeInstructeur' do diff --git a/spec/factories/zone.rb b/spec/factories/zone.rb index f8a82ea3f..09e805a47 100644 --- a/spec/factories/zone.rb +++ b/spec/factories/zone.rb @@ -5,9 +5,9 @@ FactoryBot.define do labels { [{ designated_on: '1981-05-08', name: "Ministère de l'Education Populaire" }] } end - after(:create) do |zone, evaluator| + after(:build) do |zone, evaluator| evaluator.labels.each do |label| - zone.labels.create(designated_on: label[:designated_on], name: label[:name]) + zone.labels.build(designated_on: label[:designated_on], name: label[:name]) end end end diff --git a/spec/services/demarches_publiques_export_service_spec.rb b/spec/services/demarches_publiques_export_service_spec.rb index 3ad918ba3..05e96a208 100644 --- a/spec/services/demarches_publiques_export_service_spec.rb +++ b/spec/services/demarches_publiques_export_service_spec.rb @@ -1,6 +1,6 @@ describe DemarchesPubliquesExportService do let(:procedure) { create(:procedure, :published, :with_service, :with_type_de_champ) } - let!(:dossier) { create(:dossier, procedure: procedure) } + let!(:dossier) { create(:dossier, :en_construction, procedure: procedure) } let(:gzip_filename) { "demarches.json.gz" } after { FileUtils.rm(gzip_filename) } @@ -16,19 +16,25 @@ describe DemarchesPubliquesExportService do organisme: "organisme", typeOrganisme: "association" }, - cadreJuridique: "un cadre juridique important", + cadreJuridiqueUrl: "un cadre juridique important", + demarcheUrl: nil, + dpoUrl: nil, + noticeUrl: nil, + siteWebUrl: "https://mon-site.gouv", + logo: nil, + notice: nil, deliberation: nil, datePublication: procedure.published_at.iso8601, + zones: ["Ministère de l'Education Populaire"], + tags: [], dossiersCount: 1, revision: { champDescriptors: [ { description: procedure.active_revision.types_de_champ_public.first.description, label: procedure.active_revision.types_de_champ_public.first.libelle, - options: nil, required: false, - type: "text", - champDescriptors: nil + __typename: "TextChampDescriptor" } ] }