Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions app/features/events/server/events-auth.server.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const allowOnly = (allowed: Permission) => (p: Permission) => p === allowed
const {
assignmentBelongsToEvent,
canEditEvent,
filterToManageableEventIds,
getResponsibleTemplateIds,
canManageAnyProgram,
listApplicableTemplates,
Expand Down Expand Up @@ -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])
})
})
7 changes: 5 additions & 2 deletions app/features/events/server/events-auth.server.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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) {
Expand Down