diff --git a/SoObjects/Appointments/SOGoAppointmentFolder.m b/SoObjects/Appointments/SOGoAppointmentFolder.m index 8d5e05aa1..a5806d996 100644 --- a/SoObjects/Appointments/SOGoAppointmentFolder.m +++ b/SoObjects/Appointments/SOGoAppointmentFolder.m @@ -3076,15 +3076,15 @@ firstInstanceCalendarDateRange: (NGCalendarDateRange *) fir } /* folder management */ -- (BOOL) create +- (NSException *) create { - BOOL rc; SOGoUserSettings *userSettings; NSMutableDictionary *calendarSettings; + NSException *error; SOGoUser *ownerUser; - rc = [super create]; - if (rc) + error = [super create]; + if (!error) { ownerUser = [SOGoUser userWithLogin: [self ownerInContext: context]]; userSettings = [ownerUser userSettings]; @@ -3097,7 +3097,7 @@ firstInstanceCalendarDateRange: (NGCalendarDateRange *) fir [userSettings synchronize]; } - return rc; + return error; } - (void) removeFolderSettings: (NSMutableDictionary *) moduleSettings diff --git a/SoObjects/Appointments/SOGoAppointmentFolders.m b/SoObjects/Appointments/SOGoAppointmentFolders.m index b8639c0f1..aa13063f8 100644 --- a/SoObjects/Appointments/SOGoAppointmentFolders.m +++ b/SoObjects/Appointments/SOGoAppointmentFolders.m @@ -398,20 +398,18 @@ static SoSecurityManager *sm = nil; if ([subfolderNames containsObject: newName]) { content = [NSString stringWithFormat: @"A collection named '%@' already exists.", newName]; - error = [NSException exceptionWithDAVStatus: 403 + error = [NSException exceptionWithDAVStatus: 405 reason: content]; } else { - properties = [[createContext request] - davPatchedPropertiesWithTopTag: @"mkcalendar"]; + properties = [[createContext request] davPatchedPropertiesWithTopTag: @"mkcalendar"]; setProperties = [properties objectForKey: @"set"]; newDisplayName = [self _fetchPropertyWithName: @"{DAV:}displayname" inArray: setProperties]; if (![newDisplayName length]) newDisplayName = newName; - error - = [self newFolderWithName: newDisplayName andNameInContainer: newName]; + error = [self newFolderWithName: newDisplayName andNameInContainer: newName]; if (!error) { newFolder = [self lookupName: newName diff --git a/SoObjects/SOGo/SOGoGCSFolder.h b/SoObjects/SOGo/SOGoGCSFolder.h index 6a3f56fa7..a5d0c7a13 100644 --- a/SoObjects/SOGo/SOGoGCSFolder.h +++ b/SoObjects/SOGo/SOGoGCSFolder.h @@ -1,6 +1,6 @@ /* Copyright (C) 2004-2005 SKYRIX Software AG - Copyright (C) 2006-2015 Inverse inc. + Copyright (C) 2006-2022 Inverse inc. This file is part of SOGo. @@ -96,7 +96,7 @@ - (BOOL) folderIsMandatory; -- (BOOL) create; +- (NSException *) create; - (NSException *) delete; - (void) renameTo: (NSString *) newName; diff --git a/SoObjects/SOGo/SOGoGCSFolder.m b/SoObjects/SOGo/SOGoGCSFolder.m index d2ac21d66..2b1bf55a8 100644 --- a/SoObjects/SOGo/SOGoGCSFolder.m +++ b/SoObjects/SOGo/SOGoGCSFolder.m @@ -556,7 +556,7 @@ static NSArray *childRecordFields = nil; && [userLogin isEqualToString: [self ownerInContext: context]] && [user canAuthenticate] && [self folderIsMandatory] - && [self create]) + && ![self create]) ocsFolder = [self ocsFolderForPath: [self ocsPath]]; [ocsFolder retain]; } @@ -569,7 +569,7 @@ static NSArray *childRecordFields = nil; return folder; } -- (BOOL) create +- (NSException *) create { NSException *result; result = [[self folderManager] createFolderOfType: [self folderType] @@ -580,7 +580,7 @@ static NSArray *childRecordFields = nil; && [[context request] handledByDefaultHandler]) [self sendFolderAdvisoryTemplate: @"Addition"]; - return (result == nil); + return result; } - (NSException *) delete diff --git a/SoObjects/SOGo/SOGoObject.m b/SoObjects/SOGo/SOGoObject.m index 9de8fe230..277b9d8ca 100644 --- a/SoObjects/SOGo/SOGoObject.m +++ b/SoObjects/SOGo/SOGoObject.m @@ -413,7 +413,7 @@ davPrivileges = [NSMutableArray array]; privileges = [[webdavAclManager davPermissionsForRoles: roles - onObject: self] objectEnumerator]; + onObject: self] objectEnumerator]; while ((privilege = [privileges nextObject])) [davPrivileges addObject: davElementWithContent (@"privilege", XMLNS_WEBDAV, privilege)]; diff --git a/SoObjects/SOGo/SOGoParentFolder.m b/SoObjects/SOGo/SOGoParentFolder.m index 67ecba927..e39022662 100644 --- a/SoObjects/SOGo/SOGoParentFolder.m +++ b/SoObjects/SOGo/SOGoParentFolder.m @@ -178,7 +178,7 @@ static SoSecurityManager *sm = nil; [folder setDisplayName: [self defaultFolderName]]; [folder setOCSPath: [NSString stringWithFormat: @"%@/%@", OCSPath, folderName]]; - if ([folder create]) + if (![folder create]) [subFolders setObject: folder forKey: folderName]; } else if (folderType == SOGoCollectedFolder) @@ -190,7 +190,7 @@ static SoSecurityManager *sm = nil; [folder setDisplayName: [self collectedFolderName]]; [folder setOCSPath: [NSString stringWithFormat: @"%@/%@", OCSPath, folderName]]; - if ([folder create]) + if (![folder create]) [subFolders setObject: folder forKey: folderName]; [ud setSelectedAddressBook:folderName]; @@ -406,14 +406,23 @@ static SoSecurityManager *sm = nil; [newFolder setDisplayName: name]; [newFolder setOCSPath: [NSString stringWithFormat: @"%@/%@", OCSPath, newNameInContainer]]; - if ([newFolder create]) + error = [newFolder create]; + if (!error) { [subFolders setObject: newFolder forKey: newNameInContainer]; error = nil; } + else if ([[error name] isEqual: @"GCSExitingFolder"]) + { + error = [self exceptionWithHTTPStatus: 405 + reason: [error reason]]; + } else - error = [self exceptionWithHTTPStatus: 400 - reason: @"The new folder could not be created"]; + { + [self errorWithFormat: @"An error occured when creating a folder: %@ - %@", [error name], [error reason]]; + error = [self exceptionWithHTTPStatus: 400 + reason: @"The new folder could not be created"]; + } } return error; diff --git a/Tests/spec/CalDAVPropertiesSpec.js b/Tests/spec/CalDAVPropertiesSpec.js index a0f2af15e..0c9ddb000 100644 --- a/Tests/spec/CalDAVPropertiesSpec.js +++ b/Tests/spec/CalDAVPropertiesSpec.js @@ -15,6 +15,13 @@ describe('read and set calendar properties', function() { await webdav.deleteObject(resource) }) + it("calendar already exists", async function() { + const response = await webdav.makeCalendar(resource) + expect(response[0].status) + .withContext(`HTTP status code of MKCALENDAR`) + .toEqual(405) + }) + // CalDAVPropertiesTest it("propfind", async function() { diff --git a/Tests/spec/CardDAVSpec.js b/Tests/spec/CardDAVSpec.js index c83667cf6..f57a1e09c 100644 --- a/Tests/spec/CardDAVSpec.js +++ b/Tests/spec/CardDAVSpec.js @@ -97,6 +97,13 @@ describe('CardDAV extensions', function() { await webdav_su.deleteObject(resource) }) + it("addressbook already exists", async function() { + const response = await webdav.makeCollection(resource) + expect(response[0].status) + .withContext(`HTTP status code of MKCOL`) + .toEqual(405) + }) + // CARDDAV:addressbook-query Report // https://datatracker.ietf.org/doc/html/rfc6352#section-8.6 it("supports for addressbook-query on GCS folder", async function() {