Skip to content

Commit

Permalink
fix(calendar): rely on organizer's event state before updating attendee
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cgx committed Mar 24, 2022
1 parent 5d2877c commit fbd2eb8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
25 changes: 20 additions & 5 deletions SoObjects/Appointments/SOGoAppointmentObject.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2007-2020 Inverse inc.
Copyright (C) 2007-2022 Inverse inc.
This file is part of SOGo
Expand Down Expand Up @@ -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;
}
Expand All @@ -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];
}

Expand Down Expand Up @@ -2528,6 +2528,7 @@ - (id) PUTAction: (WOContext *) _ctx
iCalEvent *currentMasterEvent;
NSArray *folders;
NSEnumerator *e;
NSString *organizerUID;
SOGoAppointmentFolder *folder;
SOGoAppointmentObject *object;

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion SoObjects/SOGo/SOGoParentFolder.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit fbd2eb8

Please sign in to comment.