diff --git a/app/graphql/api/v2/stored_query.rb b/app/graphql/api/v2/stored_query.rb index ff22fa75b..2ad9d408b 100644 --- a/app/graphql/api/v2/stored_query.rb +++ b/app/graphql/api/v2/stored_query.rb @@ -263,6 +263,7 @@ class API::V2::StoredQuery usager { email } + connectionUsager groupeInstructeur { ...GroupeInstructeurFragment } diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index ad44d1648..7ecc93333 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -462,6 +462,23 @@ type CommuneChampDescriptor implements ChampDescriptor { type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") } +enum ConnectionUsager { + """ + Compte supprimé + """ + deleted + + """ + Connexion via FranceConnect + """ + france_connect + + """ + Connexion via mot de passe + """ + password +} + """ GeoJSON coordinates """ @@ -1199,6 +1216,7 @@ type Dossier { attestation: File avis(id: ID): [Avis!]! champs(id: ID): [Champ!]! + connectionUsager: ConnectionUsager! """ Date de dépôt. diff --git a/app/graphql/types/dossier_type.rb b/app/graphql/types/dossier_type.rb index 0dc34f2c1..2a5f70381 100644 --- a/app/graphql/types/dossier_type.rb +++ b/app/graphql/types/dossier_type.rb @@ -6,6 +6,12 @@ module Types end end + class ConnectionUsager < Types::BaseEnum + value(:france_connect, "Connexion via FranceConnect", value: :france_connect) + value(:password, "Connexion via mot de passe", value: :password) + value(:deleted, "Compte supprimé", value: :deleted) + end + description "Un dossier" global_id_field :id @@ -26,6 +32,8 @@ module Types field :archived, Boolean, null: false + field :connection_usager, ConnectionUsager, null: false + field :motivation, String, null: true field :motivation_attachment, Types::File, null: true, extensions: [ { Extensions::Attachment => { attachment: :justificatif_motivation } } @@ -67,11 +75,25 @@ module Types end end + def connection_usager + if object.user_deleted? + :deleted + else + user_loader.then do |user| + if user.france_connect_information.present? + :france_connect + else + :password + end + end + end + end + def usager if object.user_deleted? { email: object.user_email_for(:display), id: '' } else - Loaders::Record.for(User).load(object.user_id) + user_loader end end @@ -173,5 +195,11 @@ module Types def self.authorized?(object, context) context.authorized_demarche?(object.revision.procedure) end + + private + + def user_loader + Loaders::Record.for(User, includes: :france_connect_information).load(object.user_id) + end end 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 09555bf12..fb1a40b7d 100644 --- a/spec/controllers/api/v2/graphql_controller_stored_queries_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_stored_queries_spec.rb @@ -83,6 +83,7 @@ describe API::V2::GraphqlController do it { expect(gql_errors).to be_nil expect(gql_data[:dossier][:id]).to eq(dossier.to_typed_id) + expect(gql_data[:dossier][:connectionUsager]).to eq('password') expect(gql_data[:dossier][:demandeur][:__typename]).to eq('PersonnePhysique') expect(gql_data[:dossier][:demandeur][:nom]).to eq(dossier.individual.nom) expect(gql_data[:dossier][:demandeur][:prenom]).to eq(dossier.individual.prenom)