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 }) =>{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 }) =>