2008-05-03 01:08:15 +02:00
|
|
|
/* SOGoUserFolder+Appointments.m - this file is part of SOGo
|
|
|
|
*
|
2009-12-19 23:50:40 +01:00
|
|
|
* Copyright (C) 2008-2009 Inverse inc.
|
2008-05-03 01:08:15 +02:00
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Foundation/NSArray.h>
|
2008-07-10 23:30:56 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2008-07-04 18:06:09 +02:00
|
|
|
#import <Foundation/NSEnumerator.h>
|
2010-01-19 13:28:10 +01:00
|
|
|
#import <Foundation/NSValue.h>
|
2008-07-04 18:06:09 +02:00
|
|
|
|
2008-05-03 01:08:15 +02:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
2008-07-10 23:30:56 +02:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
|
|
|
#import <NGExtensions/NSString+misc.h>
|
2010-01-15 00:19:19 +01:00
|
|
|
#import <DOM/DOMProtocols.h>
|
2008-07-10 23:30:56 +02:00
|
|
|
#import <SaxObjC/XMLNamespaces.h>
|
2008-05-03 01:08:15 +02:00
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
#import <SOGo/NSArray+Utilities.h>
|
2008-07-10 23:30:56 +02:00
|
|
|
#import <SOGo/NSObject+DAV.h>
|
|
|
|
#import <SOGo/NSString+DAV.h>
|
2010-01-15 00:19:19 +01:00
|
|
|
#import <SOGo/NSObject+Utilities.h>
|
|
|
|
#import <SOGo/SOGoGCSFolder.h>
|
|
|
|
#import <SOGo/SOGoUser.h>
|
|
|
|
#import <SOGo/SOGoUserSettings.h>
|
|
|
|
#import <SOGo/WOResponse+SOGo.h>
|
2009-10-21 23:17:11 +02:00
|
|
|
#import <SOGo/WORequest+SOGo.h>
|
|
|
|
|
2009-08-27 23:14:54 +02:00
|
|
|
#import "SOGoAppointmentFolders.h"
|
2008-05-03 01:08:15 +02:00
|
|
|
#import "SOGoUserFolder+Appointments.h"
|
|
|
|
|
2008-07-04 18:06:09 +02:00
|
|
|
@interface SOGoUserFolder (private)
|
|
|
|
|
|
|
|
- (SOGoAppointmentFolders *) privateCalendars: (NSString *) key
|
|
|
|
inContext: (WOContext *) localContext;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2008-05-03 01:08:15 +02:00
|
|
|
@implementation SOGoUserFolder (SOGoCalDAVSupport)
|
|
|
|
|
|
|
|
- (NSArray *) davCalendarUserAddressSet
|
|
|
|
{
|
2008-08-07 15:31:55 +02:00
|
|
|
NSArray *tag;
|
2008-05-03 01:08:15 +02:00
|
|
|
NSMutableArray *addresses;
|
|
|
|
NSEnumerator *emails;
|
|
|
|
NSString *currentEmail;
|
2008-08-07 15:31:55 +02:00
|
|
|
SOGoUser *ownerUser;
|
2008-05-03 01:08:15 +02:00
|
|
|
|
|
|
|
addresses = [NSMutableArray array];
|
|
|
|
|
2009-08-25 23:28:24 +02:00
|
|
|
ownerUser = [SOGoUser userWithLogin: owner];
|
2008-08-07 15:31:55 +02:00
|
|
|
emails = [[ownerUser allEmails] objectEnumerator];
|
2008-05-03 01:08:15 +02:00
|
|
|
while ((currentEmail = [emails nextObject]))
|
|
|
|
{
|
2010-01-21 00:09:35 +01:00
|
|
|
tag = [NSArray arrayWithObjects: @"href", XMLNS_WEBDAV, @"D",
|
2009-07-14 16:36:15 +02:00
|
|
|
[NSString stringWithFormat: @"mailto:%@", currentEmail],
|
2008-05-03 01:08:15 +02:00
|
|
|
nil];
|
|
|
|
[addresses addObject: tag];
|
|
|
|
}
|
|
|
|
|
|
|
|
return addresses;
|
|
|
|
}
|
|
|
|
|
2008-06-30 20:54:55 +02:00
|
|
|
/* CalDAV support */
|
|
|
|
- (NSArray *) davCalendarHomeSet
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
<C:calendar-home-set xmlns:D="DAV:"
|
|
|
|
xmlns:C="urn:ietf:params:xml:ns:caldav">
|
|
|
|
<D:href>http://cal.example.com/home/bernard/calendars/</D:href>
|
|
|
|
</C:calendar-home-set>
|
|
|
|
|
|
|
|
Note: this is the *container* for calendar collections, not the
|
|
|
|
collections itself. So for use its the home folder, the
|
|
|
|
public folder and the groups folder.
|
|
|
|
*/
|
|
|
|
NSArray *tag;
|
|
|
|
SOGoAppointmentFolders *parent;
|
|
|
|
|
|
|
|
parent = [self privateCalendars: @"Calendar" inContext: context];
|
2010-01-21 00:09:35 +01:00
|
|
|
tag = [NSArray arrayWithObjects: @"href", XMLNS_WEBDAV, @"D",
|
2009-10-21 23:17:11 +02:00
|
|
|
[parent davURLAsString], nil];
|
2008-06-30 20:54:55 +02:00
|
|
|
|
|
|
|
return [NSArray arrayWithObject: tag];
|
|
|
|
}
|
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
- (NSArray *) _davSpecialCalendarURLWithName: (NSString *) name
|
2008-06-30 20:54:55 +02:00
|
|
|
{
|
|
|
|
SOGoAppointmentFolders *parent;
|
2010-01-15 00:19:19 +01:00
|
|
|
NSArray *tag, *response;
|
2010-01-21 00:09:35 +01:00
|
|
|
NSString *parentURL;
|
2008-06-30 20:54:55 +02:00
|
|
|
|
2010-01-21 00:09:35 +01:00
|
|
|
parent = [self privateCalendars: @"Calendar" inContext: context];
|
|
|
|
parentURL = [parent davURLAsString];
|
|
|
|
tag = [NSArray arrayWithObjects: @"href", XMLNS_WEBDAV, @"D",
|
|
|
|
[NSString stringWithFormat: @"%@%@/", parentURL, name],
|
|
|
|
nil];
|
|
|
|
response = [NSArray arrayWithObject: tag];
|
2008-05-03 01:08:15 +02:00
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
return response;
|
2008-06-30 20:54:55 +02:00
|
|
|
}
|
|
|
|
|
2009-07-22 15:22:48 +02:00
|
|
|
- (NSArray *) davCalendarScheduleInboxURL
|
2008-06-30 20:54:55 +02:00
|
|
|
{
|
2010-01-15 00:19:19 +01:00
|
|
|
return [self _davSpecialCalendarURLWithName: @"inbox"];
|
2008-06-30 20:54:55 +02:00
|
|
|
}
|
|
|
|
|
2009-07-22 15:22:48 +02:00
|
|
|
- (NSArray *) davCalendarScheduleOutboxURL
|
2008-06-30 20:54:55 +02:00
|
|
|
{
|
2010-01-15 00:19:19 +01:00
|
|
|
return [self _davSpecialCalendarURLWithName: @"personal"];
|
2008-06-30 20:54:55 +02:00
|
|
|
}
|
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
- (NSArray *) _calendarProxiedUsersWithWriteAccess: (BOOL) write
|
2008-06-30 20:54:55 +02:00
|
|
|
{
|
2010-01-19 13:28:10 +01:00
|
|
|
NSMutableDictionary *proxiedUsers;
|
|
|
|
NSArray *references, *elements;
|
|
|
|
NSString *currentLogin;
|
|
|
|
NSNumber *yesNumber;
|
|
|
|
SOGoAppointmentFolders *parentFolder;
|
|
|
|
SOGoUserSettings *us;
|
2010-01-15 00:19:19 +01:00
|
|
|
int count, max;
|
|
|
|
|
2010-01-19 13:28:10 +01:00
|
|
|
yesNumber = [NSNumber numberWithBool: YES];
|
|
|
|
|
|
|
|
us = [[SOGoUser userWithLogin: owner] userSettings];
|
|
|
|
references = [us subscribedCalendars];
|
|
|
|
max = [references count];
|
|
|
|
proxiedUsers = [NSMutableDictionary dictionaryWithCapacity: max];
|
2010-01-15 00:19:19 +01:00
|
|
|
for (count = 0; count < max; count++)
|
2008-07-10 23:30:56 +02:00
|
|
|
{
|
2010-01-19 13:28:10 +01:00
|
|
|
elements = [[references objectAtIndex: count]
|
|
|
|
componentsSeparatedByString: @":"];
|
|
|
|
if ([elements count])
|
|
|
|
{
|
|
|
|
currentLogin = [elements objectAtIndex: 0];
|
|
|
|
if (![proxiedUsers objectForKey: currentLogin])
|
|
|
|
{
|
|
|
|
parentFolder = [[container lookupName: currentLogin
|
|
|
|
inContext: context
|
|
|
|
acquire: NO]
|
|
|
|
lookupName: @"Calendar"
|
|
|
|
inContext: context acquire: NO];
|
|
|
|
if ([parentFolder hasProxyCalendarsWithWriteAccess: write
|
|
|
|
forUserWithLogin: owner])
|
|
|
|
[proxiedUsers setObject: yesNumber forKey: currentLogin];
|
|
|
|
}
|
|
|
|
}
|
2008-07-10 23:30:56 +02:00
|
|
|
}
|
|
|
|
|
2010-01-19 13:28:10 +01:00
|
|
|
return [proxiedUsers allKeys];
|
2008-07-10 23:30:56 +02:00
|
|
|
}
|
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
- (void) _addGroupMembershipToArray: (NSMutableArray *) groups
|
|
|
|
forWriteAccess: (BOOL) write
|
2008-07-10 23:30:56 +02:00
|
|
|
{
|
2010-01-15 00:19:19 +01:00
|
|
|
NSArray *proxiedUsers, *tag;
|
|
|
|
NSString *appName, *groupId, *proxiedUser;
|
|
|
|
int count, max;
|
2008-07-10 23:30:56 +02:00
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
proxiedUsers = [self _calendarProxiedUsersWithWriteAccess: write];
|
|
|
|
max = [proxiedUsers count];
|
|
|
|
if (max)
|
2008-07-10 23:30:56 +02:00
|
|
|
{
|
2010-01-15 00:19:19 +01:00
|
|
|
appName = [[context request] applicationName];
|
|
|
|
groupId = [NSString stringWithFormat: @"calendar-proxy-%@",
|
|
|
|
(write ? @"write" : @"read")];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
proxiedUser = [proxiedUsers objectAtIndex: count];
|
2010-01-21 00:09:35 +01:00
|
|
|
tag = [NSArray arrayWithObjects: @"href", XMLNS_WEBDAV, @"D",
|
2010-01-15 00:19:19 +01:00
|
|
|
[NSString stringWithFormat: @"/%@/dav/%@/%@/",
|
|
|
|
appName, proxiedUser, groupId],
|
|
|
|
nil];
|
|
|
|
[groups addObject: tag];
|
|
|
|
}
|
2008-07-10 23:30:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
- (NSArray *) davGroupMembership
|
2008-07-10 23:30:56 +02:00
|
|
|
{
|
2010-01-15 00:19:19 +01:00
|
|
|
NSMutableArray *groups;
|
2008-07-10 23:30:56 +02:00
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
groups = [NSMutableArray array];
|
2008-07-10 23:30:56 +02:00
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
[self _addGroupMembershipToArray: groups
|
|
|
|
forWriteAccess: YES];
|
|
|
|
[self _addGroupMembershipToArray: groups
|
|
|
|
forWriteAccess: NO];
|
2008-07-10 23:30:56 +02:00
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
return groups;
|
2008-07-10 23:30:56 +02:00
|
|
|
}
|
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
- (NSMutableArray *) _davCalendarProxyForWrite: (BOOL) write
|
2008-07-10 23:30:56 +02:00
|
|
|
{
|
2010-01-15 00:19:19 +01:00
|
|
|
NSMutableArray *proxyFor;
|
|
|
|
NSArray *proxiedUsers, *tag;
|
|
|
|
NSString *appName, *proxiedUser;
|
|
|
|
int count, max;
|
2008-07-10 23:30:56 +02:00
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
appName = [[context request] applicationName];
|
2008-07-10 23:30:56 +02:00
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
proxiedUsers = [self _calendarProxiedUsersWithWriteAccess: write];
|
|
|
|
max = [proxiedUsers count];
|
|
|
|
proxyFor = [NSMutableArray arrayWithCapacity: max];
|
|
|
|
if (max)
|
2008-07-10 23:30:56 +02:00
|
|
|
{
|
2010-01-15 00:19:19 +01:00
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
proxiedUser = [proxiedUsers objectAtIndex: count];
|
2010-01-21 00:09:35 +01:00
|
|
|
tag = [NSArray arrayWithObjects: @"href", XMLNS_WEBDAV, @"D",
|
2010-01-15 00:19:19 +01:00
|
|
|
[NSString stringWithFormat: @"/%@/dav/%@/",
|
|
|
|
appName, proxiedUser],
|
|
|
|
nil];
|
|
|
|
[proxyFor addObject: tag];
|
|
|
|
}
|
2008-07-10 23:30:56 +02:00
|
|
|
}
|
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
return proxyFor;
|
2008-07-10 23:30:56 +02:00
|
|
|
}
|
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
- (NSArray *) davCalendarProxyWriteFor
|
2008-07-10 23:30:56 +02:00
|
|
|
{
|
2010-01-15 00:19:19 +01:00
|
|
|
return [self _davCalendarProxyForWrite: YES];
|
2008-07-10 23:30:56 +02:00
|
|
|
}
|
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
- (NSArray *) davCalendarProxyReadFor
|
2009-08-27 23:14:54 +02:00
|
|
|
{
|
2010-01-15 00:19:19 +01:00
|
|
|
return [self _davCalendarProxyForWrite: NO];
|
2009-08-27 23:14:54 +02:00
|
|
|
}
|
|
|
|
|
2008-05-03 01:08:15 +02:00
|
|
|
@end
|