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:
commit
40b3742d69
4 changed files with 49 additions and 1 deletions
|
@ -263,6 +263,7 @@ class API::V2::StoredQuery
|
|||
usager {
|
||||
email
|
||||
}
|
||||
connectionUsager
|
||||
groupeInstructeur {
|
||||
...GroupeInstructeurFragment
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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: '<deleted>' }
|
||||
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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue