From fbd2eb8294f6b753995b95e4e8e59a5520acd477 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Thu, 24 Mar 2022 15:28:06 -0400 Subject: [PATCH] fix(calendar): rely on organizer's event state before updating attendee When an attendee is adding a new event for which the organizer is local but doesn't have the event anymore, return a 412 error code. Fixes #5496 --- .../Appointments/SOGoAppointmentObject.m | 25 +++++++++++++++---- SoObjects/SOGo/SOGoParentFolder.m | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/SoObjects/Appointments/SOGoAppointmentObject.m b/SoObjects/Appointments/SOGoAppointmentObject.m index c2ef31443d..8d10bc7be9 100644 --- a/SoObjects/Appointments/SOGoAppointmentObject.m +++ b/SoObjects/Appointments/SOGoAppointmentObject.m @@ -1,5 +1,5 @@ /* - Copyright (C) 2007-2020 Inverse inc. + Copyright (C) 2007-2022 Inverse inc. This file is part of SOGo @@ -151,7 +151,8 @@ - (SOGoAppointmentObject *) _lookupEvent: (NSString *) eventUID if (possibleName) { object = [folder lookupName: possibleName - inContext: context acquire: NO]; + inContext: context + acquire: NO]; if ([object isKindOfClass: [NSException class]] || [object isNew]) object = nil; } @@ -163,10 +164,9 @@ - (SOGoAppointmentObject *) _lookupEvent: (NSString *) eventUID if (!object) { // Create the event in the user's personal calendar. - folder = [[SOGoUser userWithLogin: uid] - personalCalendarFolderInContext: context]; + folder = [[SOGoUser userWithLogin: uid] personalCalendarFolderInContext: context]; object = [SOGoAppointmentObject objectWithName: nameInContainer - inContainer: folder]; + inContainer: folder]; [object setIsNew: YES]; } @@ -2528,6 +2528,7 @@ - (id) PUTAction: (WOContext *) _ctx iCalEvent *currentMasterEvent; NSArray *folders; NSEnumerator *e; + NSString *organizerUID; SOGoAppointmentFolder *folder; SOGoAppointmentObject *object; @@ -2555,6 +2556,20 @@ - (id) PUTAction: (WOContext *) _ctx } } } + + // Verify if the event is still present in the organizer calendar + organizerUID = [[masterEvent organizer] uidInContext: context]; + if (organizerUID) + { + object = [self _lookupEvent: [masterEvent uid] + forUID: organizerUID]; + if ([object isNew]) + { + // The event has vanished + return [NSException exceptionWithDAVStatus: 412 + reason: @"Precondition Failed"]; + } + } } } else diff --git a/SoObjects/SOGo/SOGoParentFolder.m b/SoObjects/SOGo/SOGoParentFolder.m index a1324b34e3..22cad405ad 100644 --- a/SoObjects/SOGo/SOGoParentFolder.m +++ b/SoObjects/SOGo/SOGoParentFolder.m @@ -177,7 +177,7 @@ - (void) createSpecialFolder: (SOGoFolderType) folderType [folder setOCSPath: [NSString stringWithFormat: @"%@/%@", OCSPath, folderName]]; if ([folder create]) - [subFolders setObject: folder forKey: folderName]; + [subFolders setObject: folder forKey: folderName]; } else if (folderType == SOGoCollectedFolder) {