JSONify [UIxCalendarProperties saveAction]

pull/91/head
Francis Lachapelle 2015-01-26 15:45:42 -05:00
parent c934b3d9c0
commit 80785304f1
5 changed files with 164 additions and 254 deletions

View File

@ -65,6 +65,7 @@ typedef enum {
NSMutableDictionary *uidToFilename; NSMutableDictionary *uidToFilename;
NSMutableDictionary *aclMatrix; NSMutableDictionary *aclMatrix;
NSMutableArray *stripFields; NSMutableArray *stripFields;
NSString *baseCalDAVURL, *basePublicCalDAVURL;
int davCalendarStartTimeLimit; int davCalendarStartTimeLimit;
int davTimeLimitSeconds; int davTimeLimitSeconds;
int davTimeHalfLimitSeconds; int davTimeHalfLimitSeconds;
@ -73,6 +74,7 @@ typedef enum {
} }
- (BOOL) isActive; - (BOOL) isActive;
- (BOOL) isWebCalendar;
- (NSString *) calendarColor; - (NSString *) calendarColor;
- (void) setCalendarColor: (NSString *) newColor; - (void) setCalendarColor: (NSString *) newColor;
@ -129,6 +131,13 @@ typedef enum {
- (NSString *) baseURLForAptWithUID: (NSString *) _uid - (NSString *) baseURLForAptWithUID: (NSString *) _uid
inContext: (id) _ctx; inContext: (id) _ctx;
- (NSString *) calDavURL;
- (NSString *) webDavICSURL;
- (NSString *) webDavXMLURL;
- (NSString *) publicCalDavURL;
- (NSString *) publicWebDavICSURL;
- (NSString *) publicWebDavXMLURL;
/* folder management */ /* folder management */
- (id) lookupHomeFolderForUID: (NSString *) _uid - (id) lookupHomeFolderForUID: (NSString *) _uid

View File

@ -84,6 +84,7 @@
#import "SOGoAppointmentFolders.h" #import "SOGoAppointmentFolders.h"
#import "SOGoFreeBusyObject.h" #import "SOGoFreeBusyObject.h"
#import "SOGoTaskObject.h" #import "SOGoTaskObject.h"
#import "SOGoWebAppointmentFolder.h";
#import "SOGoAppointmentFolder.h" #import "SOGoAppointmentFolder.h"
@ -332,13 +333,15 @@ static Class iCalEventK = nil;
memset (userCanAccessObjectsClassifiedAs, NO, memset (userCanAccessObjectsClassifiedAs, NO,
iCalAccessClassCount * sizeof (BOOL)); iCalAccessClassCount * sizeof (BOOL));
davCalendarStartTimeLimit davCalendarStartTimeLimit = [[user domainDefaults] davCalendarStartTimeLimit];
= [[user domainDefaults] davCalendarStartTimeLimit];
davTimeLimitSeconds = davCalendarStartTimeLimit * 86400; davTimeLimitSeconds = davCalendarStartTimeLimit * 86400;
/* 86400 / 2 = 43200. We hardcode that value in order to avoid /* 86400 / 2 = 43200. We hardcode that value in order to avoid
integer and float confusion. */ integer and float confusion. */
davTimeHalfLimitSeconds = davCalendarStartTimeLimit * 43200; davTimeHalfLimitSeconds = davCalendarStartTimeLimit * 43200;
componentSet = nil; componentSet = nil;
baseCalDAVURL = nil;
basePublicCalDAVURL = nil;
} }
return self; return self;
@ -350,6 +353,8 @@ static Class iCalEventK = nil;
[stripFields release]; [stripFields release];
[uidToFilename release]; [uidToFilename release];
[componentSet release]; [componentSet release];
[baseCalDAVURL release];
[basePublicCalDAVURL release];
[super dealloc]; [super dealloc];
} }
@ -2869,6 +2874,70 @@ firstInstanceCalendarDateRange: (NGCalendarDateRange *) fir
return [url stringByAppendingString:_uid]; 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 */ /* folder management */
- (BOOL) create - (BOOL) create
{ {
@ -3132,6 +3201,11 @@ firstInstanceCalendarDateRange: (NGCalendarDateRange *) fir
return (![inactiveFolders containsObject: nameInContainer]); return (![inactiveFolders containsObject: nameInContainer]);
} }
- (BOOL) isWebCalendar
{
return ([self isKindOfClass: [SOGoWebAppointmentFolder class]]);
}
- (NSString *) importComponent: (iCalEntityObject *) event - (NSString *) importComponent: (iCalEntityObject *) event
timezone: (iCalTimeZone *) timezone timezone: (iCalTimeZone *) timezone
{ {

View File

@ -1,6 +1,6 @@
/* UIxCalendarProperties.m - this file is part of SOGo /* 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 * 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 * it under the terms of the GNU General Public License as published by
@ -27,36 +27,11 @@
@interface UIxCalendarProperties : UIxComponent @interface UIxCalendarProperties : UIxComponent
{ {
SOGoAppointmentFolder *calendar; 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 *) originalCalendarSyncTag;
- (NSString *) allCalendarSyncTags; - (NSString *) allCalendarSyncTags;
- (BOOL) mustSynchronize; - (BOOL) mustSynchronize;
- (NSString *) calendarSyncTag;
- (void) setCalendarSyncTag: (NSString *) newTag; - (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 @end

View File

@ -1,6 +1,6 @@
/* UIxCalendarProperties.m - this file is part of SOGo /* 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 * 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 * it under the terms of the GNU General Public License as published by
@ -21,12 +21,15 @@
#import <Foundation/NSDictionary.h> #import <Foundation/NSDictionary.h>
#import <Foundation/NSEnumerator.h> #import <Foundation/NSEnumerator.h>
#import <Foundation/NSURL.h> #import <Foundation/NSURL.h>
#import <Foundation/NSValue.h>
#import <NGObjWeb/WORequest.h> #import <NGObjWeb/WORequest.h>
#import <SOGo/NSString+Utilities.h>
#import <SOGo/SOGoUser.h> #import <SOGo/SOGoUser.h>
#import <SOGo/SOGoUserSettings.h> #import <SOGo/SOGoUserSettings.h>
#import <SOGo/SOGoSystemDefaults.h> #import <SOGo/SOGoSystemDefaults.h>
#import <Appointments/SOGoAppointmentFolder.h> #import <Appointments/SOGoAppointmentFolder.h>
#import <Appointments/SOGoWebAppointmentFolder.h> #import <Appointments/SOGoWebAppointmentFolder.h>
@ -39,9 +42,6 @@
if ((self = [super init])) if ((self = [super init]))
{ {
calendar = [self clientObject]; calendar = [self clientObject];
baseCalDAVURL = nil;
basePublicCalDAVURL = nil;
reloadTasks = NO;
} }
return self; return self;
@ -49,56 +49,9 @@
- (void) dealloc - (void) dealloc
{ {
[baseCalDAVURL release];
[basePublicCalDAVURL release];
[super dealloc]; [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 - (NSString *) originalCalendarSyncTag
{ {
return [calendar syncTag]; return [calendar syncTag];
@ -144,199 +97,98 @@
return [[calendar nameInContainer] isEqualToString: @"personal"]; return [[calendar nameInContainer] isEqualToString: @"personal"];
} }
- (NSString *) calendarSyncTag // - (NSString *) calendarSyncTag
{ // {
return [calendar syncTag]; // return [calendar syncTag];
} // }
- (void) setCalendarSyncTag: (NSString *) newTag - (void) setCalendarSyncTag: (NSString *) newTag
{ {
[calendar setSyncTag: 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 request = [context request];
{ params = [[request contentAsString] objectFromJSONString];
if (new != [calendar showCalendarAlarms])
reloadTasks = YES;
[calendar setShowCalendarAlarms: new];
}
- (BOOL) showCalendarTasks o = [params objectForKey: @"displayName"];
{ if ([o isKindOfClass: [NSString class]])
return [calendar showCalendarTasks]; [calendar renameTo: o];
}
- (void) setShowCalendarTasks: (BOOL) new o = [params objectForKey: @"color"];
{ if ([o isKindOfClass: [NSString class]])
if (new != [calendar showCalendarTasks]) [calendar setCalendarColor: o];
reloadTasks = YES;
[calendar setShowCalendarTasks: new];
}
- (BOOL) isPublicAccessEnabled o = [params objectForKey: @"includeInFreeBusy"];
{ if ([o isKindOfClass: [NSNumber class]])
// NOTE: This method is the same found in Common/UIxAclEditor.m [calendar setIncludeInFreeBusy: [o boolValue]];
return [[SOGoSystemDefaults sharedSystemDefaults]
enablePublicAccess];
}
- (BOOL) isWebCalendar o = [params objectForKey: @"synchronizeCalendar"];
{ if ([o isKindOfClass: [NSNumber class]])
return ([calendar isKindOfClass: [SOGoWebAppointmentFolder class]]); [calendar setSynchronizeCalendar: [self mustSynchronize] || [o boolValue]];
}
- (NSString *) webCalendarURL o = [params objectForKey: @"showCalendarAlarms"];
{ if ([o isKindOfClass: [NSNumber class]])
return [calendar folderPropertyValueInCategory: @"WebCalendars"]; [calendar setShowCalendarAlarms: [o boolValue]];
}
- (void) setReloadOnLogin: (BOOL) newReloadOnLogin o = [params objectForKey: @"showCalendarTasks"];
{ if ([o isKindOfClass: [NSNumber class]])
if ([calendar respondsToSelector: @selector (setReloadOnLogin:)]) [calendar setShowCalendarTasks: [o boolValue]];
[(SOGoWebAppointmentFolder *) calendar
setReloadOnLogin: newReloadOnLogin];
}
- (BOOL) reloadOnLogin o = [params objectForKey: @"showCalendarTasks"];
{ if ([o isKindOfClass: [NSNumber class]])
BOOL rc; [calendar setShowCalendarTasks: [o boolValue]];
if ([calendar respondsToSelector: @selector (reloadOnLogin)]) values = [params objectForKey: @"notifications"];
rc = [(SOGoWebAppointmentFolder *) calendar reloadOnLogin]; if ([values isKindOfClass: [NSDictionary class]])
else
rc = NO;
return rc;
}
- (BOOL) shouldTakeValuesFromRequest: (WORequest *) request
inContext: (WOContext*) context
{
NSString *method;
method = [[request uri] lastPathComponent];
return [method isEqualToString: @"saveProperties"];
}
- (id <WOActionResults>) savePropertiesAction
{
NSString *action;
if (reloadTasks)
action = @"refreshTasks()";
else
action = nil;
return [self jsCloseWithRefreshMethod: action];
}
- (NSString *) _baseCalDAVURL
{
NSString *davURL;
if (!baseCalDAVURL)
{ {
davURL = [[calendar realDavURL] absoluteString]; o = [values objectForKey: @"notifyOnPersonalModifications"];
if ([davURL hasSuffix: @"/"]) if ([o isKindOfClass: [NSNumber class]])
baseCalDAVURL = [davURL substringToIndex: [davURL length] - 1]; [calendar setNotifyOnPersonalModifications: [o boolValue]];
else
baseCalDAVURL = davURL; o = [values objectForKey: @"notifyOnExternalModifications"];
[baseCalDAVURL retain]; 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; return [self responseWith204];
}
- (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];
} }
@end @end

View File

@ -150,7 +150,7 @@
protectedBy = "Access Contents Information"; protectedBy = "Access Contents Information";
pageName = "UIxCalendarProperties"; pageName = "UIxCalendarProperties";
}; };
saveProperties = { save = {
protectedBy = "Access Contents Information"; protectedBy = "Access Contents Information";
pageName = "UIxCalendarProperties"; pageName = "UIxCalendarProperties";
actionName = "saveProperties"; actionName = "saveProperties";