diff --git a/server/src/nest/mail-ingest/mail-ingest-apply.service.ts b/server/src/nest/mail-ingest/mail-ingest-apply.service.ts index 700cfc2f5..c4d6c77fa 100644 --- a/server/src/nest/mail-ingest/mail-ingest-apply.service.ts +++ b/server/src/nest/mail-ingest/mail-ingest-apply.service.ts @@ -164,8 +164,8 @@ export class MailIngestApplyService { } /** - * The mail's documents as trip files on the booking (or on the trip, for a - * mail filed without one), when the documents addon is on: each attachment + * The mail's documents as trip files on the booking, or on the trip for a + * mail filed without one when the documents addon is on: each attachment * of a type the trip takes, or the mail's text when none is. A failure * leaves the booking standing and is reported, never thrown. * @@ -178,7 +178,8 @@ export class MailIngestApplyService { mail: WalkedMail, userId: number, ): Promise<{ fileIds: number[]; error: string | null }> { - if (!(await this.addons.isEnabledForTrip(tripId, ADDON_IDS.DOCUMENTS))) return { fileIds: [], error: null }; + if (reservationId === null && !(await this.addons.isEnabledForTrip(tripId, ADDON_IDS.DOCUMENTS))) + return { fileIds: [], error: null }; const allowed = await this.settings.allowedFileTypes(); const kept = mail.attachments.filter((file) => isUploadTypeAllowed(file.fileName, file.mimeType, allowed)); const uploads = kept.length diff --git a/server/tests/unit/nest/mail-ingest/mail-ingest.pipeline.test.ts b/server/tests/unit/nest/mail-ingest/mail-ingest.pipeline.test.ts index 7d1dcbecf..a74b1ec5b 100644 --- a/server/tests/unit/nest/mail-ingest/mail-ingest.pipeline.test.ts +++ b/server/tests/unit/nest/mail-ingest/mail-ingest.pipeline.test.ts @@ -226,6 +226,24 @@ describe('a booking that passes every check', () => { expect(t.realtime.broadcastMock).toHaveBeenCalledWith(trip.id, 'reservation:created', expect.anything()); }); + it('keeps the documents on its booking while the trip has Documents off', async () => { + const user = await person(); + const trip = await makeTrip(orm(), user.id, { title: 'Japan', start_date: '2030-03-01', end_date: '2030-03-10' }); + await setAddonEnabled(orm(), 'documents', false); + try { + await forward(user.id, eml('flight')); + const booking = await findRow(orm(), Reservations, { trip: trip.id }); + expect(files.createFileFromBytes).toHaveBeenCalledWith( + trip.id, + expect.objectContaining({ originalname: 'mail.txt' }), + user.id, + expect.objectContaining({ reservation_id: booking?.id }), + ); + } finally { + await setAddonEnabled(orm(), 'documents', true); + } + }); + it('is undone by its forwarder: the booking and its cost go, the same mail again waits in the inbox', async () => { const user = await person(); const trip = await makeTrip(orm(), user.id, { start_date: '2030-03-01', end_date: '2030-03-10' });