From 8d36a08b11d594dc37ac96371e916af8a6b7f3e9 Mon Sep 17 00:00:00 2001 From: Mistral Vibe Date: Tue, 13 Oct 2026 17:39:23 +0200 Subject: [PATCH] =?UTF-8?q?Immich=20:=20retirer=20l'identifiant=20Immich?= =?UTF-8?q?=20du=20graphe=20envoy=C3=A9=20aux=20visiteurs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - buildGraphPayload ne mappe plus immichPersonId ; test qu'il n'apparaît pas - le front ne propage plus le champ (graphAdapter, mockData et son test) - le panneau Immich propose le retrait d'association en permanence, sans lire le champ ; unassign sans association ne fait rien : pas d'écriture, pas d'entrée d'audit (test du no-op), et le bouton de la fiche garde un libellé fixe Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe --- backend/src/routes/immich.ts | 6 ++++++ backend/src/utils/graph-payload.ts | 2 -- backend/test/graph-payload.test.ts | 4 ++++ backend/test/immich.test.ts | 20 ++++++++++++++++++++ frontend/src/components/ImmichFacePanel.jsx | 16 +++++++++------- frontend/src/components/PersonCard.jsx | 2 +- frontend/src/data/mockData.js | 1 - frontend/src/data/mockData.test.js | 5 ----- frontend/src/i18n/en/fiche.js | 4 ++-- frontend/src/utils/graphAdapter.js | 1 - 10 files changed, 42 insertions(+), 19 deletions(-) diff --git a/backend/src/routes/immich.ts b/backend/src/routes/immich.ts index c0dc964..3ff6609 100644 --- a/backend/src/routes/immich.ts +++ b/backend/src/routes/immich.ts @@ -495,6 +495,12 @@ export const immichRoutes: FastifyPluginAsync = async (app) => { return reply.code(404).send({ error: 'person_not_found' }) } + // Le graphe ne dit plus qui est associé : le retrait se propose toujours côté front. Sans + // association en place, il ne fait rien — pas d'écriture, pas d'entrée d'audit. + if (!person.immichPersonId) { + return reply.send({ ok: true, avatarRemoved: false }) + } + // Le portrait vient d'Immich uniquement si son fichier porte notre préfixe. Un portrait // envoyé à la main reste en place : seule l'association est retirée. const avatarFromImmich = person.avatarPath !== null && path.basename(person.avatarPath).startsWith('immich-') diff --git a/backend/src/utils/graph-payload.ts b/backend/src/utils/graph-payload.ts index c66d297..ea847dc 100644 --- a/backend/src/utils/graph-payload.ts +++ b/backend/src/utils/graph-payload.ts @@ -17,7 +17,6 @@ export type GraphPayload = { avatarUrlPath: string | null sex: string | null notes: string | null - immichPersonId: string | null }> unions: Array<{ id: string @@ -91,7 +90,6 @@ export function buildGraphPayload( avatarUrlPath: person.avatarPath ? `/trees/${treeId}/persons/${person.id}/avatar` : null, sex: person.sex, notes: person.notes, - immichPersonId: person.immichPersonId, })), unions: unions.map((union) => ({ id: union.id, diff --git a/backend/test/graph-payload.test.ts b/backend/test/graph-payload.test.ts index 2211b80..8b1e272 100644 --- a/backend/test/graph-payload.test.ts +++ b/backend/test/graph-payload.test.ts @@ -18,6 +18,7 @@ describe('buildGraphPayload', () => { sex: null, notes: null, avatarPath: 't-1/p-2/avatar.jpg', + immichPersonId: '123e4567-e89b-42d3-a456-426614174000', createdBy: null, updatedBy: null, createdAt: new Date(), @@ -97,6 +98,9 @@ describe('buildGraphPayload', () => { expect(graph.persons[0].birthDate).toBe('1994-06-02') expect(graph.persons[0].birthName).toBe('Durand') expect(graph.persons[0].avatarUrlPath).toBe('/trees/t-1/persons/p-2/avatar') + // L'identifiant Immich ne part jamais dans le graphe : il ne sert qu'aux administrateurs. + expect(graph.persons[0]).not.toHaveProperty('immichPersonId') + expect(graph.persons[1]).not.toHaveProperty('immichPersonId') expect(graph.persons[1].avatarUrlPath).toBeNull() expect(graph.unions[0].id).toBe('u-1') expect(graph.filiations[0].viaUnionId).toBe('u-1') diff --git a/backend/test/immich.test.ts b/backend/test/immich.test.ts index 3ab3062..2cd94b4 100644 --- a/backend/test/immich.test.ts +++ b/backend/test/immich.test.ts @@ -737,6 +737,26 @@ describe('Immich integration: unassign', () => { await app.close() }) + it('does nothing when no association is in place', async () => { + const app = createApp() + const token = await createUserToken(app) + + prismaMock.person.findFirst.mockResolvedValue({ id: 'person-1', avatarPath: null, immichPersonId: null }) + + const response = await app.inject({ + method: 'POST', + url: '/trees/tree-1/immich/unassign', + headers: { authorization: `Bearer ${token}` }, + payload: { personId: 'person-1' }, + }) + + expect(response.statusCode).toBe(200) + expect(response.json()).toEqual({ ok: true, avatarRemoved: false }) + expect(prismaMock.person.update).not.toHaveBeenCalled() + expect(prismaMock.auditLog.create).not.toHaveBeenCalled() + await app.close() + }) + it('rejects unknown persons and non-admin members', async () => { const app = createApp() const token = await createUserToken(app) diff --git a/frontend/src/components/ImmichFacePanel.jsx b/frontend/src/components/ImmichFacePanel.jsx index 48b413f..b0e9e99 100644 --- a/frontend/src/components/ImmichFacePanel.jsx +++ b/frontend/src/components/ImmichFacePanel.jsx @@ -113,7 +113,7 @@ const ImmichFacePanel = ({ person, treeId, token, onClose, onImmichChange }) => }, [selected, actionLoading, treeId, person, token, onImmichChange, onClose]) const handleUnassign = useCallback(async () => { - if (!person.immichPersonId || actionLoading) return + if (actionLoading) return setActionLoading(true) setError('') try { @@ -137,11 +137,13 @@ const ImmichFacePanel = ({ person, treeId, token, onClose, onImmichChange }) => } } - // L'association en place se retire aussi bien sans connexion : changer ou retirer le serveur - // Immich ne laisse jamais une ancienne image impossible à nettoyer manuellement. - const currentAssociation = person.immichPersonId && ( + // Le retrait se propose toujours : le graphe ne dit plus qui est associé. Une association en + // place se retire aussi bien sans connexion : changer ou retirer le serveur Immich ne laisse + // jamais une ancienne image impossible à nettoyer manuellement. Sans association, le retrait + // ne fait rien côté serveur. + const unassignBlock = (
-

{t('{name} est déjà associée à une personne Immich.', { name: person.firstName || person.lastName })}

+

{t('{name} peut être détachée d’une personne Immich, même si Immich est injoignable.', { name: person.firstName || person.lastName })}

@@ -163,7 +165,7 @@ const ImmichFacePanel = ({ person, treeId, token, onClose, onImmichChange }) =>
) : available === false ? (
- {currentAssociation} + {unassignBlock}

{unavailableReason === 'not_configured' ? t('Immich n’est pas configuré pour cet arbre. Ses administrateurs le règlent dans Paramètres de l’arbre.') @@ -173,7 +175,7 @@ const ImmichFacePanel = ({ person, treeId, token, onClose, onImmichChange }) =>

) : (
- {currentAssociation} + {unassignBlock}
{t('Personne à associer dans Immich')} diff --git a/frontend/src/components/PersonCard.jsx b/frontend/src/components/PersonCard.jsx index a022e0d..fed617a 100644 --- a/frontend/src/components/PersonCard.jsx +++ b/frontend/src/components/PersonCard.jsx @@ -378,7 +378,7 @@ const PersonCard = ({ )} {treeId && onImmichChange && ( )}
diff --git a/frontend/src/data/mockData.js b/frontend/src/data/mockData.js index 0d0ea97..7a1084d 100644 --- a/frontend/src/data/mockData.js +++ b/frontend/src/data/mockData.js @@ -115,7 +115,6 @@ function mapRemotePersonToLocal(person, current = null) { profession: person?.profession || null, nationality: person?.nationality || null, photo: current?.photo || null, - immichPersonId: person?.immichPersonId ?? null, } } diff --git a/frontend/src/data/mockData.test.js b/frontend/src/data/mockData.test.js index 80a5104..91ee070 100644 --- a/frontend/src/data/mockData.test.js +++ b/frontend/src/data/mockData.test.js @@ -15,7 +15,6 @@ describe('loadGraphData avatar mapping', () => { deathDate: null, notes: null, avatarUrlPath: '/trees/t-1/persons/p-1/avatar', - immichPersonId: '123e4567-e89b-42d3-a456-426614174000', }, { id: 'p-2', @@ -25,7 +24,6 @@ describe('loadGraphData avatar mapping', () => { deathDate: null, notes: null, avatarUrlPath: null, - immichPersonId: null, }, ], unions: [], @@ -50,9 +48,6 @@ describe('loadGraphData avatar mapping', () => { expect(getPersonById('p-1')?.photo).toBe('/api/trees/t-1/persons/p-1/avatar?token=abc') expect(getPersonById('p-2')?.photo).toBeNull() expect(getPersonMedias('p-2')[0]?.source).toBe('Album familial') - // Association Immich portée par la personne (null quand il n'y en a pas) - expect(getPersonById('p-1')?.immichPersonId).toBe('123e4567-e89b-42d3-a456-426614174000') - expect(getPersonById('p-2')?.immichPersonId).toBeNull() }) }) diff --git a/frontend/src/i18n/en/fiche.js b/frontend/src/i18n/en/fiche.js index 8236c81..f54142c 100644 --- a/frontend/src/i18n/en/fiche.js +++ b/frontend/src/i18n/en/fiche.js @@ -261,7 +261,6 @@ export default { 'Inconnu': 'Unknown', // Visages venus d'Immich (PersonCard, ImmichFacePanel, immichApi) 'Depuis Immich': 'From Immich', - 'Visage Immich': 'Immich face', 'Reconnaissance des visages': 'Face recognition', 'Immich n’est pas configuré pour cet arbre.': 'Immich is not configured for this tree.', 'Immich n’est pas configuré pour cet arbre. Ses administrateurs le règlent dans Paramètres de l’arbre.': 'Immich is not configured for this tree. Its administrators set it up in Tree settings.', @@ -275,7 +274,8 @@ export default { 'Cette adresse Immich n’est pas autorisée par l’opérateur du serveur.': 'This Immich address is not authorized by the server operator.', 'Seuls les administrateurs de l’arbre peuvent associer un visage Immich.': 'Only tree administrators can link an Immich face.', 'Erreur inattendue.': 'Unexpected error.', - '{name} est déjà associée à une personne Immich.': '{name} is already linked to an Immich person.', + '{name} peut être détachée d’une personne Immich, même si Immich est injoignable.': + '{name} can be detached from an Immich person, even when Immich cannot be reached.', 'Retirer l’association': 'Remove the link', 'Personne à associer dans Immich': 'Immich person to link', 'Rechercher par nom': 'Search by name', diff --git a/frontend/src/utils/graphAdapter.js b/frontend/src/utils/graphAdapter.js index f0f716f..7fb09ca 100644 --- a/frontend/src/utils/graphAdapter.js +++ b/frontend/src/utils/graphAdapter.js @@ -57,7 +57,6 @@ export function adaptGraphForGalaxy(apiGraph, _treeId) { birthDate: p.birthDate, deathDate: p.deathDate, photo: p.avatarUrlPath ? `/api${p.avatarUrlPath}` : null, - immichPersonId: p.immichPersonId || null, frameType: 'round', // Default }))