mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-11-20 14:36:53 +00:00
fix(calendar): send every organizer change to the attendees
When an organizer saves a recurring event from a CalDAV client and the save changes several occurrences, SOGo sends only one of those changes to the attendees. The other changes are stored in the organizer's calendar, but the attendees never receive them and no error is reported. Which change is sent depends on the order of the occurrences in the request. Send every change instead: first the removed occurrences, then the added or changed occurrences, and last the main event if it changed. The main event goes last because attendees then receive the whole series, which must already include the updated occurrences. The checks on the organizer and on delegated senders are unchanged. Reported to Alinto support as ticket 6099.
This commit is contained in:
1 parent
1ed977528c
commit
5c6a8fc8ee
2 files changed
+251
-5
No files matched your search
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#import <Foundation/NSCalendarDate.h>
|
||||
#import <Foundation/NSNull.h>
|
||||
#import <Foundation/NSTimeZone.h>
|
||||
#import <Foundation/NSValue.h>
|
||||
|
||||
@@ -2163,6 +2164,109 @@ inRecurrenceExceptionsForEvent: (iCalEvent *) theEvent
|
||||
return nil;
|
||||
}
|
||||
|
||||
//
|
||||
// Schedule every component the organizer changed in a single PUT. Clients
|
||||
// send the whole series, so one request can remove some occurrences, move
|
||||
// others and edit the master event at the same time.
|
||||
//
|
||||
// The master event is handled last because, when it changed, attendees
|
||||
// usually receive the whole calendar, and that calendar must already carry
|
||||
// the updated occurrences. When only occurrences changed, the master event
|
||||
// is left alone to keep the participation status of its attendees.
|
||||
//
|
||||
- (NSException *) _handleUpdatedCalendar: (iCalCalendar *) newCalendar
|
||||
fromOldCalendar: (iCalCalendar *) oldCalendar
|
||||
{
|
||||
NSArray *newEvents, *oldEvents;
|
||||
NSMutableArray *removedEvents, *updatedEvents, *updatedOldEvents;
|
||||
iCalEvent *newEvent, *oldEvent, *newMaster, *oldMaster;
|
||||
iCalEventChanges *changes;
|
||||
NSException *ex;
|
||||
NSString *recurrenceTime;
|
||||
BOOL resourceHasAutoAccepted;
|
||||
int i;
|
||||
|
||||
newEvents = [newCalendar events];
|
||||
oldEvents = [oldCalendar events];
|
||||
removedEvents = [NSMutableArray array];
|
||||
updatedEvents = [NSMutableArray array];
|
||||
updatedOldEvents = [NSMutableArray array];
|
||||
newMaster = oldMaster = nil;
|
||||
|
||||
for (i = 0; i < [oldEvents count]; i++)
|
||||
{
|
||||
oldEvent = [oldEvents objectAtIndex: i];
|
||||
|
||||
if (![oldEvent recurrenceId])
|
||||
{
|
||||
if (!oldMaster)
|
||||
oldMaster = oldEvent;
|
||||
}
|
||||
else if (![self _eventFromRecurrenceId: [oldEvent recurrenceId] events: newEvents])
|
||||
[removedEvents addObject: oldEvent];
|
||||
}
|
||||
|
||||
for (i = 0; i < [newEvents count]; i++)
|
||||
{
|
||||
newEvent = [newEvents objectAtIndex: i];
|
||||
|
||||
if (![newEvent recurrenceId])
|
||||
{
|
||||
if (!newMaster)
|
||||
newMaster = newEvent;
|
||||
continue;
|
||||
}
|
||||
|
||||
oldEvent = [self _eventFromRecurrenceId: [newEvent recurrenceId] events: oldEvents];
|
||||
|
||||
// For a new RECURRENCE-ID, compare against the occurrence it replaces
|
||||
if (oldEvent == nil)
|
||||
{
|
||||
recurrenceTime = [NSString stringWithFormat: @"%f", [[newEvent recurrenceId] timeIntervalSince1970]];
|
||||
oldEvent = (iCalEvent *)[self newOccurenceWithID: recurrenceTime];
|
||||
}
|
||||
|
||||
changes = [iCalEventChanges changesFromEvent: oldEvent toEvent: newEvent];
|
||||
|
||||
if ([changes sequenceShouldBeIncreased] || [changes hasAttendeeChanges])
|
||||
{
|
||||
[updatedEvents addObject: newEvent];
|
||||
[updatedOldEvents addObject: (oldEvent ? (id) oldEvent : (id) [NSNull null])];
|
||||
}
|
||||
}
|
||||
|
||||
if (newMaster)
|
||||
{
|
||||
changes = [iCalEventChanges changesFromEvent: oldMaster toEvent: newMaster];
|
||||
|
||||
if (([removedEvents count] == 0 && [updatedEvents count] == 0)
|
||||
|| [changes sequenceShouldBeIncreased] || [changes hasAttendeeChanges])
|
||||
{
|
||||
[updatedEvents addObject: newMaster];
|
||||
[updatedOldEvents addObject: (oldMaster ? (id) oldMaster : (id) [NSNull null])];
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < [removedEvents count]; i++)
|
||||
[self prepareDeleteOccurence: [removedEvents objectAtIndex: i]];
|
||||
|
||||
// Each conflict check resets _resourceHasAutoAccepted, keep it set if any
|
||||
// component got a resource to accept
|
||||
resourceHasAutoAccepted = NO;
|
||||
for (i = 0; i < [updatedEvents count]; i++)
|
||||
{
|
||||
oldEvent = [updatedOldEvents objectAtIndex: i];
|
||||
if ((id) oldEvent == [NSNull null])
|
||||
oldEvent = nil;
|
||||
if ((ex = [self _handleUpdatedEvent: [updatedEvents objectAtIndex: i] fromOldEvent: oldEvent force: YES]))
|
||||
return ex;
|
||||
resourceHasAutoAccepted = resourceHasAutoAccepted || _resourceHasAutoAccepted;
|
||||
}
|
||||
_resourceHasAutoAccepted = resourceHasAutoAccepted;
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
@@ -2479,11 +2583,7 @@ inRecurrenceExceptionsForEvent: (iCalEvent *) theEvent
|
||||
}
|
||||
}
|
||||
|
||||
// A RECCURENCE-ID was removed
|
||||
if (!newEvent && oldEvent)
|
||||
[self prepareDeleteOccurence: oldEvent];
|
||||
// The master event was changed, A RECCURENCE-ID was added or modified
|
||||
else if ((ex = [self _handleUpdatedEvent: newEvent fromOldEvent: oldEvent force: YES]))
|
||||
if ((ex = [self _handleUpdatedCalendar: calendar fromOldCalendar: oldCalendar]))
|
||||
return ex;
|
||||
} // if (ownerIsOrganizer) ..
|
||||
//
|
||||
|
||||
@@ -547,6 +547,152 @@ describe('CalDAV Scheduling', function() {
|
||||
await _getEvent(webdavAttendee1, attendee1Calendar, icsName, 404)
|
||||
})
|
||||
|
||||
describe('RRULE with several changed components in one PUT', function() {
|
||||
const _master = function(uid, summary) {
|
||||
return [
|
||||
'BEGIN:VEVENT',
|
||||
`UID:${uid}`,
|
||||
'DTSTAMP:20260901T100000Z',
|
||||
'DTSTART:20261001T130000Z',
|
||||
'DTEND:20261001T140000Z',
|
||||
'SEQUENCE:0',
|
||||
`SUMMARY:${summary}`,
|
||||
'RRULE:FREQ=WEEKLY;COUNT=5',
|
||||
`ORGANIZER:${user.email}`,
|
||||
`ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION:${attendee1.email}`,
|
||||
'END:VEVENT'
|
||||
]
|
||||
}
|
||||
|
||||
// Moves the occurrence of 'day' (October 2026) two hours earlier
|
||||
const _exception = function(uid, day, partstat) {
|
||||
return [
|
||||
'BEGIN:VEVENT',
|
||||
`UID:${uid}`,
|
||||
'DTSTAMP:20260901T100000Z',
|
||||
`RECURRENCE-ID:202610${day}T130000Z`,
|
||||
`DTSTART:202610${day}T110000Z`,
|
||||
`DTEND:202610${day}T120000Z`,
|
||||
'SEQUENCE:1',
|
||||
'SUMMARY:Weekly sync',
|
||||
`ORGANIZER:${user.email}`,
|
||||
`ATTENDEE;RSVP=TRUE;PARTSTAT=${partstat}:${attendee1.email}`,
|
||||
'END:VEVENT'
|
||||
]
|
||||
}
|
||||
|
||||
const _calendar = function(...vevents) {
|
||||
const lines = ['BEGIN:VCALENDAR', 'VERSION:2.0', 'PRODID:-//SOGo//Tests//EN']
|
||||
return ICAL.Component.fromString(lines.concat(...vevents, 'END:VCALENDAR').join('\r\n'))
|
||||
}
|
||||
|
||||
const _attendeeStartOf = async function(icsName, day) {
|
||||
const vcalendar = await _getEvent(webdavAttendee1, attendee1Calendar, icsName)
|
||||
const vevent = vcalendar.getAllSubcomponents('vevent').find(e => {
|
||||
const rid = e.getFirstPropertyValue('recurrence-id')
|
||||
return day ? rid && rid.toICALString() == `202610${day}T130000Z` : !rid
|
||||
})
|
||||
return vevent && vevent.getFirstPropertyValue('dtstart').toICALString()
|
||||
}
|
||||
|
||||
for (const changedFirst of [true, false]) {
|
||||
it(`schedules every changed occurrence (changed one ${changedFirst ? 'first' : 'last'})`, async function() {
|
||||
const uid = `rrule-several-occurrences-${changedFirst ? 'first' : 'last'}`
|
||||
const icsName = `${uid}.ics`
|
||||
icsList.push(icsName)
|
||||
|
||||
// 1. Move the occurrence of the 22nd. The attendee receives it
|
||||
await _putEvent(webdav, userCalendar, icsName, _calendar(
|
||||
_master(uid, 'Weekly sync'), _exception(uid, '22', 'NEEDS-ACTION')))
|
||||
expect(await _attendeeStartOf(icsName, '22')).toBe('20261022T110000Z')
|
||||
|
||||
// 2. Move the occurrence of the 8th as well. The 22nd is sent back with
|
||||
// a different PARTSTAT, as a client holding an older copy would do.
|
||||
const moved = _exception(uid, '08', 'NEEDS-ACTION')
|
||||
const untouched = _exception(uid, '22', 'ACCEPTED')
|
||||
await _putEvent(webdav, userCalendar, icsName, _calendar(_master(uid, 'Weekly sync'),
|
||||
...(changedFirst ? [moved, untouched] : [untouched, moved])), 204)
|
||||
|
||||
expect(await _attendeeStartOf(icsName, '08'))
|
||||
.withContext('Occurrence of the 8th moved in the calendar of the attendee')
|
||||
.toBe('20261008T110000Z')
|
||||
expect(await _attendeeStartOf(icsName, '22'))
|
||||
.withContext('Occurrence of the 22nd still moved in the calendar of the attendee')
|
||||
.toBe('20261022T110000Z')
|
||||
})
|
||||
}
|
||||
|
||||
it('schedules several occurrences moved in the same PUT', async function() {
|
||||
const uid = 'rrule-several-occurrences-moved'
|
||||
const icsName = `${uid}.ics`
|
||||
icsList.push(icsName)
|
||||
|
||||
await _putEvent(webdav, userCalendar, icsName, _calendar(
|
||||
_master(uid, 'Weekly sync'), _exception(uid, '22', 'NEEDS-ACTION')))
|
||||
|
||||
await _putEvent(webdav, userCalendar, icsName, _calendar(
|
||||
_master(uid, 'Weekly sync'), _exception(uid, '08', 'NEEDS-ACTION'),
|
||||
_exception(uid, '15', 'NEEDS-ACTION'), _exception(uid, '22', 'NEEDS-ACTION')), 204)
|
||||
|
||||
for (const day of ['08', '15', '22']) {
|
||||
expect(await _attendeeStartOf(icsName, day))
|
||||
.withContext(`Occurrence of the ${day} moved in the calendar of the attendee`)
|
||||
.toBe(`202610${day}T110000Z`)
|
||||
}
|
||||
})
|
||||
|
||||
it('cancels a moved occurrence replaced by an EXDATE', async function() {
|
||||
const uid = 'rrule-moved-occurrence-cancelled'
|
||||
const icsName = `${uid}.ics`
|
||||
icsList.push(icsName)
|
||||
|
||||
await _putEvent(webdav, userCalendar, icsName, _calendar(
|
||||
_master(uid, 'Weekly sync'), _exception(uid, '15', 'NEEDS-ACTION'),
|
||||
_exception(uid, '22', 'NEEDS-ACTION')))
|
||||
|
||||
// Drop the occurrence of the 22nd and exclude it from the series
|
||||
const master = _master(uid, 'Weekly sync')
|
||||
master.splice(-1, 0, 'EXDATE:20261022T130000Z')
|
||||
await _putEvent(webdav, userCalendar, icsName, _calendar(
|
||||
master, _exception(uid, '15', 'NEEDS-ACTION')), 204)
|
||||
|
||||
const vcalendar = await _getEvent(webdavAttendee1, attendee1Calendar, icsName)
|
||||
const vevents = vcalendar.getAllSubcomponents('vevent')
|
||||
expect(await _attendeeStartOf(icsName, '22'))
|
||||
.withContext('Occurrence of the 22nd removed from the calendar of the attendee')
|
||||
.toBeUndefined()
|
||||
expect(vevents.find(e => !e.hasProperty('recurrence-id')).hasProperty('exdate'))
|
||||
.withContext('Master event of the attendee excludes the 22nd')
|
||||
.toBe(true)
|
||||
expect(await _attendeeStartOf(icsName, '15'))
|
||||
.withContext('Occurrence of the 15th still moved in the calendar of the attendee')
|
||||
.toBe('20261015T110000Z')
|
||||
})
|
||||
|
||||
it('schedules the master event along with a changed occurrence', async function() {
|
||||
const uid = 'rrule-master-and-occurrence'
|
||||
const icsName = `${uid}.ics`
|
||||
icsList.push(icsName)
|
||||
|
||||
await _putEvent(webdav, userCalendar, icsName, _calendar(
|
||||
_master(uid, 'Weekly sync'), _exception(uid, '22', 'NEEDS-ACTION')))
|
||||
|
||||
// Rename the series and move the occurrence of the 8th in the same PUT
|
||||
await _putEvent(webdav, userCalendar, icsName, _calendar(
|
||||
_master(uid, 'Renamed sync'), _exception(uid, '08', 'NEEDS-ACTION'),
|
||||
_exception(uid, '22', 'NEEDS-ACTION')), 204)
|
||||
|
||||
const vcalendar = await _getEvent(webdavAttendee1, attendee1Calendar, icsName)
|
||||
const master = vcalendar.getAllSubcomponents('vevent').find(e => !e.hasProperty('recurrence-id'))
|
||||
expect(master.getFirstPropertyValue('summary'))
|
||||
.withContext('Summary of the master event in the calendar of the attendee')
|
||||
.toBe('Renamed sync')
|
||||
expect(await _attendeeStartOf(icsName, '08'))
|
||||
.withContext('Occurrence of the 8th moved in the calendar of the attendee')
|
||||
.toBe('20261008T110000Z')
|
||||
})
|
||||
})
|
||||
|
||||
it ('RRULE invitation delete exdate dance', async function() {
|
||||
// Workflow:
|
||||
// Create an recurring event and invite Bob
|
||||
|
||||
Reference in new issue
Block a user