Merge pull request #9081 from tchak/graphql-user-connection-type

ETQ Intégrateur d’API, je voudrais savoir si l’utilisateur est connecté avec FranceConnect
This commit is contained in:
Paul Chavard 2023-05-24 08:03:09 +00:00 committed by GitHub
commit 40b3742d69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 1 deletions

View file

@ -263,6 +263,7 @@ class API::V2::StoredQuery
usager { usager {
email email
} }
connectionUsager
groupeInstructeur { groupeInstructeur {
...GroupeInstructeurFragment ...GroupeInstructeurFragment
} }

View file

@ -462,6 +462,23 @@ type CommuneChampDescriptor implements ChampDescriptor {
type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") 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 GeoJSON coordinates
""" """
@ -1199,6 +1216,7 @@ type Dossier {
attestation: File attestation: File
avis(id: ID): [Avis!]! avis(id: ID): [Avis!]!
champs(id: ID): [Champ!]! champs(id: ID): [Champ!]!
connectionUsager: ConnectionUsager!
""" """
Date de dépôt. Date de dépôt.

View file

@ -6,6 +6,12 @@ module Types
end end
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" description "Un dossier"
global_id_field :id global_id_field :id
@ -26,6 +32,8 @@ module Types
field :archived, Boolean, null: false field :archived, Boolean, null: false
field :connection_usager, ConnectionUsager, null: false
field :motivation, String, null: true field :motivation, String, null: true
field :motivation_attachment, Types::File, null: true, extensions: [ field :motivation_attachment, Types::File, null: true, extensions: [
{ Extensions::Attachment => { attachment: :justificatif_motivation } } { Extensions::Attachment => { attachment: :justificatif_motivation } }
@ -67,11 +75,25 @@ module Types
end end
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 def usager
if object.user_deleted? if object.user_deleted?
{ email: object.user_email_for(:display), id: '<deleted>' } { email: object.user_email_for(:display), id: '<deleted>' }
else else
Loaders::Record.for(User).load(object.user_id) user_loader
end end
end end
@ -173,5 +195,11 @@ module Types
def self.authorized?(object, context) def self.authorized?(object, context)
context.authorized_demarche?(object.revision.procedure) context.authorized_demarche?(object.revision.procedure)
end end
private
def user_loader
Loaders::Record.for(User, includes: :france_connect_information).load(object.user_id)
end
end end
end end

View file

@ -83,6 +83,7 @@ describe API::V2::GraphqlController do
it { it {
expect(gql_errors).to be_nil expect(gql_errors).to be_nil
expect(gql_data[:dossier][:id]).to eq(dossier.to_typed_id) 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][:__typename]).to eq('PersonnePhysique')
expect(gql_data[:dossier][:demandeur][:nom]).to eq(dossier.individual.nom) expect(gql_data[:dossier][:demandeur][:nom]).to eq(dossier.individual.nom)
expect(gql_data[:dossier][:demandeur][:prenom]).to eq(dossier.individual.prenom) expect(gql_data[:dossier][:demandeur][:prenom]).to eq(dossier.individual.prenom)