From 80785304f16270ae4bc2f08c56b30ed54eaae9c0 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Mon, 26 Jan 2015 15:45:42 -0500 Subject: [PATCH] JSONify [UIxCalendarProperties saveAction] --- .../Appointments/SOGoAppointmentFolder.h | 9 + .../Appointments/SOGoAppointmentFolder.m | 78 ++++- UI/Scheduler/UIxCalendarProperties.h | 27 +- UI/Scheduler/UIxCalendarProperties.m | 302 +++++------------- UI/Scheduler/product.plist | 2 +- 5 files changed, 164 insertions(+), 254 deletions(-) diff --git a/SoObjects/Appointments/SOGoAppointmentFolder.h b/SoObjects/Appointments/SOGoAppointmentFolder.h index d535806b4..126273d6a 100644 --- a/SoObjects/Appointments/SOGoAppointmentFolder.h +++ b/SoObjects/Appointments/SOGoAppointmentFolder.h @@ -65,6 +65,7 @@ typedef enum { NSMutableDictionary *uidToFilename; NSMutableDictionary *aclMatrix; NSMutableArray *stripFields; + NSString *baseCalDAVURL, *basePublicCalDAVURL; int davCalendarStartTimeLimit; int davTimeLimitSeconds; int davTimeHalfLimitSeconds; @@ -73,6 +74,7 @@ typedef enum { } - (BOOL) isActive; +- (BOOL) isWebCalendar; - (NSString *) calendarColor; - (void) setCalendarColor: (NSString *) newColor; @@ -129,6 +131,13 @@ typedef enum { - (NSString *) baseURLForAptWithUID: (NSString *) _uid inContext: (id) _ctx; +- (NSString *) calDavURL; +- (NSString *) webDavICSURL; +- (NSString *) webDavXMLURL; +- (NSString *) publicCalDavURL; +- (NSString *) publicWebDavICSURL; +- (NSString *) publicWebDavXMLURL; + /* folder management */ - (id) lookupHomeFolderForUID: (NSString *) _uid diff --git a/SoObjects/Appointments/SOGoAppointmentFolder.m b/SoObjects/Appointments/SOGoAppointmentFolder.m index f0d310bd7..1279959b6 100644 --- a/SoObjects/Appointments/SOGoAppointmentFolder.m +++ b/SoObjects/Appointments/SOGoAppointmentFolder.m @@ -84,6 +84,7 @@ #import "SOGoAppointmentFolders.h" #import "SOGoFreeBusyObject.h" #import "SOGoTaskObject.h" +#import "SOGoWebAppointmentFolder.h"; #import "SOGoAppointmentFolder.h" @@ -332,13 +333,15 @@ static Class iCalEventK = nil; memset (userCanAccessObjectsClassifiedAs, NO, iCalAccessClassCount * sizeof (BOOL)); - davCalendarStartTimeLimit - = [[user domainDefaults] davCalendarStartTimeLimit]; + davCalendarStartTimeLimit = [[user domainDefaults] davCalendarStartTimeLimit]; davTimeLimitSeconds = davCalendarStartTimeLimit * 86400; /* 86400 / 2 = 43200. We hardcode that value in order to avoid integer and float confusion. */ davTimeHalfLimitSeconds = davCalendarStartTimeLimit * 43200; componentSet = nil; + + baseCalDAVURL = nil; + basePublicCalDAVURL = nil; } return self; @@ -350,6 +353,8 @@ static Class iCalEventK = nil; [stripFields release]; [uidToFilename release]; [componentSet release]; + [baseCalDAVURL release]; + [basePublicCalDAVURL release]; [super dealloc]; } @@ -2869,6 +2874,70 @@ firstInstanceCalendarDateRange: (NGCalendarDateRange *) fir return [url stringByAppendingString:_uid]; } +- (NSString *) _baseCalDAVURL +{ + NSString *davURL; + + if (!baseCalDAVURL) + { + davURL = [[self realDavURL] absoluteString]; + if ([davURL hasSuffix: @"/"]) + baseCalDAVURL = [davURL substringToIndex: [davURL length] - 1]; + else + baseCalDAVURL = davURL; + [baseCalDAVURL retain]; + } + + return baseCalDAVURL; +} + +- (NSString *) _basePublicCalDAVURL +{ + NSString *davURL; + + if (!basePublicCalDAVURL) + { + davURL = [[self publicDavURL] absoluteString]; + if ([davURL hasSuffix: @"/"]) + basePublicCalDAVURL = [davURL substringToIndex: [davURL length] - 1]; + else + basePublicCalDAVURL = davURL; + [basePublicCalDAVURL retain]; + } + + return basePublicCalDAVURL; +} + +- (NSString *) calDavURL +{ + return [NSString stringWithFormat: @"%@/", [self _baseCalDAVURL]]; +} + +- (NSString *) webDavICSURL +{ + return [NSString stringWithFormat: @"%@.ics", [self _baseCalDAVURL]]; +} + +- (NSString *) webDavXMLURL +{ + return [NSString stringWithFormat: @"%@.xml", [self _baseCalDAVURL]]; +} + +- (NSString *) publicCalDavURL +{ + return [NSString stringWithFormat: @"%@/", [self _basePublicCalDAVURL]]; +} + +- (NSString *) publicWebDavICSURL +{ + return [NSString stringWithFormat: @"%@.ics", [self _basePublicCalDAVURL]]; +} + +- (NSString *) publicWebDavXMLURL +{ + return [NSString stringWithFormat: @"%@.xml", [self _basePublicCalDAVURL]]; +} + /* folder management */ - (BOOL) create { @@ -3132,6 +3201,11 @@ firstInstanceCalendarDateRange: (NGCalendarDateRange *) fir return (![inactiveFolders containsObject: nameInContainer]); } +- (BOOL) isWebCalendar +{ + return ([self isKindOfClass: [SOGoWebAppointmentFolder class]]); +} + - (NSString *) importComponent: (iCalEntityObject *) event timezone: (iCalTimeZone *) timezone { diff --git a/UI/Scheduler/UIxCalendarProperties.h b/UI/Scheduler/UIxCalendarProperties.h index de17b6117..dd005bbb8 100644 --- a/UI/Scheduler/UIxCalendarProperties.h +++ b/UI/Scheduler/UIxCalendarProperties.h @@ -1,6 +1,6 @@ /* UIxCalendarProperties.m - this file is part of SOGo * - * Copyright (C) 2008-2014 Inverse inc. + * Copyright (C) 2008-2015 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,36 +27,11 @@ @interface UIxCalendarProperties : UIxComponent { SOGoAppointmentFolder *calendar; - NSString *baseCalDAVURL, *basePublicCalDAVURL; - BOOL reloadTasks; } -- (NSString *) calendarName; -- (void) setCalendarName: (NSString *) newName; - -- (NSString *) calendarColor; -- (void) setCalendarColor: (NSString *) newColor; - -- (BOOL) showCalendarAlarms; -- (void) setShowCalendarAlarms: (BOOL) new; - -- (BOOL) synchronizeCalendar; -- (void) setSynchronizeCalendar: (BOOL) new; - - (NSString *) originalCalendarSyncTag; - (NSString *) allCalendarSyncTags; - (BOOL) mustSynchronize; -- (NSString *) calendarSyncTag; - (void) setCalendarSyncTag: (NSString *) newTag; -/* notifications */ -- (BOOL) notifyOnPersonalModifications; -- (void) setNotifyOnPersonalModifications: (BOOL) b; -- (BOOL) notifyOnExternalModifications; -- (void) setNotifyOnExternalModifications: (BOOL) b; -- (BOOL) notifyUserOnPersonalModifications; -- (void) setNotifyUserOnPersonalModifications: (BOOL) b; -- (NSString *) notifiedUserOnPersonalModifications; -- (void) setNotifiedUserOnPersonalModifications: (NSString *) theUser; - @end diff --git a/UI/Scheduler/UIxCalendarProperties.m b/UI/Scheduler/UIxCalendarProperties.m index 8f0ec4e81..bd1497dc2 100644 --- a/UI/Scheduler/UIxCalendarProperties.m +++ b/UI/Scheduler/UIxCalendarProperties.m @@ -1,6 +1,6 @@ /* UIxCalendarProperties.m - this file is part of SOGo * - * Copyright (C) 2008-2014 Inverse inc. + * Copyright (C) 2008-2015 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,12 +21,15 @@ #import #import #import +#import #import +#import #import #import #import + #import #import @@ -39,9 +42,6 @@ if ((self = [super init])) { calendar = [self clientObject]; - baseCalDAVURL = nil; - basePublicCalDAVURL = nil; - reloadTasks = NO; } return self; @@ -49,56 +49,9 @@ - (void) dealloc { - [baseCalDAVURL release]; - [basePublicCalDAVURL release]; [super dealloc]; } -- (NSString *) calendarID -{ - return [calendar folderReference]; -} - -- (NSString *) calendarName -{ - return [calendar displayName]; -} - -- (void) setCalendarName: (NSString *) newName -{ - [calendar renameTo: newName]; -} - -- (NSString *) calendarColor -{ - return [calendar calendarColor]; -} - -- (void) setCalendarColor: (NSString *) newColor -{ - [calendar setCalendarColor: newColor]; -} - -- (BOOL) includeInFreeBusy -{ - return [calendar includeInFreeBusy]; -} - -- (void) setIncludeInFreeBusy: (BOOL) newInclude -{ - [calendar setIncludeInFreeBusy: newInclude]; -} - -- (BOOL) synchronizeCalendar -{ - return [self mustSynchronize] || [calendar synchronizeCalendar]; -} - -- (void) setSynchronizeCalendar: (BOOL) new -{ - [calendar setSynchronizeCalendar: new]; -} - - (NSString *) originalCalendarSyncTag { return [calendar syncTag]; @@ -144,199 +97,98 @@ return [[calendar nameInContainer] isEqualToString: @"personal"]; } -- (NSString *) calendarSyncTag -{ - return [calendar syncTag]; -} +// - (NSString *) calendarSyncTag +// { +// return [calendar syncTag]; +// } - (void) setCalendarSyncTag: (NSString *) newTag { [calendar setSyncTag: newTag]; } -- (BOOL) showCalendarAlarms +/** + * @api {post} /so/:username/Calendar/:calendarId/save Save calendar + * @apiDescription Save a calendar's properties. + * @apiVersion 1.0.0 + * @apiName PostSaveProperties + * @apiGroup Calendar + * @apiExample {curl} Example usage: + * curl -i http://localhost/SOGo/so/sogo1/Calendar/personal/save \ + * -H "Content-Type: application/json" \ + * -d '{"displayName": "Personal Calendar", "notifications": {"notifyOnPersonalModifications": true}}' + * + * @apiParam {String} displayName Human readable name + * @apiParam {String} color Calendar's hex color code + * @apiParam {Number} includeInFreeBusy 1 if calendar must be include in freebusy + * @apiParam {Number} synchronizeCalendar 1 if calendar must be synchronized + * @apiParam {Number} showCalendarAlarms 1 if alarms must be enabled + * @apiParam {Number} showCalendarTasks 1 if tasks must be enabled + * @apiParam {Number} reloadOnLogin 1 if calendar is a Web calendar that must be reload when user logins + * @apiParam {Object} [notifications] Notification (if active user is the calendar's owner) + * @apiParam {Number} notifications.notifyOnPersonalModifications 1 if a mail is sent for each modification made by the owner + * @apiParam {Number} notifications.notifyOnExternalModifications 1 if a mail is sent for each modification made by someone else + * @apiParam {Number} notifications.notifyUserOnPersonalModifications 1 if a mail is sent to an external address for modification made by the owner + * @apiParam {String} [notifications.notifiedUserOnPersonalModifications] Email address to notify changes + */ +- (WOResponse *) savePropertiesAction { - return [calendar showCalendarAlarms]; -} + WORequest *request; + NSDictionary *params; + id o, values; -- (void) setShowCalendarAlarms: (BOOL) new -{ - if (new != [calendar showCalendarAlarms]) - reloadTasks = YES; - [calendar setShowCalendarAlarms: new]; -} + request = [context request]; + params = [[request contentAsString] objectFromJSONString]; -- (BOOL) showCalendarTasks -{ - return [calendar showCalendarTasks]; -} + o = [params objectForKey: @"displayName"]; + if ([o isKindOfClass: [NSString class]]) + [calendar renameTo: o]; -- (void) setShowCalendarTasks: (BOOL) new -{ - if (new != [calendar showCalendarTasks]) - reloadTasks = YES; - [calendar setShowCalendarTasks: new]; -} + o = [params objectForKey: @"color"]; + if ([o isKindOfClass: [NSString class]]) + [calendar setCalendarColor: o]; -- (BOOL) isPublicAccessEnabled -{ - // NOTE: This method is the same found in Common/UIxAclEditor.m - return [[SOGoSystemDefaults sharedSystemDefaults] - enablePublicAccess]; -} + o = [params objectForKey: @"includeInFreeBusy"]; + if ([o isKindOfClass: [NSNumber class]]) + [calendar setIncludeInFreeBusy: [o boolValue]]; -- (BOOL) isWebCalendar -{ - return ([calendar isKindOfClass: [SOGoWebAppointmentFolder class]]); -} + o = [params objectForKey: @"synchronizeCalendar"]; + if ([o isKindOfClass: [NSNumber class]]) + [calendar setSynchronizeCalendar: [self mustSynchronize] || [o boolValue]]; -- (NSString *) webCalendarURL -{ - return [calendar folderPropertyValueInCategory: @"WebCalendars"]; -} + o = [params objectForKey: @"showCalendarAlarms"]; + if ([o isKindOfClass: [NSNumber class]]) + [calendar setShowCalendarAlarms: [o boolValue]]; -- (void) setReloadOnLogin: (BOOL) newReloadOnLogin -{ - if ([calendar respondsToSelector: @selector (setReloadOnLogin:)]) - [(SOGoWebAppointmentFolder *) calendar - setReloadOnLogin: newReloadOnLogin]; -} + o = [params objectForKey: @"showCalendarTasks"]; + if ([o isKindOfClass: [NSNumber class]]) + [calendar setShowCalendarTasks: [o boolValue]]; -- (BOOL) reloadOnLogin -{ - BOOL rc; + o = [params objectForKey: @"showCalendarTasks"]; + if ([o isKindOfClass: [NSNumber class]]) + [calendar setShowCalendarTasks: [o boolValue]]; - if ([calendar respondsToSelector: @selector (reloadOnLogin)]) - rc = [(SOGoWebAppointmentFolder *) calendar reloadOnLogin]; - else - rc = NO; - - return rc; -} - -- (BOOL) shouldTakeValuesFromRequest: (WORequest *) request - inContext: (WOContext*) context -{ - NSString *method; - - method = [[request uri] lastPathComponent]; - - return [method isEqualToString: @"saveProperties"]; -} - -- (id ) savePropertiesAction -{ - NSString *action; - - if (reloadTasks) - action = @"refreshTasks()"; - else - action = nil; - return [self jsCloseWithRefreshMethod: action]; -} - -- (NSString *) _baseCalDAVURL -{ - NSString *davURL; - - if (!baseCalDAVURL) + values = [params objectForKey: @"notifications"]; + if ([values isKindOfClass: [NSDictionary class]]) { - davURL = [[calendar realDavURL] absoluteString]; - if ([davURL hasSuffix: @"/"]) - baseCalDAVURL = [davURL substringToIndex: [davURL length] - 1]; - else - baseCalDAVURL = davURL; - [baseCalDAVURL retain]; + o = [values objectForKey: @"notifyOnPersonalModifications"]; + if ([o isKindOfClass: [NSNumber class]]) + [calendar setNotifyOnPersonalModifications: [o boolValue]]; + + o = [values objectForKey: @"notifyOnExternalModifications"]; + if ([o isKindOfClass: [NSNumber class]]) + [calendar setNotifyOnExternalModifications: [o boolValue]]; + + o = [values objectForKey: @"notifyUserOnPersonalModifications"]; + if ([o isKindOfClass: [NSNumber class]]) + [calendar setNotifyUserOnPersonalModifications: [o boolValue]]; + + o = [values objectForKey: @"notifiedUserOnPersonalModifications"]; + if ([o isKindOfClass: [NSString class]]) + [calendar setNotifiedUserOnPersonalModifications: o]; } - return baseCalDAVURL; -} - -- (NSString *) _basePublicCalDAVURL -{ - NSString *davURL; - - if (!basePublicCalDAVURL) - { - davURL = [[calendar publicDavURL] absoluteString]; - if ([davURL hasSuffix: @"/"]) - basePublicCalDAVURL = [davURL substringToIndex: [davURL length] - 1]; - else - basePublicCalDAVURL = davURL; - [basePublicCalDAVURL retain]; - } - - return basePublicCalDAVURL; -} - -- (NSString *) calDavURL -{ - return [NSString stringWithFormat: @"%@/", [self _baseCalDAVURL]]; -} - -- (NSString *) webDavICSURL -{ - return [NSString stringWithFormat: @"%@.ics", [self _baseCalDAVURL]]; -} - -- (NSString *) webDavXMLURL -{ - return [NSString stringWithFormat: @"%@.xml", [self _baseCalDAVURL]]; -} - -- (NSString *) publicCalDavURL -{ - return [NSString stringWithFormat: @"%@/", [self _basePublicCalDAVURL]]; -} - -- (NSString *) publicWebDavICSURL -{ - return [NSString stringWithFormat: @"%@.ics", [self _basePublicCalDAVURL]]; -} - -- (NSString *) publicWebDavXMLURL -{ - return [NSString stringWithFormat: @"%@.xml", [self _basePublicCalDAVURL]]; -} - -- (BOOL) notifyOnPersonalModifications -{ - return [calendar notifyOnPersonalModifications]; -} - -- (void) setNotifyOnPersonalModifications: (BOOL) b -{ - [calendar setNotifyOnPersonalModifications: b]; -} - -- (BOOL) notifyOnExternalModifications -{ - return [calendar notifyOnExternalModifications]; -} - -- (void) setNotifyOnExternalModifications: (BOOL) b -{ - [calendar setNotifyOnExternalModifications: b]; -} - -- (BOOL) notifyUserOnPersonalModifications -{ - return [calendar notifyUserOnPersonalModifications]; -} - -- (void) setNotifyUserOnPersonalModifications: (BOOL) b -{ - [calendar setNotifyUserOnPersonalModifications: b]; -} - -- (NSString *) notifiedUserOnPersonalModifications -{ - return [calendar notifiedUserOnPersonalModifications]; -} - -- (void) setNotifiedUserOnPersonalModifications: (NSString *) theUser -{ - [calendar setNotifiedUserOnPersonalModifications: theUser]; + return [self responseWith204]; } @end diff --git a/UI/Scheduler/product.plist b/UI/Scheduler/product.plist index 1ab6737b5..d684b659d 100644 --- a/UI/Scheduler/product.plist +++ b/UI/Scheduler/product.plist @@ -150,7 +150,7 @@ protectedBy = "Access Contents Information"; pageName = "UIxCalendarProperties"; }; - saveProperties = { + save = { protectedBy = "Access Contents Information"; pageName = "UIxCalendarProperties"; actionName = "saveProperties";