2009-08-27 23:14:54 +02:00
|
|
|
/* SOGoCalendarProxy.m - this file is part of SOGo
|
|
|
|
*
|
2016-09-26 21:22:49 +02:00
|
|
|
* Copyright (C) 2009-2016 Inverse inc.
|
2009-08-27 23:14:54 +02:00
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
#import <Foundation/NSEnumerator.h>
|
|
|
|
#import <Foundation/NSString.h>
|
2010-01-15 00:19:19 +01:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
|
|
|
#import <NGObjWeb/WORequest.h>
|
|
|
|
#import <SaxObjC/XMLNamespaces.h>
|
2009-08-27 23:14:54 +02:00
|
|
|
#import <SOGo/NSArray+Utilities.h>
|
|
|
|
#import <SOGo/SOGoUser.h>
|
2012-10-22 16:09:13 +02:00
|
|
|
#import <SOGo/SOGoUserFolder.h>
|
2010-01-15 00:19:19 +01:00
|
|
|
#import <SOGo/SOGoUserSettings.h>
|
|
|
|
|
2011-11-30 15:51:01 +01:00
|
|
|
#import <SOGo/NSObject+DAV.h>
|
|
|
|
#import <SOGo/SOGoPermissions.h>
|
|
|
|
#import <SOGo/SOGoWebDAVAclManager.h>
|
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
#import "SOGoAppointmentFolders.h"
|
2009-08-27 23:14:54 +02:00
|
|
|
|
|
|
|
#import "SOGoCalendarProxy.h"
|
|
|
|
|
|
|
|
@implementation SOGoCalendarProxy
|
|
|
|
|
2011-11-30 15:51:01 +01:00
|
|
|
+ (SOGoWebDAVAclManager *) webdavAclManager
|
|
|
|
{
|
|
|
|
static SOGoWebDAVAclManager *aclManager = nil;
|
|
|
|
NSString *nsI;
|
|
|
|
|
|
|
|
if (!aclManager)
|
|
|
|
{
|
|
|
|
nsI = @"urn:inverse:params:xml:ns:inverse-dav";
|
|
|
|
|
|
|
|
aclManager = [SOGoWebDAVAclManager new];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"read", XMLNS_WEBDAV)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: SoPerm_WebDAVAccess
|
|
|
|
asChildOf: davElement (@"all", XMLNS_WEBDAV)];
|
|
|
|
[aclManager
|
|
|
|
registerDAVPermission: davElement (@"read-current-user-privilege-set", XMLNS_WEBDAV)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: SoPerm_WebDAVAccess
|
|
|
|
asChildOf: davElement (@"read", XMLNS_WEBDAV)];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"write", XMLNS_WEBDAV)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"all", XMLNS_WEBDAV)];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"bind", XMLNS_WEBDAV)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: SoPerm_AddDocumentsImagesAndFiles
|
|
|
|
asChildOf: davElement (@"write", XMLNS_WEBDAV)];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"unbind", XMLNS_WEBDAV)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: SoPerm_DeleteObjects
|
|
|
|
asChildOf: davElement (@"write", XMLNS_WEBDAV)];
|
|
|
|
[aclManager
|
|
|
|
registerDAVPermission: davElement (@"write-properties", XMLNS_WEBDAV)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: SoPerm_ChangePermissions /* hackish */
|
|
|
|
asChildOf: davElement (@"write", XMLNS_WEBDAV)];
|
|
|
|
[aclManager
|
|
|
|
registerDAVPermission: davElement (@"write-content", XMLNS_WEBDAV)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: SoPerm_AddDocumentsImagesAndFiles
|
|
|
|
asChildOf: davElement (@"write", XMLNS_WEBDAV)];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"admin", nsI)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"all", XMLNS_WEBDAV)];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"read-acl", XMLNS_WEBDAV)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: SOGoPerm_ReadAcls
|
|
|
|
asChildOf: davElement (@"admin", nsI)];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"write-acl", XMLNS_WEBDAV)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: SoPerm_ChangePermissions
|
|
|
|
asChildOf: davElement (@"admin", nsI)];
|
|
|
|
}
|
|
|
|
|
|
|
|
return aclManager;
|
|
|
|
}
|
|
|
|
|
2009-08-27 23:14:54 +02:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
hasWriteAccess = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setWriteAccess: (BOOL) newHasWriteAccess
|
|
|
|
{
|
|
|
|
hasWriteAccess = newHasWriteAccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) davResourceType
|
|
|
|
{
|
|
|
|
NSString *proxyType;
|
|
|
|
NSMutableArray *rType;
|
|
|
|
|
|
|
|
rType = [NSMutableArray arrayWithArray: [super davResourceType]];
|
|
|
|
[rType addObject: @"principal"];
|
|
|
|
if (hasWriteAccess)
|
|
|
|
proxyType = @"calendar-proxy-write";
|
|
|
|
else
|
|
|
|
proxyType = @"calendar-proxy-read";
|
|
|
|
[rType addObject: [NSArray arrayWithObjects: proxyType,
|
2010-01-15 00:19:19 +01:00
|
|
|
XMLNS_CalendarServerOrg, nil]];
|
2009-08-27 23:14:54 +02:00
|
|
|
|
|
|
|
return rType;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) davGroupMemberSet
|
|
|
|
{
|
|
|
|
NSMutableArray *members;
|
2010-01-19 13:28:10 +01:00
|
|
|
NSArray *proxySubscribers, *member;
|
2010-01-15 00:19:19 +01:00
|
|
|
NSString *appName, *proxyUser;
|
|
|
|
int count, max;
|
2009-08-27 23:14:54 +02:00
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
appName = [[context request] applicationName];
|
2009-08-27 23:14:54 +02:00
|
|
|
|
2010-01-19 13:28:10 +01:00
|
|
|
proxySubscribers
|
2011-11-30 15:51:01 +01:00
|
|
|
= [[[self lookupUserFolder] lookupName: @"Calendar"
|
|
|
|
inContext: context
|
|
|
|
acquire: NO]
|
2010-01-19 13:28:10 +01:00
|
|
|
proxySubscribersWithWriteAccess: hasWriteAccess];
|
|
|
|
max = [proxySubscribers count];
|
2010-01-15 00:19:19 +01:00
|
|
|
members = [NSMutableArray arrayWithCapacity: max];
|
|
|
|
for (count = 0; count < max; count++)
|
2009-08-27 23:14:54 +02:00
|
|
|
{
|
2010-01-19 13:28:10 +01:00
|
|
|
proxyUser = [proxySubscribers objectAtIndex: count];
|
2010-01-15 00:19:19 +01:00
|
|
|
member = [NSArray arrayWithObjects: @"href", XMLNS_WEBDAV, @"D",
|
|
|
|
[NSString stringWithFormat: @"/%@/dav/%@/",
|
|
|
|
appName, proxyUser],
|
2009-08-27 23:14:54 +02:00
|
|
|
nil];
|
|
|
|
[members addObject: member];
|
|
|
|
}
|
|
|
|
|
|
|
|
return members;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) _parseSubscriber: (NSString *) memberSet
|
|
|
|
until: (int) length
|
|
|
|
{
|
|
|
|
int begin, end;
|
|
|
|
NSRange beginRange;
|
|
|
|
|
|
|
|
end = length;
|
|
|
|
if ([memberSet characterAtIndex: end - 1] == '/')
|
|
|
|
end--;
|
|
|
|
beginRange = [memberSet rangeOfString: @"/"
|
|
|
|
options: NSBackwardsSearch
|
|
|
|
range: NSMakeRange (0, end)];
|
|
|
|
begin = NSMaxRange (beginRange);
|
|
|
|
|
|
|
|
return [memberSet substringWithRange: NSMakeRange (begin, end - begin)];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) _parseSubscribers: (NSString *) memberSet
|
|
|
|
{
|
|
|
|
NSRange endRange;
|
|
|
|
NSMutableArray *subscribers;
|
|
|
|
NSMutableString *mMemberSet;
|
|
|
|
NSString *subscriber;
|
|
|
|
|
|
|
|
subscribers = [NSMutableArray array];
|
|
|
|
mMemberSet = [NSMutableString stringWithString: memberSet];
|
|
|
|
|
|
|
|
endRange = [mMemberSet rangeOfString: @"</"];
|
|
|
|
while (endRange.location != NSNotFound)
|
|
|
|
{
|
|
|
|
subscriber = [self _parseSubscriber: mMemberSet
|
|
|
|
until: endRange.location];
|
|
|
|
[subscribers addObjectUniquely: subscriber];
|
|
|
|
[mMemberSet
|
|
|
|
deleteCharactersInRange: NSMakeRange (0, endRange.location + 1)];
|
|
|
|
endRange = [mMemberSet rangeOfString: @"</"];
|
|
|
|
}
|
|
|
|
|
|
|
|
return subscribers;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSException *) setDavGroupMemberSet: (NSString *) memberSet
|
|
|
|
{
|
2010-01-19 13:28:10 +01:00
|
|
|
NSMutableArray *addedSubscribers, *removedSubscribers;
|
|
|
|
NSArray *oldProxySubscribers, *newProxySubscribers;
|
2010-01-15 00:19:19 +01:00
|
|
|
SOGoAppointmentFolders *folders;
|
|
|
|
|
2011-11-30 15:51:01 +01:00
|
|
|
folders = [[self lookupUserFolder] lookupName: @"Calendar"
|
|
|
|
inContext: context
|
|
|
|
acquire: NO];
|
2010-01-19 13:28:10 +01:00
|
|
|
oldProxySubscribers
|
|
|
|
= [folders proxySubscribersWithWriteAccess: hasWriteAccess];
|
|
|
|
if (!oldProxySubscribers)
|
|
|
|
oldProxySubscribers = [NSMutableArray array];
|
|
|
|
newProxySubscribers = [self _parseSubscribers: memberSet];
|
|
|
|
if (!newProxySubscribers)
|
|
|
|
newProxySubscribers = [NSMutableArray array];
|
|
|
|
|
|
|
|
addedSubscribers = [newProxySubscribers mutableCopy];
|
|
|
|
[addedSubscribers removeObjectsInArray: oldProxySubscribers];
|
|
|
|
[addedSubscribers autorelease];
|
|
|
|
[folders addProxySubscribers: addedSubscribers
|
|
|
|
withWriteAccess: hasWriteAccess];
|
|
|
|
|
|
|
|
removedSubscribers = [oldProxySubscribers mutableCopy];
|
|
|
|
[removedSubscribers removeObjectsInArray: newProxySubscribers];
|
|
|
|
[removedSubscribers autorelease];
|
|
|
|
[folders removeProxySubscribers: removedSubscribers
|
|
|
|
withWriteAccess: hasWriteAccess];
|
2009-08-27 23:14:54 +02:00
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
return nil;
|
2009-08-27 23:14:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|