From 9a5861c903b123e1b7959051eb5d21fc61ad9ca0 Mon Sep 17 00:00:00 2001 From: mindsers Date: Thu, 19 Nov 2026 10:21:32 +0100 Subject: [PATCH] fix(events): keep absences out of the programme list's bulk actions Publishing, unpublishing and deleting programmes in bulk took any event id the request posted, so a programme manager could, with a hand-written request, unpublish or delete someone's absence. The list never offers one; the actions now refuse them too, as the single event pages already do. --- .../events-auth.server.integration.test.ts | 32 +++++++++++++++++++ .../events/server/events-auth.server.ts | 7 ++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/app/features/events/server/events-auth.server.integration.test.ts b/app/features/events/server/events-auth.server.integration.test.ts index c5cd5781..cffc6ffb 100644 --- a/app/features/events/server/events-auth.server.integration.test.ts +++ b/app/features/events/server/events-auth.server.integration.test.ts @@ -46,6 +46,7 @@ const allowOnly = (allowed: Permission) => (p: Permission) => p === allowed const { assignmentBelongsToEvent, canEditEvent, + filterToManageableEventIds, getResponsibleTemplateIds, canManageAnyProgram, listApplicableTemplates, @@ -684,3 +685,34 @@ describe('mayReadSlotFacts (integration)', () => { expect(result).toBe(true) }) }) + +// The programme list's bulk actions — publish, unpublish, delete — take the ids the request posts. The list never offers +// an absence, so none may go through, however the request is written: a manager would otherwise delete or unpublish +// someone's absence. +describe('filterToManageableEventIds and absences (integration)', () => { + it('never lets an absence through, even for a programme manager', async () => { + const absenceId = await withScope(primaryCongId, async tx => { + const dayOff = await tx.eventTemplate.findFirstOrThrow({ where: { key: 'day-off' } }) + const day = new Date('2027-01-12T00:00:00Z') + return ( + await tx.event.create({ + data: { + name: 'Absence', + startDate: day, + endDate: day, + status: 'released', + templateId: dayOff.id, + createdById: plainId, + congregationId: primaryCongId, + }, + }) + ).id + }) + + const allowed = await withScope(primaryCongId, tx => + filterToManageableEventIds(tx, allowAll, [absenceId, ownedEventId], managerId, primaryCongId), + ) + + expect(allowed).toEqual([ownedEventId]) + }) +}) diff --git a/app/features/events/server/events-auth.server.ts b/app/features/events/server/events-auth.server.ts index 2309faeb..5feefeca 100644 --- a/app/features/events/server/events-auth.server.ts +++ b/app/features/events/server/events-auth.server.ts @@ -1,6 +1,7 @@ import { SYSTEM_TEMPLATE_KEYS } from '~/features/events/model/event-template.type' import { ResponsibilityScope, scopesCovering } from '~/features/events/model/responsibility-scope.type' import { isTemplateResponsible } from '~/features/events/server/event-templates.server' +import { PROGRAMME_EVENT } from '~/features/events/server/programme-event.queries' import { resolveEffectiveRoleIds } from '~/shared/auth/permissions.server' import type { TransactionClient } from '~/shared/infra/db.server' import { createLogger } from '~/shared/infra/logger.server' @@ -232,11 +233,13 @@ export async function filterToManageableEventIds( if (eventIds.length === 0) return [] const holdsRequiredCapability = can(required) + // Never an absence: the programme list does not offer one, and these actions would publish, unpublish or delete + // someone's absence. const events = await db.event.findMany({ - where: { id: { in: eventIds }, congregationId }, + where: { id: { in: eventIds }, congregationId, ...PROGRAMME_EVENT }, select: { id: true, templateId: true }, }) - // Cross-tenant / stale ids: submitted but not present in this congregation. + // Cross-tenant / stale ids, or absences: submitted but not a programme of this congregation. const droppedCrossTenant = eventIds.length - events.length if (holdsRequiredCapability) {