(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.
pull/91/merge
Francis Lachapelle 2015-07-30 11:51:02 -04:00
parent 0fc7c96924
commit 449093c3f0
1 changed files with 54 additions and 24 deletions

View File

@ -321,15 +321,18 @@
{ {
NSDictionary *params; NSDictionary *params;
NSException *ex; NSException *ex;
NSString *newCalendar, *jsonResponse; NSString *jsonResponse;
SOGoAppointmentFolder *thisFolder, *newFolder; SOGoAppointmentFolder *previousCalendar;
SOGoTaskObject *co; SOGoTaskObject *co;
SoSecurityManager *sm; SoSecurityManager *sm;
WORequest *request; WORequest *request;
iCalToDo *todo; iCalToDo *todo;
unsigned int httpStatus;
todo = [self todo]; todo = [self todo];
co = [self clientObject]; co = [self clientObject];
previousCalendar = [co container];
sm = [SoSecurityManager sharedSecurityManager];
ex = nil; ex = nil;
request = [context request]; request = [context request];
@ -343,40 +346,67 @@
else else
{ {
[self setAttributes: params]; [self setAttributes: params];
ex = [co saveComponent: todo];
newCalendar = [self queryParameterForKey: @"moveToCalendar"]; if ([co isNew])
if ([newCalendar length])
{ {
sm = [SoSecurityManager sharedSecurityManager]; if (componentCalendar
&& ![[componentCalendar ocsPath]
thisFolder = [co container]; isEqualToString: [previousCalendar ocsPath]])
if (![sm validatePermission: SoPerm_DeleteObjects
onObject: thisFolder
inContext: context])
{ {
newFolder = [[thisFolder container] lookupName: newCalendar // New task in a different calendar -- make sure the user can
inContext: context // write to the selected calendar since the rights were verified
acquire: NO]; // on the calendar specified in the URL, not on the selected
// calendar of the popup menu.
if (![sm validatePermission: SoPerm_AddDocumentsImagesAndFiles if (![sm validatePermission: SoPerm_AddDocumentsImagesAndFiles
onObject: newFolder onObject: componentCalendar
inContext: context]) 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) if (ex)
jsonResponse = [NSDictionary dictionaryWithObjectsAndKeys: {
@"failure", @"status", httpStatus = 500;
[ex reason], jsonResponse = [NSDictionary dictionaryWithObjectsAndKeys:
@"message", @"failure", @"status",
nil]; [ex reason], @"message",
nil];
}
else 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]; andJSONRepresentation: jsonResponse];
} }