From 449093c3f0e84ba8dd15c5a7eed47086c844bd32 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Thu, 30 Jul 2015 11:51:02 -0400 Subject: [PATCH] (fix) Calendar destination of new task Also removed the possibility to use the "moveToCalendar" parameter. We should eventually create UIxTaskActions.m as we have UIxAppointmentActions.m for this kind of actions. --- UI/Scheduler/UIxTaskEditor.m | 78 +++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 24 deletions(-) diff --git a/UI/Scheduler/UIxTaskEditor.m b/UI/Scheduler/UIxTaskEditor.m index 1c0d38004..138db2684 100644 --- a/UI/Scheduler/UIxTaskEditor.m +++ b/UI/Scheduler/UIxTaskEditor.m @@ -321,15 +321,18 @@ { NSDictionary *params; NSException *ex; - NSString *newCalendar, *jsonResponse; - SOGoAppointmentFolder *thisFolder, *newFolder; + NSString *jsonResponse; + SOGoAppointmentFolder *previousCalendar; SOGoTaskObject *co; SoSecurityManager *sm; WORequest *request; iCalToDo *todo; + unsigned int httpStatus; todo = [self todo]; co = [self clientObject]; + previousCalendar = [co container]; + sm = [SoSecurityManager sharedSecurityManager]; ex = nil; request = [context request]; @@ -343,40 +346,67 @@ else { [self setAttributes: params]; - ex = [co saveComponent: todo]; - newCalendar = [self queryParameterForKey: @"moveToCalendar"]; - if ([newCalendar length]) + if ([co isNew]) { - sm = [SoSecurityManager sharedSecurityManager]; - - thisFolder = [co container]; - if (![sm validatePermission: SoPerm_DeleteObjects - onObject: thisFolder - inContext: context]) + if (componentCalendar + && ![[componentCalendar ocsPath] + isEqualToString: [previousCalendar ocsPath]]) { - newFolder = [[thisFolder container] lookupName: newCalendar - inContext: context - acquire: NO]; + // New task in a different calendar -- make sure the user can + // write to the selected calendar since the rights were verified + // on the calendar specified in the URL, not on the selected + // calendar of the popup menu. if (![sm validatePermission: SoPerm_AddDocumentsImagesAndFiles - onObject: newFolder + onObject: componentCalendar inContext: context]) - [co moveToFolder: newFolder]; + co = [componentCalendar lookupName: [co nameInContainer] + inContext: context + acquire: NO]; + } + + // Save the task. + ex = [co saveComponent: todo]; + } + else + { + // The task was modified -- save it. + ex = [co saveComponent: todo]; + + if (componentCalendar + && ![[componentCalendar ocsPath] + isEqualToString: [previousCalendar ocsPath]]) + { + // The task was moved to a different calendar. + if (![sm validatePermission: SoPerm_DeleteObjects + onObject: previousCalendar + inContext: context]) + { + if (![sm validatePermission: SoPerm_AddDocumentsImagesAndFiles + onObject: componentCalendar + inContext: context]) + ex = [co moveToFolder: componentCalendar]; + } } } } if (ex) - jsonResponse = [NSDictionary dictionaryWithObjectsAndKeys: - @"failure", @"status", - [ex reason], - @"message", - nil]; + { + httpStatus = 500; + jsonResponse = [NSDictionary dictionaryWithObjectsAndKeys: + @"failure", @"status", + [ex reason], @"message", + nil]; + } else - jsonResponse = [NSDictionary dictionaryWithObjectsAndKeys: - @"success", @"status", nil]; + { + httpStatus = 200; + jsonResponse = [NSDictionary dictionaryWithObjectsAndKeys: + @"success", @"status", nil]; + } - return [self responseWithStatus: 200 + return [self responseWithStatus: httpStatus andJSONRepresentation: jsonResponse]; }