From 0f937186ae609abde134a5e83a11864f78087f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Luaces?= Date: Mon, 9 Nov 2026 14:58:05 +0100 Subject: [PATCH] fix(calendar): check all changes before sending any When one save changes several occurrences, each change is sent to the attendees in turn. If a later change was refused, for example because a resource was already booked, the earlier changes had already reached the attendees while the organizer's calendar was left unchanged. Run the booking and availability checks for all changes first, and send nothing if one of them fails. A save with a single change skips this step, because the normal check already covers it. --- .../Appointments/SOGoAppointmentObject.m | 14 ++++++++ Tests/spec/CalDAVSchedulingSpec.js | 36 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/SoObjects/Appointments/SOGoAppointmentObject.m b/SoObjects/Appointments/SOGoAppointmentObject.m index 8fbe90b5b..a8fb8b8f0 100644 --- a/SoObjects/Appointments/SOGoAppointmentObject.m +++ b/SoObjects/Appointments/SOGoAppointmentObject.m @@ -2247,6 +2247,20 @@ inRecurrenceExceptionsForEvent: (iCalEvent *) theEvent } } + // Attendees are written to as each component is scheduled. Refuse the + // request before any of that happens if one component would be refused. + if ([removedEvents count] + [updatedEvents count] > 1) + { + for (i = 0; i < [updatedEvents count]; i++) + { + newEvent = [updatedEvents objectAtIndex: i]; + if ((ex = [self _handleAttendeesConflicts: [newEvent attendees] forEvent: newEvent force: YES])) + return ex; + if ((ex = [self _handleAttendeesAvailability: [newEvent attendees] forEvent: newEvent])) + return ex; + } + } + for (i = 0; i < [removedEvents count]; i++) [self prepareDeleteOccurence: [removedEvents objectAtIndex: i]]; diff --git a/Tests/spec/CalDAVSchedulingSpec.js b/Tests/spec/CalDAVSchedulingSpec.js index 216ffd3d1..2e75aca0a 100644 --- a/Tests/spec/CalDAVSchedulingSpec.js +++ b/Tests/spec/CalDAVSchedulingSpec.js @@ -669,6 +669,42 @@ describe('CalDAV Scheduling', function() { .toBe('20261015T110000Z') }) + it('refuses the whole PUT when one changed occurrence is refused', async function() { + const uid = 'rrule-several-occurrences-refused' + const icsName = `${uid}.ics` + const blockerIcsName = `${uid}-blocker.ics` + icsList.push(icsName, blockerIcsName) + + await _deleteAllEvents(webdav_su, resourceNoOverbookCalendar) + + // 1. Book the resource where the occurrence of the 8th will be moved + await _putEvent(webdav, userCalendar, blockerIcsName, _calendar([ + 'BEGIN:VEVENT', + `UID:${uid}-blocker`, + 'DTSTAMP:20260901T100000Z', + 'DTSTART:20261008T110000Z', + 'DTEND:20261008T120000Z', + 'SUMMARY:Blocker', + `ORGANIZER:${user.email}`, + `ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION:${resourceNoOverbook.email}`, + 'END:VEVENT' + ])) + + await _putEvent(webdav, userCalendar, icsName, _calendar( + _master(uid, 'Weekly sync'), _exception(uid, '22', 'NEEDS-ACTION'))) + + // 2. Move the 15th, and the 8th with the booked resource + const refused = _exception(uid, '08', 'NEEDS-ACTION') + refused.splice(-1, 0, `ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION:${resourceNoOverbook.email}`) + await _putEvent(webdav, userCalendar, icsName, _calendar( + _master(uid, 'Weekly sync'), _exception(uid, '15', 'NEEDS-ACTION'), refused, + _exception(uid, '22', 'NEEDS-ACTION')), 409) + + expect(await _attendeeStartOf(icsName, '15')) + .withContext('Occurrence of the 15th not moved in the calendar of the attendee') + .toBeUndefined() + }) + it('schedules the master event along with a changed occurrence', async function() { const uid = 'rrule-master-and-occurrence' const icsName = `${uid}.ics`