(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.
This commit is contained in:
Francis Lachapelle 2015-07-30 11:51:02 -04:00
parent 0fc7c96924
commit 449093c3f0

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 // 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: componentCalendar
inContext: context]) inContext: context])
{ co = [componentCalendar lookupName: [co nameInContainer]
newFolder = [[thisFolder container] lookupName: newCalendar
inContext: context inContext: context
acquire: NO]; acquire: NO];
if (![sm validatePermission: SoPerm_AddDocumentsImagesAndFiles }
onObject: newFolder
// 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]) inContext: context])
[co moveToFolder: newFolder]; {
if (![sm validatePermission: SoPerm_AddDocumentsImagesAndFiles
onObject: componentCalendar
inContext: context])
ex = [co moveToFolder: componentCalendar];
}
} }
} }
} }
if (ex) if (ex)
{
httpStatus = 500;
jsonResponse = [NSDictionary dictionaryWithObjectsAndKeys: jsonResponse = [NSDictionary dictionaryWithObjectsAndKeys:
@"failure", @"status", @"failure", @"status",
[ex reason], [ex reason], @"message",
@"message",
nil]; nil];
}
else else
{
httpStatus = 200;
jsonResponse = [NSDictionary dictionaryWithObjectsAndKeys: jsonResponse = [NSDictionary dictionaryWithObjectsAndKeys:
@"success", @"status", nil]; @"success", @"status", nil];
}
return [self responseWithStatus: 200 return [self responseWithStatus: httpStatus
andJSONRepresentation: jsonResponse]; andJSONRepresentation: jsonResponse];
} }