2008-02-22 22:25:34 +01:00
|
|
|
/* SOGoGCSFolder.m - this file is part of SOGo
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2005 SKYRIX Software AG
|
2008-09-27 03:13:41 +02:00
|
|
|
* Copyright (C) 2006-2008 Inverse inc.
|
2008-02-22 22:25:34 +01: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.
|
|
|
|
*/
|
|
|
|
|
2007-06-18 17:37:37 +02:00
|
|
|
#import <Foundation/NSArray.h>
|
2009-06-19 18:20:49 +02:00
|
|
|
#import <Foundation/NSAutoreleasePool.h>
|
2008-06-13 22:16:30 +02:00
|
|
|
#import <Foundation/NSCalendarDate.h>
|
2007-06-18 17:37:37 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2008-07-04 18:06:09 +02:00
|
|
|
#import <Foundation/NSEnumerator.h>
|
2007-06-18 17:37:37 +02:00
|
|
|
#import <Foundation/NSException.h>
|
2007-08-15 22:27:32 +02:00
|
|
|
#import <Foundation/NSKeyValueCoding.h>
|
2007-06-18 17:37:37 +02:00
|
|
|
#import <Foundation/NSURL.h>
|
2007-12-05 00:28:52 +01:00
|
|
|
#import <Foundation/NSUserDefaults.h>
|
2008-06-13 22:16:30 +02:00
|
|
|
#import <Foundation/NSValue.h>
|
2007-06-18 17:37:37 +02:00
|
|
|
|
2007-09-11 22:25:57 +02:00
|
|
|
#import <NGObjWeb/NSException+HTTP.h>
|
2006-12-14 22:20:13 +01:00
|
|
|
#import <NGObjWeb/SoObject.h>
|
2007-07-22 22:40:34 +02:00
|
|
|
#import <NGObjWeb/SoObject+SoDAV.h>
|
2007-07-04 22:13:49 +02:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
2007-10-14 18:07:22 +02:00
|
|
|
#import <NGObjWeb/WOApplication.h>
|
2007-12-05 00:28:52 +01:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
2008-02-22 22:25:34 +01:00
|
|
|
#import <NGExtensions/NSString+misc.h>
|
2007-06-18 17:37:37 +02:00
|
|
|
#import <NGExtensions/NSNull+misc.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
2009-06-18 22:58:46 +02:00
|
|
|
#import <DOM/DOMElement.h>
|
2008-02-25 22:59:25 +01:00
|
|
|
#import <DOM/DOMProtocols.h>
|
2009-06-08 19:49:15 +02:00
|
|
|
#import <EOControl/EOFetchSpecification.h>
|
2007-06-18 17:37:37 +02:00
|
|
|
#import <EOControl/EOQualifier.h>
|
2009-06-08 19:49:15 +02:00
|
|
|
#import <EOControl/EOSortOrdering.h>
|
2007-04-17 16:30:12 +02:00
|
|
|
#import <GDLAccess/EOAdaptorChannel.h>
|
2009-01-21 18:01:06 +01:00
|
|
|
#import <GDLAccess/EOAdaptorContext.h>
|
2007-09-15 00:01:02 +02:00
|
|
|
#import <GDLContentStore/GCSChannelManager.h>
|
2007-02-09 22:21:35 +01:00
|
|
|
#import <GDLContentStore/GCSFolderManager.h>
|
|
|
|
#import <GDLContentStore/GCSFolder.h>
|
2007-09-15 00:01:02 +02:00
|
|
|
#import <GDLContentStore/NSURL+GCS.h>
|
2007-06-05 00:38:43 +02:00
|
|
|
#import <SaxObjC/XMLNamespaces.h>
|
2007-10-14 18:07:22 +02:00
|
|
|
#import <UI/SOGoUI/SOGoFolderAdvisory.h>
|
2007-11-09 00:07:30 +01:00
|
|
|
#import "NSDictionary+Utilities.h"
|
2006-12-14 22:20:13 +01:00
|
|
|
|
2007-08-24 22:38:44 +02:00
|
|
|
#import "NSArray+Utilities.h"
|
2008-05-03 01:11:21 +02:00
|
|
|
#import "NSObject+DAV.h"
|
2007-07-22 22:40:34 +02:00
|
|
|
#import "NSString+Utilities.h"
|
2009-06-19 16:49:47 +02:00
|
|
|
#import "NSString+DAV.h"
|
2007-07-22 22:40:34 +02:00
|
|
|
|
2009-06-18 22:58:46 +02:00
|
|
|
#import "DOMNode+SOGo.h"
|
2007-09-15 01:16:48 +02:00
|
|
|
#import "SOGoContentObject.h"
|
2009-05-03 19:50:57 +02:00
|
|
|
#import "SOGoGroup.h"
|
2007-11-20 20:15:26 +01:00
|
|
|
#import "SOGoParentFolder.h"
|
2007-04-26 03:16:19 +02:00
|
|
|
#import "SOGoPermissions.h"
|
2007-07-04 22:13:49 +02:00
|
|
|
#import "SOGoUser.h"
|
2008-05-03 01:11:21 +02:00
|
|
|
#import "SOGoWebDAVAclManager.h"
|
2008-02-07 17:51:41 +01:00
|
|
|
#import "WORequest+SOGo.h"
|
2007-06-18 17:37:37 +02:00
|
|
|
|
2007-11-07 16:58:43 +01:00
|
|
|
#import "SOGoGCSFolder.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-05-22 20:35:17 +02:00
|
|
|
static NSString *defaultUserID = @"<default>";
|
2007-12-03 15:13:10 +01:00
|
|
|
static BOOL sendFolderAdvisories = NO;
|
2008-06-13 22:16:30 +02:00
|
|
|
static NSArray *childRecordFields = nil;
|
2007-05-22 20:35:17 +02:00
|
|
|
|
2007-11-07 16:58:43 +01:00
|
|
|
@implementation SOGoGCSFolder
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-05-03 01:11:21 +02:00
|
|
|
+ (SOGoWebDAVAclManager *) webdavAclManager
|
|
|
|
{
|
2008-12-15 23:27:45 +01:00
|
|
|
static SOGoWebDAVAclManager *aclManager = nil;
|
2008-05-03 01:11:21 +02:00
|
|
|
|
2008-07-29 18:36:16 +02:00
|
|
|
if (!aclManager)
|
2008-05-03 01:11:21 +02:00
|
|
|
{
|
2008-07-29 18:36:16 +02:00
|
|
|
aclManager = [SOGoWebDAVAclManager new];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"read", @"DAV:")
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: SoPerm_WebDAVAccess
|
|
|
|
asChildOf: davElement (@"all", @"DAV:")];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"read-current-user-privilege-set", @"DAV:")
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: SoPerm_WebDAVAccess
|
|
|
|
asChildOf: davElement (@"read", @"DAV:")];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"write", @"DAV:")
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"all", @"DAV:")];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"bind", @"DAV:")
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: SoPerm_AddDocumentsImagesAndFiles
|
|
|
|
asChildOf: davElement (@"write", @"DAV:")];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"unbind", @"DAV:")
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: SoPerm_DeleteObjects
|
|
|
|
asChildOf: davElement (@"write", @"DAV:")];
|
|
|
|
[aclManager
|
2008-05-03 01:11:21 +02:00
|
|
|
registerDAVPermission: davElement (@"write-properties", @"DAV:")
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: SoPerm_ChangePermissions /* hackish */
|
|
|
|
asChildOf: davElement (@"write", @"DAV:")];
|
2008-07-29 18:36:16 +02:00
|
|
|
[aclManager
|
2008-05-03 01:11:21 +02:00
|
|
|
registerDAVPermission: davElement (@"write-content", @"DAV:")
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"write", @"DAV:")];
|
2008-07-29 18:36:16 +02:00
|
|
|
[aclManager registerDAVPermission: davElement (@"admin", @"urn:inverse:params:xml:ns:inverse-dav")
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"all", @"DAV:")];
|
|
|
|
[aclManager
|
2008-05-03 01:11:21 +02:00
|
|
|
registerDAVPermission: davElement (@"read-acl", @"DAV:")
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: SOGoPerm_ReadAcls
|
|
|
|
asChildOf: davElement (@"admin", @"urn:inverse:params:xml:ns:inverse-dav")];
|
2008-07-29 18:36:16 +02:00
|
|
|
[aclManager
|
2008-05-03 01:11:21 +02:00
|
|
|
registerDAVPermission: davElement (@"write-acl", @"DAV:")
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: SoPerm_ChangePermissions
|
|
|
|
asChildOf: davElement (@"admin", @"urn:inverse:params:xml:ns:inverse-dav")];
|
|
|
|
}
|
|
|
|
|
2008-07-29 18:36:16 +02:00
|
|
|
return aclManager;
|
2008-05-03 01:11:21 +02:00
|
|
|
}
|
|
|
|
|
2007-12-03 15:13:10 +01:00
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
NSUserDefaults *ud;
|
|
|
|
|
|
|
|
ud = [NSUserDefaults standardUserDefaults];
|
2008-04-02 16:17:53 +02:00
|
|
|
|
2007-12-03 15:13:10 +01:00
|
|
|
sendFolderAdvisories = [ud boolForKey: @"SOGoFoldersSendEMailNotifications"];
|
2008-06-13 22:16:30 +02:00
|
|
|
if (!childRecordFields)
|
|
|
|
{
|
|
|
|
childRecordFields = [NSArray arrayWithObjects: @"c_name", @"c_version",
|
|
|
|
@"c_creationdate", @"c_lastmodified",
|
|
|
|
@"c_component", @"c_content", nil];
|
|
|
|
[childRecordFields retain];
|
|
|
|
}
|
2007-12-03 15:13:10 +01:00
|
|
|
}
|
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
+ (id) folderWithSubscriptionReference: (NSString *) reference
|
|
|
|
inContainer: (id) aContainer
|
2007-09-11 22:25:57 +02:00
|
|
|
{
|
|
|
|
id newFolder;
|
2007-09-15 00:01:02 +02:00
|
|
|
NSArray *elements, *pathElements;
|
2008-05-16 22:33:55 +02:00
|
|
|
NSString *path, *objectPath, *login, *currentUser, *ocsName, *folderName;
|
|
|
|
WOContext *context;
|
2007-09-15 00:01:02 +02:00
|
|
|
|
|
|
|
elements = [reference componentsSeparatedByString: @":"];
|
2007-11-08 21:35:09 +01:00
|
|
|
login = [elements objectAtIndex: 0];
|
2008-05-16 22:33:55 +02:00
|
|
|
context = [[WOApplication application] context];
|
|
|
|
currentUser = [[context activeUser] login];
|
2007-09-15 00:01:02 +02:00
|
|
|
objectPath = [elements objectAtIndex: 1];
|
|
|
|
pathElements = [objectPath componentsSeparatedByString: @"/"];
|
|
|
|
if ([pathElements count] > 1)
|
|
|
|
ocsName = [pathElements objectAtIndex: 1];
|
|
|
|
else
|
|
|
|
ocsName = @"personal";
|
2007-09-11 22:25:57 +02:00
|
|
|
|
2007-11-09 00:04:42 +01:00
|
|
|
path = [NSString stringWithFormat: @"/Users/%@/%@/%@",
|
|
|
|
login, [pathElements objectAtIndex: 0], ocsName];
|
2009-01-21 18:01:06 +01:00
|
|
|
folderName = [NSString stringWithFormat: @"%@_%@",
|
|
|
|
[login asCSSIdentifier], ocsName];
|
2007-11-09 00:04:42 +01:00
|
|
|
newFolder = [self objectWithName: folderName inContainer: aContainer];
|
|
|
|
[newFolder setOCSPath: path];
|
2007-11-08 21:35:09 +01:00
|
|
|
[newFolder setOwner: login];
|
2008-05-16 22:33:55 +02:00
|
|
|
[newFolder setIsSubscription: ![login isEqualToString: currentUser]];
|
2007-11-29 22:10:39 +01:00
|
|
|
if (![newFolder displayName])
|
|
|
|
newFolder = nil;
|
2007-09-11 22:25:57 +02:00
|
|
|
|
|
|
|
return newFolder;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-04-27 21:45:12 +02:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
ocsPath = nil;
|
|
|
|
ocsFolder = nil;
|
|
|
|
aclCache = [NSMutableDictionary new];
|
2008-06-13 22:16:30 +02:00
|
|
|
childRecords = [NSMutableDictionary new];
|
2009-06-04 02:40:21 +02:00
|
|
|
userCanAccessAllObjects = NO;
|
2007-04-27 21:45:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[ocsFolder release];
|
|
|
|
[ocsPath release];
|
|
|
|
[aclCache release];
|
2008-06-13 22:16:30 +02:00
|
|
|
[childRecords release];
|
2006-06-15 21:34:10 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* accessors */
|
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
- (void) _setDisplayNameFromRow: (NSDictionary *) row
|
|
|
|
{
|
2007-11-20 20:15:26 +01:00
|
|
|
NSString *currentLogin, *ownerLogin, *primaryDN;
|
2007-09-15 00:01:02 +02:00
|
|
|
NSDictionary *ownerIdentity;
|
2007-06-29 23:58:23 +02:00
|
|
|
|
2007-11-20 20:15:26 +01:00
|
|
|
primaryDN = [row objectForKey: @"c_foldername"];
|
2007-11-30 17:43:55 +01:00
|
|
|
if ([primaryDN length])
|
2007-09-15 00:01:02 +02:00
|
|
|
{
|
2007-11-30 17:43:55 +01:00
|
|
|
displayName = [NSMutableString new];
|
|
|
|
if ([primaryDN isEqualToString: [container defaultFolderName]])
|
|
|
|
[displayName appendString: [self labelForKey: primaryDN]];
|
|
|
|
else
|
|
|
|
[displayName appendString: primaryDN];
|
|
|
|
|
|
|
|
currentLogin = [[context activeUser] login];
|
|
|
|
ownerLogin = [self ownerInContext: context];
|
|
|
|
if (![currentLogin isEqualToString: ownerLogin])
|
|
|
|
{
|
|
|
|
ownerIdentity = [[SOGoUser userWithLogin: ownerLogin roles: nil]
|
|
|
|
primaryIdentity];
|
|
|
|
[displayName
|
|
|
|
appendString: [ownerIdentity keysWithFormat:
|
|
|
|
@" (%{fullName} <%{email}>)"]];
|
|
|
|
}
|
2007-09-15 00:01:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _fetchDisplayName
|
|
|
|
{
|
|
|
|
GCSChannelManager *cm;
|
|
|
|
EOAdaptorChannel *fc;
|
|
|
|
NSURL *folderLocation;
|
|
|
|
NSString *sql;
|
|
|
|
NSArray *attrs;
|
|
|
|
NSDictionary *row;
|
|
|
|
|
|
|
|
cm = [GCSChannelManager defaultChannelManager];
|
|
|
|
folderLocation
|
|
|
|
= [[GCSFolderManager defaultFolderManager] folderInfoLocation];
|
|
|
|
fc = [cm acquireOpenChannelForURL: folderLocation];
|
|
|
|
if (fc)
|
|
|
|
{
|
|
|
|
sql
|
|
|
|
= [NSString stringWithFormat: (@"SELECT c_foldername FROM %@"
|
|
|
|
@" WHERE c_path = '%@'"),
|
|
|
|
[folderLocation gcsTableName], ocsPath];
|
|
|
|
[fc evaluateExpressionX: sql];
|
|
|
|
attrs = [fc describeResults: NO];
|
|
|
|
row = [fc fetchAttributes: attrs withZone: NULL];
|
|
|
|
if (row)
|
|
|
|
[self _setDisplayNameFromRow: row];
|
|
|
|
[fc cancelFetch];
|
|
|
|
[cm releaseChannel: fc];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-11 22:25:57 +02:00
|
|
|
- (NSString *) displayName
|
|
|
|
{
|
2007-11-30 17:43:55 +01:00
|
|
|
if (!displayName)
|
|
|
|
[self _fetchDisplayName];
|
|
|
|
|
2007-09-11 22:25:57 +02:00
|
|
|
return displayName;
|
|
|
|
}
|
|
|
|
|
2007-11-07 16:58:43 +01:00
|
|
|
- (void) setOCSPath: (NSString *) _path
|
|
|
|
{
|
|
|
|
if (![ocsPath isEqualToString:_path])
|
|
|
|
{
|
|
|
|
if (ocsPath)
|
|
|
|
[self warnWithFormat: @"GCS path is already set! '%@'", _path];
|
|
|
|
ASSIGN (ocsPath, _path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) ocsPath
|
|
|
|
{
|
|
|
|
return ocsPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (GCSFolderManager *) folderManager
|
|
|
|
{
|
|
|
|
static GCSFolderManager *folderManager = nil;
|
|
|
|
|
|
|
|
if (!folderManager)
|
|
|
|
folderManager = [GCSFolderManager defaultFolderManager];
|
|
|
|
|
|
|
|
return folderManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (GCSFolder *) ocsFolderForPath: (NSString *) _path
|
|
|
|
{
|
|
|
|
return [[self folderManager] folderAtPath: _path];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) folderIsMandatory
|
|
|
|
{
|
|
|
|
return [nameInContainer isEqualToString: @"personal"];
|
|
|
|
}
|
|
|
|
|
2008-04-22 01:03:48 +02:00
|
|
|
- (NSString *) folderReference
|
|
|
|
{
|
2008-05-16 22:33:55 +02:00
|
|
|
return [NSString stringWithFormat: @"%@:%@/%@",
|
|
|
|
owner,
|
|
|
|
[container nameInContainer],
|
|
|
|
[self realNameInContainer]];
|
|
|
|
}
|
2008-04-22 01:03:48 +02:00
|
|
|
|
2008-05-16 22:33:55 +02:00
|
|
|
- (NSArray *) pathArrayToFolder
|
|
|
|
{
|
|
|
|
NSArray *basePathElements;
|
|
|
|
unsigned int max;
|
2008-04-22 01:03:48 +02:00
|
|
|
|
2008-05-16 22:33:55 +02:00
|
|
|
basePathElements = [[self ocsPath] componentsSeparatedByString: @"/"];
|
|
|
|
max = [basePathElements count];
|
2008-04-22 01:03:48 +02:00
|
|
|
|
2008-05-16 22:33:55 +02:00
|
|
|
return [basePathElements subarrayWithRange: NSMakeRange (2, max - 2)];
|
2008-04-22 01:03:48 +02:00
|
|
|
}
|
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
- (NSString *) davDisplayName
|
|
|
|
{
|
|
|
|
return [self displayName];
|
|
|
|
}
|
|
|
|
|
2008-04-22 01:03:48 +02:00
|
|
|
- (NSException *) setDavDisplayName: (NSString *) newName
|
|
|
|
{
|
|
|
|
NSException *error;
|
2008-04-22 16:50:40 +02:00
|
|
|
NSArray *currentRoles;
|
2008-04-22 01:03:48 +02:00
|
|
|
|
2008-04-22 16:50:40 +02:00
|
|
|
currentRoles = [[context activeUser] rolesForObject: self
|
|
|
|
inContext: context];
|
|
|
|
if ([currentRoles containsObject: SoRole_Owner])
|
2008-04-22 01:03:48 +02:00
|
|
|
{
|
2008-04-22 16:50:40 +02:00
|
|
|
if ([newName length])
|
|
|
|
{
|
|
|
|
[self renameTo: newName];
|
|
|
|
error = nil;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
error = [NSException exceptionWithHTTPStatus: 400
|
2008-05-03 01:11:21 +02:00
|
|
|
reason: @"Empty string"];
|
2008-04-22 01:03:48 +02:00
|
|
|
}
|
|
|
|
else
|
2008-04-22 16:50:40 +02:00
|
|
|
error = [NSException exceptionWithHTTPStatus: 403
|
|
|
|
reason: @"Modification denied."];
|
2008-04-22 01:03:48 +02:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2007-04-27 21:45:12 +02:00
|
|
|
- (GCSFolder *) ocsFolder
|
|
|
|
{
|
2006-09-29 20:26:29 +02:00
|
|
|
GCSFolder *folder;
|
2007-07-04 22:13:49 +02:00
|
|
|
NSString *userLogin;
|
2006-09-29 20:26:29 +02:00
|
|
|
|
|
|
|
if (!ocsFolder)
|
2007-06-29 23:58:23 +02:00
|
|
|
{
|
|
|
|
ocsFolder = [self ocsFolderForPath: [self ocsPath]];
|
2007-07-04 22:13:49 +02:00
|
|
|
userLogin = [[context activeUser] login];
|
2007-06-29 23:58:23 +02:00
|
|
|
if (!ocsFolder
|
2007-11-07 16:58:43 +01:00
|
|
|
&& [userLogin isEqualToString: [self ownerInContext: context]]
|
2007-06-29 23:58:23 +02:00
|
|
|
&& [self folderIsMandatory]
|
|
|
|
&& [self create])
|
|
|
|
ocsFolder = [self ocsFolderForPath: [self ocsPath]];
|
|
|
|
[ocsFolder retain];
|
|
|
|
}
|
2006-09-29 20:26:29 +02:00
|
|
|
|
|
|
|
if ([ocsFolder isNotNull])
|
|
|
|
folder = ocsFolder;
|
|
|
|
else
|
|
|
|
folder = nil;
|
|
|
|
|
|
|
|
return folder;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-10-14 18:07:22 +02:00
|
|
|
- (void) sendFolderAdvisoryTemplate: (NSString *) template
|
|
|
|
{
|
2007-10-22 23:52:13 +02:00
|
|
|
NSString *pageName;
|
2007-10-14 18:07:22 +02:00
|
|
|
SOGoUser *user;
|
|
|
|
SOGoFolderAdvisory *page;
|
|
|
|
|
2009-01-09 18:32:30 +01:00
|
|
|
if (sendFolderAdvisories)
|
|
|
|
{
|
|
|
|
user = [context activeUser];
|
|
|
|
pageName = [NSString stringWithFormat: @"SOGoFolder%@%@Advisory",
|
|
|
|
[user language], template];
|
|
|
|
|
|
|
|
page = [[WOApplication application] pageWithName: pageName
|
|
|
|
inContext: context];
|
|
|
|
[page setFolderObject: self];
|
|
|
|
[page setRecipientUID: [user login]];
|
|
|
|
[page send];
|
|
|
|
}
|
2007-10-14 18:07:22 +02:00
|
|
|
}
|
|
|
|
|
2007-02-09 22:21:35 +01:00
|
|
|
- (BOOL) create
|
|
|
|
{
|
|
|
|
NSException *result;
|
|
|
|
result = [[self folderManager] createFolderOfType: [self folderType]
|
2007-09-15 00:01:02 +02:00
|
|
|
withName: displayName
|
2007-02-09 22:21:35 +01:00
|
|
|
atPath: ocsPath];
|
|
|
|
|
2008-02-06 17:20:59 +01:00
|
|
|
if (!result
|
2009-01-09 18:32:30 +01:00
|
|
|
&& [[context request] handledByDefaultHandler])
|
2008-02-06 17:20:59 +01:00
|
|
|
[self sendFolderAdvisoryTemplate: @"Addition"];
|
2007-12-03 15:13:10 +01:00
|
|
|
|
2007-02-09 22:21:35 +01:00
|
|
|
return (result == nil);
|
|
|
|
}
|
|
|
|
|
2007-03-21 15:27:04 +01:00
|
|
|
- (NSException *) delete
|
|
|
|
{
|
2007-09-11 22:25:57 +02:00
|
|
|
NSException *error;
|
|
|
|
|
2007-10-14 18:07:22 +02:00
|
|
|
// We just fetch our displayName since our table will use it!
|
|
|
|
[self displayName];
|
|
|
|
|
2007-09-11 22:25:57 +02:00
|
|
|
if ([nameInContainer isEqualToString: @"personal"])
|
|
|
|
error = [NSException exceptionWithHTTPStatus: 403
|
2007-09-15 00:01:02 +02:00
|
|
|
reason: @"folder 'personal' cannot be deleted"];
|
2007-09-11 22:25:57 +02:00
|
|
|
else
|
|
|
|
error = [[self folderManager] deleteFolderAtPath: ocsPath];
|
|
|
|
|
2009-01-09 18:32:30 +01:00
|
|
|
if (!error && [[context request] handledByDefaultHandler])
|
2008-02-06 17:20:59 +01:00
|
|
|
[self sendFolderAdvisoryTemplate: @"Removal"];
|
2007-12-03 15:13:10 +01:00
|
|
|
|
2007-09-11 22:25:57 +02:00
|
|
|
return error;
|
2007-03-21 15:27:04 +01:00
|
|
|
}
|
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
- (void) renameTo: (NSString *) newName
|
|
|
|
{
|
|
|
|
GCSChannelManager *cm;
|
|
|
|
EOAdaptorChannel *fc;
|
|
|
|
NSURL *folderLocation;
|
|
|
|
NSString *sql;
|
|
|
|
|
|
|
|
[displayName release];
|
|
|
|
displayName = nil;
|
|
|
|
|
|
|
|
cm = [GCSChannelManager defaultChannelManager];
|
|
|
|
folderLocation
|
|
|
|
= [[GCSFolderManager defaultFolderManager] folderInfoLocation];
|
|
|
|
fc = [cm acquireOpenChannelForURL: folderLocation];
|
|
|
|
if (fc)
|
|
|
|
{
|
|
|
|
sql
|
|
|
|
= [NSString stringWithFormat: (@"UPDATE %@ SET c_foldername = '%@'"
|
|
|
|
@" WHERE c_path = '%@'"),
|
2008-11-26 13:20:26 +01:00
|
|
|
[folderLocation gcsTableName],
|
|
|
|
[newName stringByReplacingString: @"'" withString: @"''"],
|
|
|
|
ocsPath];
|
2007-09-15 00:01:02 +02:00
|
|
|
[fc evaluateExpressionX: sql];
|
|
|
|
[cm releaseChannel: fc];
|
|
|
|
// sql = [sql stringByAppendingFormat:@" WHERE %@ = '%@'",
|
|
|
|
// uidColumnName, [self uid]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-29 23:58:23 +02:00
|
|
|
- (NSArray *) fetchContentObjectNames
|
|
|
|
{
|
2008-06-13 22:16:30 +02:00
|
|
|
NSArray *records, *names;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-06-13 22:16:30 +02:00
|
|
|
records = [[self ocsFolder] fetchFields: childRecordFields
|
|
|
|
matchingQualifier:nil];
|
2007-06-29 23:58:23 +02:00
|
|
|
if (![records isNotNull])
|
|
|
|
{
|
|
|
|
[self errorWithFormat: @"(%s): fetch failed!", __PRETTY_FUNCTION__];
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
if ([records isKindOfClass: [NSException class]])
|
2006-06-15 21:34:10 +02:00
|
|
|
return records;
|
2008-02-12 16:48:53 +01:00
|
|
|
|
2008-06-13 22:16:30 +02:00
|
|
|
[childRecords release];
|
2008-10-23 17:35:20 +02:00
|
|
|
names = [records objectsForKey: @"c_name" notFoundMarker: nil];
|
2008-06-13 22:16:30 +02:00
|
|
|
childRecords = [[NSMutableDictionary alloc] initWithObjects: records
|
|
|
|
forKeys: names];
|
|
|
|
|
|
|
|
return names;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-08-09 23:32:39 +02:00
|
|
|
|
2008-06-13 22:16:30 +02:00
|
|
|
- (NSDictionary *) _recordForObjectName: (NSString *) objectName
|
2007-02-21 22:11:40 +01:00
|
|
|
{
|
2008-06-13 22:16:30 +02:00
|
|
|
NSArray *records;
|
2007-02-21 22:11:40 +01:00
|
|
|
EOQualifier *qualifier;
|
2008-06-13 22:16:30 +02:00
|
|
|
NSDictionary *record;
|
2007-02-21 22:11:40 +01:00
|
|
|
|
|
|
|
qualifier
|
|
|
|
= [EOQualifier qualifierWithQualifierFormat:
|
|
|
|
[NSString stringWithFormat: @"c_name='%@'", objectName]];
|
|
|
|
|
2008-06-13 22:16:30 +02:00
|
|
|
records = [[self ocsFolder] fetchFields: childRecordFields
|
2007-02-21 22:11:40 +01:00
|
|
|
matchingQualifier: qualifier];
|
2008-06-13 22:16:30 +02:00
|
|
|
if (![records isKindOfClass: [NSException class]]
|
|
|
|
&& [records count])
|
|
|
|
record = [records objectAtIndex: 0];
|
|
|
|
else
|
|
|
|
record = nil;
|
|
|
|
|
|
|
|
return record;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) nameExistsInFolder: (NSString *) objectName
|
|
|
|
{
|
|
|
|
NSDictionary *record;
|
|
|
|
|
|
|
|
record = [self _recordForObjectName: objectName];
|
|
|
|
|
|
|
|
return (record != nil);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (Class) objectClassForComponentName: (NSString *) componentName
|
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
|
|
|
return Nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (Class) objectClassForContent: (NSString *) content
|
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
|
|
|
return Nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) _createChildComponentWithRecord: (NSDictionary *) record
|
|
|
|
{
|
|
|
|
Class klazz;
|
|
|
|
|
|
|
|
klazz = [self objectClassForComponentName:
|
|
|
|
[record objectForKey: @"c_component"]];
|
|
|
|
|
|
|
|
return [klazz objectWithRecord: record inContainer: self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) _createChildComponentWithName: (NSString *) newName
|
|
|
|
andContent: (NSString *) newContent
|
|
|
|
{
|
|
|
|
Class klazz;
|
|
|
|
NSDictionary *record;
|
|
|
|
unsigned int now;
|
|
|
|
NSNumber *nowNumber;
|
|
|
|
|
|
|
|
klazz = [self objectClassForContent: newContent];
|
|
|
|
now = [[NSCalendarDate calendarDate] timeIntervalSince1970];
|
|
|
|
nowNumber = [NSNumber numberWithUnsignedInt: now];
|
|
|
|
record = [NSDictionary dictionaryWithObjectsAndKeys: newName, @"c_name",
|
|
|
|
newContent, @"c_content",
|
|
|
|
nowNumber, @"c_creationdate",
|
|
|
|
nowNumber, @"c_lastmodified", nil];
|
|
|
|
|
|
|
|
return [klazz objectWithRecord: record inContainer: self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) lookupName: (NSString *) key
|
|
|
|
inContext: (WOContext *) localContext
|
|
|
|
acquire: (BOOL) acquire
|
|
|
|
{
|
|
|
|
id obj;
|
|
|
|
NSDictionary *record;
|
|
|
|
WORequest *request;
|
|
|
|
|
|
|
|
obj = [super lookupName: key
|
|
|
|
inContext: localContext
|
|
|
|
acquire: acquire];
|
|
|
|
if (!obj)
|
|
|
|
{
|
|
|
|
record = [childRecords objectForKey: key];
|
|
|
|
if (!record)
|
|
|
|
{
|
|
|
|
record = [self _recordForObjectName: key];
|
|
|
|
if (record)
|
|
|
|
[childRecords setObject: record forKey: key];
|
|
|
|
}
|
|
|
|
if (record)
|
|
|
|
obj = [self _createChildComponentWithRecord: record];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
request = [localContext request];
|
|
|
|
if ([[request method] isEqualToString: @"PUT"])
|
2008-07-14 18:47:10 +02:00
|
|
|
{
|
|
|
|
obj = [self _createChildComponentWithName: key
|
|
|
|
andContent: [request contentAsString]];
|
|
|
|
[obj setIsNew: YES];
|
|
|
|
}
|
2008-06-13 22:16:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj;
|
2007-02-21 22:11:40 +01:00
|
|
|
}
|
|
|
|
|
2007-09-15 01:16:48 +02:00
|
|
|
- (void) deleteEntriesWithIds: (NSArray *) ids
|
|
|
|
{
|
|
|
|
unsigned int count, max;
|
|
|
|
NSString *currentID;
|
|
|
|
SOGoContentObject *deleteObject;
|
|
|
|
|
|
|
|
max = [ids count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
currentID = [ids objectAtIndex: count];
|
|
|
|
deleteObject = [self lookupName: currentID
|
2008-06-13 22:16:30 +02:00
|
|
|
inContext: context
|
|
|
|
acquire: NO];
|
2007-11-04 20:51:09 +01:00
|
|
|
if (![deleteObject isKindOfClass: [NSException class]])
|
2007-11-18 11:16:25 +01:00
|
|
|
{
|
|
|
|
if ([deleteObject respondsToSelector: @selector (prepareDelete)])
|
|
|
|
[deleteObject prepareDelete];
|
|
|
|
[deleteObject delete];
|
|
|
|
}
|
2007-09-15 01:16:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-08 19:16:09 +02:00
|
|
|
- (NSString *) davCollectionTag
|
|
|
|
{
|
|
|
|
NSArray *records;
|
|
|
|
GCSFolder *folder;
|
2009-06-08 19:49:15 +02:00
|
|
|
EOFetchSpecification *cTagSpec;
|
2009-06-08 19:16:09 +02:00
|
|
|
EOSortOrdering *ordering;
|
|
|
|
NSNumber *lastModified;
|
|
|
|
NSString *cTag;
|
|
|
|
|
|
|
|
folder = [self ocsFolder];
|
|
|
|
ordering = [EOSortOrdering sortOrderingWithKey: @"c_lastmodified"
|
2009-06-08 19:49:15 +02:00
|
|
|
selector: EOCompareDescending];
|
2009-06-08 19:16:09 +02:00
|
|
|
cTagSpec = [EOFetchSpecification
|
2009-06-08 19:49:15 +02:00
|
|
|
fetchSpecificationWithEntityName: [folder folderName]
|
|
|
|
qualifier: nil
|
|
|
|
sortOrderings: [NSArray arrayWithObject: ordering]];
|
2009-06-08 19:16:09 +02:00
|
|
|
|
|
|
|
records = [folder fetchFields: [NSArray arrayWithObject: @"c_lastmodified"]
|
|
|
|
fetchSpecification: cTagSpec
|
|
|
|
ignoreDeleted: NO];
|
|
|
|
if ([records count])
|
|
|
|
{
|
|
|
|
lastModified = [[records objectAtIndex: 0]
|
|
|
|
objectForKey: @"c_lastmodified"];
|
|
|
|
cTag = [lastModified stringValue];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cTag = @"-1";
|
|
|
|
|
|
|
|
return cTag;
|
|
|
|
}
|
|
|
|
|
2007-12-05 00:28:52 +01:00
|
|
|
#warning this code should be cleaned up
|
2008-02-25 22:59:25 +01:00
|
|
|
- (void) _subscribeUser: (SOGoUser *) subscribingUser
|
2009-07-01 16:03:58 +02:00
|
|
|
reallyDo: (BOOL) reallyDo
|
2008-05-16 22:33:55 +02:00
|
|
|
fromMailInvitation: (BOOL) isMailInvitation
|
2009-07-01 16:03:58 +02:00
|
|
|
inResponse: (WOResponse *) response
|
2007-12-05 00:28:52 +01:00
|
|
|
{
|
|
|
|
NSMutableArray *folderSubscription;
|
2008-05-16 22:33:55 +02:00
|
|
|
NSString *subscriptionPointer, *mailInvitationURL;
|
2007-12-05 00:28:52 +01:00
|
|
|
NSUserDefaults *ud;
|
|
|
|
NSMutableDictionary *moduleSettings;
|
|
|
|
|
2008-02-25 22:59:25 +01:00
|
|
|
if ([owner isEqualToString: [subscribingUser login]])
|
2007-12-05 00:28:52 +01:00
|
|
|
{
|
|
|
|
[response setStatus: 403];
|
|
|
|
[response appendContentString:
|
2009-07-01 16:03:58 +02:00
|
|
|
@"You cannot (un)subscribe to a folder that you own!"];
|
2007-12-05 00:28:52 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-03-23 20:04:31 +01:00
|
|
|
ud = [subscribingUser userSettings];
|
|
|
|
moduleSettings = [ud objectForKey: [container nameInContainer]];
|
|
|
|
if (!(moduleSettings
|
2009-07-01 16:03:58 +02:00
|
|
|
&& [moduleSettings isKindOfClass: [NSMutableDictionary class]]))
|
|
|
|
{
|
|
|
|
moduleSettings = [NSMutableDictionary dictionary];
|
|
|
|
[ud setObject: moduleSettings forKey: [container nameInContainer]];
|
|
|
|
}
|
2009-03-23 20:04:31 +01:00
|
|
|
|
2007-12-05 00:28:52 +01:00
|
|
|
folderSubscription
|
2009-07-01 16:03:58 +02:00
|
|
|
= [moduleSettings objectForKey: @"SubscribedFolders"];
|
2007-12-05 00:28:52 +01:00
|
|
|
if (!(folderSubscription
|
2009-07-01 16:03:58 +02:00
|
|
|
&& [folderSubscription isKindOfClass: [NSMutableArray class]]))
|
|
|
|
{
|
|
|
|
folderSubscription = [NSMutableArray array];
|
|
|
|
[moduleSettings setObject: folderSubscription
|
|
|
|
forKey: @"SubscribedFolders"];
|
|
|
|
}
|
2007-12-05 00:28:52 +01:00
|
|
|
|
2008-04-22 01:03:48 +02:00
|
|
|
subscriptionPointer = [self folderReference];
|
2007-12-05 00:28:52 +01:00
|
|
|
if (reallyDo)
|
2009-07-01 16:03:58 +02:00
|
|
|
[folderSubscription addObjectUniquely: subscriptionPointer];
|
2007-12-05 00:28:52 +01:00
|
|
|
else
|
2009-07-01 16:03:58 +02:00
|
|
|
{
|
|
|
|
[[moduleSettings objectForKey: @"FolderColors"]
|
|
|
|
removeObjectForKey: subscriptionPointer];
|
|
|
|
[folderSubscription removeObject: subscriptionPointer];
|
|
|
|
}
|
2007-12-05 00:28:52 +01:00
|
|
|
|
|
|
|
[ud synchronize];
|
|
|
|
|
2008-05-16 22:33:55 +02:00
|
|
|
if (isMailInvitation)
|
2009-07-01 16:03:58 +02:00
|
|
|
{
|
|
|
|
mailInvitationURL = [[self soURLToBaseContainerForCurrentUser]
|
|
|
|
absoluteString];
|
|
|
|
[response setStatus: 302];
|
|
|
|
[response setHeader: mailInvitationURL
|
|
|
|
forKey: @"location"];
|
|
|
|
}
|
2008-05-16 22:33:55 +02:00
|
|
|
else
|
2009-07-01 16:03:58 +02:00
|
|
|
[response setStatus: 204];
|
2007-12-05 00:28:52 +01:00
|
|
|
}
|
2008-02-25 22:59:25 +01:00
|
|
|
}
|
|
|
|
|
2008-05-16 22:33:55 +02:00
|
|
|
- (WOResponse *) subscribe: (BOOL) reallyDo
|
2009-07-01 16:03:58 +02:00
|
|
|
inTheNamesOf: (NSArray *) delegatedUsers
|
|
|
|
fromMailInvitation: (BOOL) isMailInvitation
|
|
|
|
inContext: (WOContext *) localContext
|
2008-02-25 22:59:25 +01:00
|
|
|
{
|
|
|
|
WOResponse *response;
|
2008-11-18 01:06:37 +01:00
|
|
|
SOGoUser *currentUser;
|
2008-02-25 22:59:25 +01:00
|
|
|
|
|
|
|
response = [localContext response];
|
2009-01-21 17:20:11 +01:00
|
|
|
[response setHeader: @"text/plain; charset=utf-8"
|
2009-07-01 16:03:58 +02:00
|
|
|
forKey: @"Content-Type"];
|
2009-01-21 17:20:11 +01:00
|
|
|
|
2008-02-25 22:59:25 +01:00
|
|
|
currentUser = [localContext activeUser];
|
|
|
|
|
2009-06-11 21:55:13 +02:00
|
|
|
if ([delegatedUsers count])
|
2008-02-25 22:59:25 +01:00
|
|
|
{
|
2008-11-18 01:06:37 +01:00
|
|
|
if (![currentUser isSuperUser])
|
2009-07-01 16:03:58 +02:00
|
|
|
{
|
|
|
|
[response setStatus: 403];
|
|
|
|
[response appendContentString:
|
|
|
|
@"You cannot subscribe another user to any folder"
|
|
|
|
@" unless you are a super-user."];
|
|
|
|
}
|
2008-11-18 01:06:37 +01:00
|
|
|
else
|
2009-07-01 16:03:58 +02:00
|
|
|
{
|
|
|
|
// The current user is a superuser...
|
|
|
|
SOGoUser *subscriptionUser;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < [delegatedUsers count]; i++)
|
|
|
|
{
|
|
|
|
// We trust the passed user ID here as it might generate tons or LDAP
|
|
|
|
// call but more importantly, cache propagation calls that will create
|
|
|
|
// contention on GDNC.
|
|
|
|
subscriptionUser = [SOGoUser userWithLogin: [delegatedUsers objectAtIndex: i]
|
|
|
|
roles: nil
|
|
|
|
trust: YES];
|
|
|
|
|
|
|
|
[self _subscribeUser: subscriptionUser
|
|
|
|
reallyDo: reallyDo
|
|
|
|
fromMailInvitation: isMailInvitation
|
|
|
|
inResponse: response];
|
|
|
|
}
|
|
|
|
}
|
2008-11-18 01:06:37 +01:00
|
|
|
}
|
2008-02-25 22:59:25 +01:00
|
|
|
else
|
|
|
|
{
|
2008-11-18 01:06:37 +01:00
|
|
|
[self _subscribeUser: currentUser
|
2009-07-01 16:03:58 +02:00
|
|
|
reallyDo: reallyDo
|
|
|
|
fromMailInvitation: isMailInvitation
|
|
|
|
inResponse: response];
|
2008-02-25 22:59:25 +01:00
|
|
|
}
|
2007-12-05 00:28:52 +01:00
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2008-11-18 01:06:37 +01:00
|
|
|
- (NSArray *) _parseDAVDelegatedUser: (WOContext *) queryContext
|
2008-02-25 22:59:25 +01:00
|
|
|
{
|
|
|
|
id <DOMDocument> document;
|
|
|
|
id <DOMNamedNodeMap> attrs;
|
2008-11-18 01:06:37 +01:00
|
|
|
id o;
|
2008-02-25 22:59:25 +01:00
|
|
|
document = [[queryContext request] contentAsDOMDocument];
|
|
|
|
attrs = [[document documentElement] attributes];
|
|
|
|
|
2008-11-18 01:06:37 +01:00
|
|
|
o = [attrs namedItem: @"users"];
|
2009-07-01 16:03:58 +02:00
|
|
|
|
2008-11-18 01:06:37 +01:00
|
|
|
if (o) return [[o nodeValue] componentsSeparatedByString: @","];
|
2009-07-01 16:03:58 +02:00
|
|
|
|
2008-11-18 01:06:37 +01:00
|
|
|
return nil;
|
2008-02-25 22:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id <WOActionResults>) davSubscribe: (WOContext *) queryContext
|
2007-12-05 00:28:52 +01:00
|
|
|
{
|
2008-05-16 22:33:55 +02:00
|
|
|
return [self subscribe: YES
|
2009-06-08 19:16:09 +02:00
|
|
|
inTheNamesOf: [self _parseDAVDelegatedUser: queryContext]
|
2009-07-01 16:03:58 +02:00
|
|
|
fromMailInvitation: NO
|
|
|
|
inContext: queryContext];
|
2007-12-05 00:28:52 +01:00
|
|
|
}
|
|
|
|
|
2008-02-25 22:59:25 +01:00
|
|
|
- (id <WOActionResults>) davUnsubscribe: (WOContext *) queryContext
|
2007-12-05 00:28:52 +01:00
|
|
|
{
|
2008-05-16 22:33:55 +02:00
|
|
|
return [self subscribe: NO
|
2009-06-08 19:16:09 +02:00
|
|
|
inTheNamesOf: [self _parseDAVDelegatedUser: queryContext]
|
2009-07-01 16:03:58 +02:00
|
|
|
fromMailInvitation: NO
|
|
|
|
inContext: queryContext];
|
2007-12-05 00:28:52 +01:00
|
|
|
}
|
|
|
|
|
2009-06-18 22:58:46 +02:00
|
|
|
- (NSDictionary *) davSQLFieldsTable
|
|
|
|
{
|
|
|
|
static NSMutableDictionary *davSQLFieldsTable = nil;
|
|
|
|
|
|
|
|
if (!davSQLFieldsTable)
|
|
|
|
{
|
|
|
|
davSQLFieldsTable = [NSMutableDictionary new];
|
|
|
|
[davSQLFieldsTable setObject: @"c_version" forKey: @"{DAV:}getetag"];
|
2009-06-24 01:41:25 +02:00
|
|
|
[davSQLFieldsTable setObject: @"" forKey: @"{DAV:}getcontenttype"];
|
2009-06-18 22:58:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return davSQLFieldsTable;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) _davSQLFieldsForProperties: (NSArray *) properties
|
|
|
|
{
|
|
|
|
NSMutableDictionary *davSQLFields;
|
|
|
|
NSDictionary *davSQLFieldsTable;
|
|
|
|
NSString *sqlField, *property;
|
|
|
|
unsigned int count, max;
|
|
|
|
|
|
|
|
davSQLFieldsTable = [self davSQLFieldsTable];
|
|
|
|
|
|
|
|
max = [properties count];
|
|
|
|
davSQLFields = [NSMutableDictionary dictionaryWithCapacity: max];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
property = [properties objectAtIndex: count];
|
|
|
|
sqlField = [davSQLFieldsTable objectForKey: property];
|
|
|
|
if (sqlField)
|
|
|
|
[davSQLFields setObject: sqlField forKey: property];
|
|
|
|
else
|
|
|
|
[self errorWithFormat: @"DAV property '%@' has no matching SQL field,"
|
2009-07-01 16:03:58 +02:00
|
|
|
@" response could be incomplete", property];
|
2009-06-18 22:58:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return davSQLFields;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) parseDAVRequestedProperties: (DOMElement *) propElement
|
|
|
|
{
|
|
|
|
NSArray *properties;
|
|
|
|
NSDictionary *sqlFieldsTable;
|
|
|
|
|
|
|
|
properties = [propElement flatPropertyNameOfSubElements];
|
|
|
|
sqlFieldsTable = [self _davSQLFieldsForProperties: properties];
|
|
|
|
|
|
|
|
return sqlFieldsTable;
|
|
|
|
}
|
|
|
|
|
2009-06-19 22:14:19 +02:00
|
|
|
/* make this a public method? */
|
|
|
|
- (NSArray *) _fetchFields: (NSArray *) fields
|
|
|
|
withQualifier: (EOQualifier *) qualifier
|
|
|
|
ignoreDeleted: (BOOL) ignoreDeleted
|
|
|
|
{
|
|
|
|
GCSFolder *folder;
|
|
|
|
EOFetchSpecification *fetchSpec;
|
|
|
|
|
|
|
|
folder = [self ocsFolder];
|
|
|
|
|
|
|
|
if (qualifier)
|
|
|
|
fetchSpec = [EOFetchSpecification
|
2009-07-01 16:03:58 +02:00
|
|
|
fetchSpecificationWithEntityName: [folder folderName]
|
|
|
|
qualifier: qualifier
|
|
|
|
sortOrderings: nil];
|
2009-06-19 22:14:19 +02:00
|
|
|
else
|
|
|
|
fetchSpec = nil;
|
|
|
|
|
|
|
|
return [folder fetchFields: fields fetchSpecification: fetchSpec
|
|
|
|
ignoreDeleted: ignoreDeleted];
|
|
|
|
}
|
|
|
|
|
2009-06-19 16:49:47 +02:00
|
|
|
- (NSArray *) _fetchSyncTokenFields: (NSDictionary *) properties
|
|
|
|
matchingSyncToken: (int) syncToken
|
|
|
|
{
|
|
|
|
/* TODO:
|
|
|
|
- validation:
|
|
|
|
- synctoken and return "DAV:valid-sync-token" as error if needed
|
|
|
|
- properties
|
|
|
|
- database errors */
|
2009-06-19 22:14:19 +02:00
|
|
|
NSMutableArray *fields, *mRecords;
|
|
|
|
NSArray *records;
|
2009-06-19 16:49:47 +02:00
|
|
|
EOQualifier *qualifier;
|
2009-06-24 01:41:25 +02:00
|
|
|
NSEnumerator *addFields;
|
|
|
|
NSString *currentField;
|
2009-06-19 16:49:47 +02:00
|
|
|
|
|
|
|
fields = [NSMutableArray arrayWithObjects: @"c_name", @"c_component",
|
2009-07-01 16:03:58 +02:00
|
|
|
@"c_creationdate", @"c_lastmodified", nil];
|
2009-06-24 01:41:25 +02:00
|
|
|
addFields = [[properties allValues] objectEnumerator];
|
|
|
|
while ((currentField = [addFields nextObject]))
|
|
|
|
if ([currentField length])
|
|
|
|
[fields addObjectUniquely: currentField];
|
2009-06-19 16:49:47 +02:00
|
|
|
|
|
|
|
if (syncToken)
|
2009-06-19 22:14:19 +02:00
|
|
|
{
|
|
|
|
qualifier = [EOQualifier qualifierWithQualifierFormat:
|
2009-07-01 16:03:58 +02:00
|
|
|
@"c_lastmodified > %d", syncToken];
|
2009-06-19 22:14:19 +02:00
|
|
|
mRecords = [NSMutableArray arrayWithArray: [self _fetchFields: fields
|
2009-07-01 16:03:58 +02:00
|
|
|
withQualifier: qualifier
|
|
|
|
ignoreDeleted: YES]];
|
2009-06-19 22:14:19 +02:00
|
|
|
qualifier = [EOQualifier qualifierWithQualifierFormat:
|
2009-07-01 16:03:58 +02:00
|
|
|
@"c_lastmodified > %d and c_deleted == 1",
|
|
|
|
syncToken];
|
2009-06-19 22:14:19 +02:00
|
|
|
fields = [NSMutableArray arrayWithObjects: @"c_name", @"c_deleted", nil];
|
|
|
|
[mRecords addObjectsFromArray: [self _fetchFields: fields
|
2009-07-01 16:03:58 +02:00
|
|
|
withQualifier: qualifier
|
|
|
|
ignoreDeleted: NO]];
|
2009-06-19 22:14:19 +02:00
|
|
|
records = mRecords;
|
|
|
|
}
|
2009-06-19 16:49:47 +02:00
|
|
|
else
|
2009-06-19 22:14:19 +02:00
|
|
|
records = [self _fetchFields: fields withQualifier: nil
|
|
|
|
ignoreDeleted: YES];
|
2009-06-19 16:49:47 +02:00
|
|
|
|
2009-06-19 22:14:19 +02:00
|
|
|
return records;
|
2009-06-19 16:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* These methods are the optimal ones to generate propstats for DAV reports,
|
|
|
|
it should be used in other subclasses. */
|
|
|
|
- (NSDictionary *) _davPropstat: (NSArray *) properties
|
|
|
|
withStatus: (NSString *) status
|
|
|
|
{
|
|
|
|
NSMutableArray *propstat;
|
|
|
|
|
|
|
|
propstat = [NSMutableArray arrayWithCapacity: 2];
|
|
|
|
[propstat addObject: davElementWithContent (@"prop", XMLNS_WEBDAV,
|
|
|
|
properties)];
|
|
|
|
[propstat addObject: davElementWithContent (@"status", XMLNS_WEBDAV,
|
|
|
|
status)];
|
|
|
|
|
|
|
|
return davElementWithContent (@"propstat", XMLNS_WEBDAV, propstat);
|
|
|
|
}
|
|
|
|
|
2009-06-24 01:41:25 +02:00
|
|
|
- (NSArray *) _davPropstatsWithProperties: (NSArray *) davProperties
|
2009-06-19 16:49:47 +02:00
|
|
|
andMethodSelectors: (SEL *) selectors
|
|
|
|
fromRecord: (NSDictionary *) record
|
|
|
|
{
|
|
|
|
SOGoContentObject *sogoObject;
|
|
|
|
unsigned int count, max;
|
|
|
|
NSMutableArray *properties200, *properties404, *propstats;
|
|
|
|
NSDictionary *propContent;
|
|
|
|
id result;
|
|
|
|
|
|
|
|
propstats = [NSMutableArray arrayWithCapacity: 2];
|
|
|
|
|
|
|
|
max = [davProperties count];
|
|
|
|
properties200 = [NSMutableArray arrayWithCapacity: max];
|
|
|
|
properties404 = [NSMutableArray arrayWithCapacity: max];
|
|
|
|
|
|
|
|
sogoObject = [self _createChildComponentWithRecord: record];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
if (selectors[count]
|
|
|
|
&& [sogoObject respondsToSelector: selectors[count]])
|
2009-07-01 16:03:58 +02:00
|
|
|
result = [sogoObject performSelector: selectors[count]];
|
2009-06-19 16:49:47 +02:00
|
|
|
else
|
|
|
|
result = nil;
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
propContent = [[davProperties objectAtIndex: count]
|
2009-07-01 16:03:58 +02:00
|
|
|
asWebDAVTupleWithContent: result];
|
2009-06-19 16:49:47 +02:00
|
|
|
[properties200 addObject: propContent];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
propContent = [[davProperties objectAtIndex: count]
|
2009-07-01 16:03:58 +02:00
|
|
|
asWebDAVTuple];
|
2009-06-19 16:49:47 +02:00
|
|
|
[properties404 addObject: propContent];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([properties200 count])
|
|
|
|
[propstats addObject: [self _davPropstat: properties200
|
2009-07-01 16:03:58 +02:00
|
|
|
withStatus: @"HTTP/1.1 200 OK"]];
|
2009-06-19 16:49:47 +02:00
|
|
|
if ([properties404 count])
|
|
|
|
[propstats addObject: [self _davPropstat: properties404
|
2009-07-01 16:03:58 +02:00
|
|
|
withStatus: @"HTTP/1.1 404 Not Found"]];
|
2009-06-19 16:49:47 +02:00
|
|
|
|
|
|
|
return propstats;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) _syncResponseWithProperties: (NSArray *) properties
|
|
|
|
andMethodSelectors: (SEL *) selectors
|
|
|
|
fromRecord: (NSDictionary *) record
|
|
|
|
withToken: (int) syncToken
|
|
|
|
andBaseURL: (NSString *) baseURL
|
|
|
|
{
|
|
|
|
static NSString *status[] = { @"HTTP/1.1 404 Not Found",
|
2009-07-01 16:03:58 +02:00
|
|
|
@"HTTP/1.1 201 Created",
|
|
|
|
@"HTTP/1.1 200 OK" };
|
2009-06-19 16:49:47 +02:00
|
|
|
NSMutableArray *children;
|
|
|
|
NSString *href;
|
|
|
|
unsigned int statusIndex;
|
|
|
|
|
|
|
|
children = [NSMutableArray arrayWithCapacity: 3];
|
|
|
|
href = [NSString stringWithFormat: @"%@%@",
|
2009-07-01 16:03:58 +02:00
|
|
|
baseURL, [record objectForKey: @"c_name"]];
|
2009-06-19 16:49:47 +02:00
|
|
|
[children addObject: davElementWithContent (@"href", XMLNS_WEBDAV,
|
|
|
|
href)];
|
|
|
|
if (syncToken)
|
|
|
|
{
|
|
|
|
if ([[record objectForKey: @"c_deleted"] intValue] > 0)
|
|
|
|
statusIndex = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ([[record objectForKey: @"c_creationdate"] intValue]
|
|
|
|
>= syncToken)
|
|
|
|
statusIndex = 1;
|
|
|
|
else
|
|
|
|
statusIndex = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
statusIndex = 1;
|
|
|
|
|
2009-07-01 16:03:58 +02:00
|
|
|
// NSLog (@"webdav sync: %@ (%@)", href, status[statusIndex]);
|
2009-06-19 16:49:47 +02:00
|
|
|
[children addObject: davElementWithContent (@"status", XMLNS_WEBDAV,
|
|
|
|
status[statusIndex])];
|
|
|
|
if (statusIndex)
|
|
|
|
[children
|
2009-06-24 01:41:25 +02:00
|
|
|
addObjectsFromArray: [self _davPropstatsWithProperties: properties
|
2009-07-01 16:03:58 +02:00
|
|
|
andMethodSelectors: selectors
|
|
|
|
fromRecord: record]];
|
2009-06-19 16:49:47 +02:00
|
|
|
|
|
|
|
return davElementWithContent (@"sync-response", XMLNS_WEBDAV, children);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _appendComponentProperties: (NSArray *) properties
|
|
|
|
fromRecords: (NSArray *) records
|
|
|
|
matchingSyncToken: (int) syncToken
|
|
|
|
toResponse: (WOResponse *) response
|
|
|
|
{
|
|
|
|
NSMutableArray *syncResponses;
|
|
|
|
NSDictionary *multistatus, *record;
|
|
|
|
unsigned int count, max, now;
|
|
|
|
int newToken, currentLM;
|
|
|
|
NSString *baseURL, *newTokenStr;
|
|
|
|
SEL *selectors;
|
|
|
|
|
|
|
|
max = [properties count];
|
|
|
|
selectors = NSZoneMalloc (NULL, sizeof (max * sizeof (SEL)));
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
selectors[count]
|
|
|
|
= SOGoSelectorForPropertyGetter ([properties objectAtIndex: count]);
|
|
|
|
|
|
|
|
now = (unsigned int) [[NSDate date] timeIntervalSince1970];
|
|
|
|
|
|
|
|
newToken = 0;
|
|
|
|
|
|
|
|
baseURL = [[self davURL] absoluteString];
|
|
|
|
|
|
|
|
max = [records count];
|
|
|
|
syncResponses = [NSMutableArray arrayWithCapacity: max + 1];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
record = [records objectAtIndex: count];
|
|
|
|
currentLM = [[record objectForKey: @"c_lastmodified"] intValue];
|
|
|
|
if (newToken < currentLM)
|
|
|
|
newToken = currentLM;
|
|
|
|
[syncResponses addObject: [self _syncResponseWithProperties: properties
|
2009-07-01 16:03:58 +02:00
|
|
|
andMethodSelectors: selectors
|
|
|
|
fromRecord: record
|
|
|
|
withToken: syncToken
|
|
|
|
andBaseURL: baseURL]];
|
2009-06-19 16:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
NSZoneFree (NULL, selectors);
|
|
|
|
|
|
|
|
/* If the most recent c_lastmodified is "now", we need to return "now - 1"
|
|
|
|
in order to make sure during the next sync that every records that might
|
|
|
|
get added at the same moment are not lost. */
|
|
|
|
if (!newToken || newToken == now)
|
|
|
|
newToken = now - 1;
|
|
|
|
|
|
|
|
newTokenStr = [NSString stringWithFormat: @"%d", newToken];
|
|
|
|
[syncResponses addObject: davElementWithContent (@"sync-token",
|
|
|
|
XMLNS_WEBDAV,
|
|
|
|
newTokenStr)];
|
|
|
|
multistatus = davElementWithContent (@"multistatus", XMLNS_WEBDAV,
|
|
|
|
syncResponses);
|
|
|
|
[response
|
|
|
|
appendContentString: [multistatus asWebDavStringWithNamespaces: nil]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) davSyncCollection: (WOContext *) localContext
|
|
|
|
{
|
|
|
|
WOResponse *r;
|
|
|
|
id <DOMDocument> document;
|
|
|
|
DOMElement *documentElement, *propElement;
|
|
|
|
NSString *syncToken;
|
|
|
|
NSDictionary *properties;
|
|
|
|
NSArray *records;
|
|
|
|
int syncTokenInt;
|
|
|
|
|
|
|
|
r = [context response];
|
|
|
|
[r setStatus: 207];
|
|
|
|
[r setContentEncoding: NSUTF8StringEncoding];
|
|
|
|
[r setHeader: @"text/xml; charset=\"utf-8\"" forKey: @"content-type"];
|
|
|
|
[r setHeader: @"no-cache" forKey: @"pragma"];
|
|
|
|
[r setHeader: @"no-cache" forKey: @"cache-control"];
|
|
|
|
[r appendContentString:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"];
|
|
|
|
|
|
|
|
document = [[context request] contentAsDOMDocument];
|
|
|
|
documentElement = (DOMElement *) [document documentElement];
|
|
|
|
syncToken = [[documentElement firstElementWithTag: @"sync-token"
|
|
|
|
inNamespace: XMLNS_WEBDAV] textValue];
|
|
|
|
propElement = [documentElement firstElementWithTag: @"prop"
|
|
|
|
inNamespace: XMLNS_WEBDAV];
|
|
|
|
|
|
|
|
syncTokenInt = [syncToken intValue];
|
|
|
|
properties = [self parseDAVRequestedProperties: propElement];
|
|
|
|
records = [self _fetchSyncTokenFields: properties
|
|
|
|
matchingSyncToken: syncTokenInt];
|
|
|
|
[self _appendComponentProperties: [properties allKeys]
|
|
|
|
fromRecords: records
|
|
|
|
matchingSyncToken: syncTokenInt
|
|
|
|
toResponse: r];
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2009-06-04 02:40:21 +02:00
|
|
|
/* handling acls from quick tables */
|
|
|
|
- (void) initializeQuickTablesAclsInContext: (WOContext *) localContext
|
|
|
|
{
|
|
|
|
NSString *login;
|
|
|
|
|
|
|
|
if (activeUserIsOwner)
|
|
|
|
userCanAccessAllObjects = activeUserIsOwner;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
login = [[localContext activeUser] login];
|
|
|
|
/* we only grant "userCanAccessAllObjects" for role "ObjectEraser" and
|
|
|
|
not "ObjectCreator" because the latter doesn't imply we can read
|
|
|
|
properties from subobjects or even know their existence. */
|
|
|
|
userCanAccessAllObjects = ([[self ownerInContext: localContext]
|
2009-07-01 16:03:58 +02:00
|
|
|
isEqualToString: login]
|
2009-06-04 02:40:21 +02:00
|
|
|
|| [[self aclsForUser: login]
|
2009-07-01 16:03:58 +02:00
|
|
|
containsObject: SOGoRole_ObjectEraser]);
|
2009-06-04 02:40:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-17 16:30:12 +02:00
|
|
|
/* acls as a container */
|
|
|
|
|
2007-05-19 02:49:05 +02:00
|
|
|
- (NSArray *) aclUsersForObjectAtPath: (NSArray *) objectPathArray;
|
2007-04-17 16:30:12 +02:00
|
|
|
{
|
|
|
|
EOQualifier *qualifier;
|
|
|
|
NSString *qs;
|
2008-02-22 22:25:34 +01:00
|
|
|
NSArray *records, *uids;
|
2007-04-17 16:30:12 +02:00
|
|
|
|
|
|
|
qs = [NSString stringWithFormat: @"c_object = '/%@'",
|
2009-07-01 16:03:58 +02:00
|
|
|
[objectPathArray componentsJoinedByString: @"/"]];
|
2007-04-17 16:30:12 +02:00
|
|
|
qualifier = [EOQualifier qualifierWithQualifierFormat: qs];
|
2007-05-19 02:49:05 +02:00
|
|
|
records = [[self ocsFolder] fetchAclMatchingQualifier: qualifier];
|
2008-02-22 22:25:34 +01:00
|
|
|
uids = [[records valueForKey: @"c_uid"] uniqueObjects];
|
2007-04-17 16:30:12 +02:00
|
|
|
|
2008-02-22 22:25:34 +01:00
|
|
|
return uids;
|
2007-04-17 16:30:12 +02:00
|
|
|
}
|
|
|
|
|
2007-04-27 21:45:12 +02:00
|
|
|
- (NSArray *) _fetchAclsForUser: (NSString *) uid
|
2009-07-01 16:03:58 +02:00
|
|
|
forObjectAtPath: (NSString *) objectPath
|
2007-04-17 16:30:12 +02:00
|
|
|
{
|
|
|
|
EOQualifier *qualifier;
|
|
|
|
NSArray *records;
|
2007-04-26 03:16:19 +02:00
|
|
|
NSMutableArray *acls;
|
2007-04-17 16:30:12 +02:00
|
|
|
NSString *qs;
|
|
|
|
|
2009-05-03 19:50:57 +02:00
|
|
|
// We look for the exact uid or any uid that begins with "@" (corresponding to groups)
|
|
|
|
qs = [NSString stringWithFormat: @"(c_object = '/%@') AND (c_uid = '%@' OR c_uid LIKE '@%%')",
|
2009-07-01 16:03:58 +02:00
|
|
|
objectPath, uid];
|
2007-04-17 16:30:12 +02:00
|
|
|
qualifier = [EOQualifier qualifierWithQualifierFormat: qs];
|
|
|
|
records = [[self ocsFolder] fetchAclMatchingQualifier: qualifier];
|
2007-04-26 03:16:19 +02:00
|
|
|
acls = [NSMutableArray array];
|
|
|
|
|
2009-05-03 19:50:57 +02:00
|
|
|
unsigned int i, j;
|
|
|
|
NSArray *members;
|
|
|
|
NSDictionary *record;
|
|
|
|
NSString *currentUid;
|
|
|
|
SOGoGroup *group;
|
|
|
|
SOGoUser *user;
|
|
|
|
|
|
|
|
for (i = 0; i < [records count]; i ++)
|
|
|
|
{
|
|
|
|
record = [records objectAtIndex: i];
|
|
|
|
currentUid = [record valueForKey: @"c_uid"];
|
|
|
|
if ([currentUid isEqualToString: uid])
|
2009-07-01 16:03:58 +02:00
|
|
|
[acls addObject: [record valueForKey: @"c_role"]];
|
2009-05-03 19:50:57 +02:00
|
|
|
else
|
2009-07-01 16:03:58 +02:00
|
|
|
{
|
|
|
|
group = [SOGoGroup groupWithIdentifier: currentUid];
|
|
|
|
if (group)
|
|
|
|
{
|
|
|
|
members = [group members];
|
|
|
|
for (j = 0; j < [members count]; j++)
|
|
|
|
{
|
|
|
|
user = [members objectAtIndex: j];
|
|
|
|
if ([[user login] isEqualToString: uid])
|
|
|
|
{
|
|
|
|
[acls addObject: [record valueForKey: @"c_role"]];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-05-03 19:50:57 +02:00
|
|
|
}
|
2009-07-01 16:03:58 +02:00
|
|
|
|
2008-02-22 22:25:34 +01:00
|
|
|
return [acls uniqueObjects];
|
2007-04-17 16:30:12 +02:00
|
|
|
}
|
|
|
|
|
2007-04-27 21:45:12 +02:00
|
|
|
- (void) _cacheRoles: (NSArray *) roles
|
2009-07-01 16:03:58 +02:00
|
|
|
forUser: (NSString *) uid
|
2007-04-27 21:45:12 +02:00
|
|
|
forObjectAtPath: (NSString *) objectPath
|
|
|
|
{
|
|
|
|
NSMutableDictionary *aclsForObject;
|
|
|
|
|
|
|
|
aclsForObject = [aclCache objectForKey: objectPath];
|
|
|
|
if (!aclsForObject)
|
|
|
|
{
|
|
|
|
aclsForObject = [NSMutableDictionary dictionary];
|
|
|
|
[aclCache setObject: aclsForObject
|
2009-06-04 01:06:52 +02:00
|
|
|
forKey: objectPath];
|
2007-04-27 21:45:12 +02:00
|
|
|
}
|
|
|
|
if (roles)
|
|
|
|
[aclsForObject setObject: roles forKey: uid];
|
|
|
|
else
|
|
|
|
[aclsForObject removeObjectForKey: uid];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) aclsForUser: (NSString *) uid
|
|
|
|
forObjectAtPath: (NSArray *) objectPathArray
|
|
|
|
{
|
|
|
|
NSArray *acls;
|
|
|
|
NSString *objectPath;
|
|
|
|
NSDictionary *aclsForObject;
|
|
|
|
|
|
|
|
objectPath = [objectPathArray componentsJoinedByString: @"/"];
|
|
|
|
aclsForObject = [aclCache objectForKey: objectPath];
|
|
|
|
if (aclsForObject)
|
|
|
|
acls = [aclsForObject objectForKey: uid];
|
|
|
|
else
|
|
|
|
acls = nil;
|
|
|
|
if (!acls)
|
|
|
|
{
|
|
|
|
acls = [self _fetchAclsForUser: uid forObjectAtPath: objectPath];
|
2009-02-06 21:11:11 +01:00
|
|
|
if (!acls)
|
2009-07-01 16:03:58 +02:00
|
|
|
acls = [NSArray array];
|
2007-04-27 21:45:12 +02:00
|
|
|
[self _cacheRoles: acls forUser: uid forObjectAtPath: objectPath];
|
|
|
|
}
|
|
|
|
|
2007-05-22 20:35:17 +02:00
|
|
|
if (!([acls count] || [uid isEqualToString: defaultUserID]))
|
2009-07-01 16:03:58 +02:00
|
|
|
acls = [self aclsForUser: defaultUserID
|
|
|
|
forObjectAtPath: objectPathArray];
|
2007-04-27 21:45:12 +02:00
|
|
|
|
2008-12-30 23:25:30 +01:00
|
|
|
// If we still don't have ACLs defined for this particular resource,
|
|
|
|
// let's go get the system-wide defaults, if any.
|
|
|
|
if (![acls count])
|
|
|
|
{
|
2009-06-04 01:06:52 +02:00
|
|
|
if ([[container nameInContainer] isEqualToString: @"Calendar"]
|
2009-07-01 16:03:58 +02:00
|
|
|
|| [[container nameInContainer] isEqualToString: @"Contacts"])
|
|
|
|
acls = [[NSUserDefaults standardUserDefaults]
|
|
|
|
objectForKey: [NSString stringWithFormat: @"SOGo%@DefaultRoles",
|
|
|
|
[container nameInContainer]]];
|
2008-12-30 23:25:30 +01:00
|
|
|
}
|
2009-06-04 01:06:52 +02:00
|
|
|
|
2007-04-27 21:45:12 +02:00
|
|
|
return acls;
|
|
|
|
}
|
|
|
|
|
2007-04-17 16:30:12 +02:00
|
|
|
- (void) removeAclsForUsers: (NSArray *) users
|
|
|
|
forObjectAtPath: (NSArray *) objectPathArray
|
|
|
|
{
|
|
|
|
EOQualifier *qualifier;
|
2009-05-06 23:57:21 +02:00
|
|
|
NSString *uid, *uids, *qs, *objectPath;
|
|
|
|
NSMutableArray *usersAndGroups;
|
2007-04-27 21:45:12 +02:00
|
|
|
NSMutableDictionary *aclsForObject;
|
2009-05-06 23:57:21 +02:00
|
|
|
SOGoGroup *group;
|
|
|
|
unsigned int i;
|
2007-04-17 16:30:12 +02:00
|
|
|
|
|
|
|
if ([users count] > 0)
|
|
|
|
{
|
2009-05-06 23:57:21 +02:00
|
|
|
usersAndGroups = [NSMutableArray arrayWithArray: users];
|
|
|
|
for (i = 0; i < [usersAndGroups count]; i++)
|
2009-07-01 16:03:58 +02:00
|
|
|
{
|
|
|
|
uid = [usersAndGroups objectAtIndex: i];
|
|
|
|
if (![uid hasPrefix: @"@"])
|
|
|
|
{
|
|
|
|
// Prefix the UID with the character "@" when dealing with a group
|
|
|
|
group = [SOGoGroup groupWithIdentifier: uid];
|
|
|
|
if (group)
|
|
|
|
[usersAndGroups replaceObjectAtIndex: i
|
|
|
|
withObject: [NSString stringWithFormat: @"@%@", uid]];
|
|
|
|
}
|
|
|
|
}
|
2007-04-27 21:45:12 +02:00
|
|
|
objectPath = [objectPathArray componentsJoinedByString: @"/"];
|
|
|
|
aclsForObject = [aclCache objectForKey: objectPath];
|
|
|
|
if (aclsForObject)
|
2009-07-01 16:03:58 +02:00
|
|
|
[aclsForObject removeObjectsForKeys: usersAndGroups];
|
2009-05-06 23:57:21 +02:00
|
|
|
uids = [usersAndGroups componentsJoinedByString: @"') OR (c_uid = '"];
|
2007-04-17 16:30:12 +02:00
|
|
|
qs = [NSString
|
2009-07-01 16:03:58 +02:00
|
|
|
stringWithFormat: @"(c_object = '/%@') AND ((c_uid = '%@'))",
|
|
|
|
objectPath, uids];
|
2007-04-17 16:30:12 +02:00
|
|
|
qualifier = [EOQualifier qualifierWithQualifierFormat: qs];
|
|
|
|
[[self ocsFolder] deleteAclMatchingQualifier: qualifier];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-18 01:09:46 +02:00
|
|
|
- (void) _commitRoles: (NSArray *) roles
|
2009-07-01 16:03:58 +02:00
|
|
|
forUID: (NSString *) uid
|
|
|
|
forObject: (NSString *) objectPath
|
2007-04-17 16:30:12 +02:00
|
|
|
{
|
|
|
|
EOAdaptorChannel *channel;
|
|
|
|
GCSFolder *folder;
|
2007-04-25 00:45:38 +02:00
|
|
|
NSEnumerator *userRoles;
|
2007-05-18 01:09:46 +02:00
|
|
|
NSString *SQL, *currentRole;
|
2007-04-27 21:45:12 +02:00
|
|
|
|
2007-04-17 16:30:12 +02:00
|
|
|
folder = [self ocsFolder];
|
|
|
|
channel = [folder acquireAclChannel];
|
2008-11-26 17:26:32 +01:00
|
|
|
[[channel adaptorContext] beginTransaction];
|
2007-04-25 00:45:38 +02:00
|
|
|
userRoles = [roles objectEnumerator];
|
2008-07-04 18:06:09 +02:00
|
|
|
while ((currentRole = [userRoles nextObject]))
|
2007-04-25 00:45:38 +02:00
|
|
|
{
|
2007-05-18 01:09:46 +02:00
|
|
|
SQL = [NSString stringWithFormat: @"INSERT INTO %@"
|
2009-07-01 16:03:58 +02:00
|
|
|
@" (c_object, c_uid, c_role)"
|
|
|
|
@" VALUES ('/%@', '%@', '%@')",
|
|
|
|
[folder aclTableName],
|
|
|
|
objectPath, uid, currentRole];
|
2008-11-26 17:26:32 +01:00
|
|
|
[channel evaluateExpressionX: SQL];
|
2007-04-25 00:45:38 +02:00
|
|
|
}
|
2007-04-17 16:30:12 +02:00
|
|
|
|
2008-11-26 17:26:32 +01:00
|
|
|
[[channel adaptorContext] commitTransaction];
|
2007-04-17 16:30:12 +02:00
|
|
|
[folder releaseChannel: channel];
|
|
|
|
}
|
|
|
|
|
2007-05-18 01:09:46 +02:00
|
|
|
- (void) setRoles: (NSArray *) roles
|
|
|
|
forUser: (NSString *) uid
|
|
|
|
forObjectAtPath: (NSArray *) objectPathArray
|
|
|
|
{
|
2009-05-03 19:50:57 +02:00
|
|
|
NSString *objectPath, *aUID;
|
2007-05-18 01:09:46 +02:00
|
|
|
NSMutableArray *newRoles;
|
2009-05-03 19:50:57 +02:00
|
|
|
SOGoGroup *group;
|
2007-05-18 01:09:46 +02:00
|
|
|
|
2009-05-03 19:50:57 +02:00
|
|
|
aUID = uid;
|
|
|
|
if (![uid hasPrefix: @"@"])
|
|
|
|
{
|
|
|
|
// Prefix the UID with the character "@" when dealing with a group
|
|
|
|
group = [SOGoGroup groupWithIdentifier: uid];
|
|
|
|
if (group)
|
2009-07-01 16:03:58 +02:00
|
|
|
aUID = [NSString stringWithFormat: @"@%@", uid];
|
2009-05-03 19:50:57 +02:00
|
|
|
}
|
|
|
|
[self removeAclsForUsers: [NSArray arrayWithObject: aUID]
|
2009-07-01 16:03:58 +02:00
|
|
|
forObjectAtPath: objectPathArray];
|
2007-05-18 01:09:46 +02:00
|
|
|
|
|
|
|
newRoles = [NSMutableArray arrayWithArray: roles];
|
|
|
|
[newRoles removeObject: SOGoRole_AuthorizedSubscriber];
|
|
|
|
[newRoles removeObject: SOGoRole_None];
|
|
|
|
objectPath = [objectPathArray componentsJoinedByString: @"/"];
|
|
|
|
[self _cacheRoles: newRoles forUser: uid
|
2009-07-01 16:03:58 +02:00
|
|
|
forObjectAtPath: objectPath];
|
2007-05-18 01:09:46 +02:00
|
|
|
if (![newRoles count])
|
|
|
|
[newRoles addObject: SOGoRole_None];
|
|
|
|
|
2009-05-03 19:50:57 +02:00
|
|
|
[self _commitRoles: newRoles forUID: aUID forObject: objectPath];
|
2007-05-18 01:09:46 +02:00
|
|
|
}
|
|
|
|
|
2007-04-17 16:30:12 +02:00
|
|
|
/* acls */
|
2007-05-19 02:49:05 +02:00
|
|
|
- (NSArray *) aclUsers
|
2007-04-17 16:30:12 +02:00
|
|
|
{
|
2008-05-16 22:33:55 +02:00
|
|
|
return [self aclUsersForObjectAtPath: [self pathArrayToFolder]];
|
2007-04-17 16:30:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) aclsForUser: (NSString *) uid
|
|
|
|
{
|
2007-06-01 23:03:50 +02:00
|
|
|
NSMutableArray *acls;
|
|
|
|
NSArray *ownAcls, *containerAcls;
|
|
|
|
|
|
|
|
acls = [NSMutableArray array];
|
2008-05-16 22:33:55 +02:00
|
|
|
ownAcls = [self aclsForUser: uid forObjectAtPath: [self pathArrayToFolder]];
|
2007-06-01 23:03:50 +02:00
|
|
|
[acls addObjectsFromArray: ownAcls];
|
|
|
|
if ([container respondsToSelector: @selector (aclsForUser:)])
|
|
|
|
{
|
|
|
|
containerAcls = [container aclsForUser: uid];
|
|
|
|
if ([containerAcls count] > 0)
|
2009-07-01 16:03:58 +02:00
|
|
|
{
|
2007-06-01 23:03:50 +02:00
|
|
|
#warning this should be checked
|
2009-07-01 16:03:58 +02:00
|
|
|
if ([containerAcls containsObject: SOGoRole_ObjectEraser])
|
|
|
|
[acls addObject: SOGoRole_ObjectEraser];
|
|
|
|
}
|
2007-06-01 23:03:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return acls;
|
2007-04-17 16:30:12 +02:00
|
|
|
}
|
|
|
|
|
2007-04-25 00:45:38 +02:00
|
|
|
- (void) setRoles: (NSArray *) roles
|
2007-04-17 16:30:12 +02:00
|
|
|
forUser: (NSString *) uid
|
|
|
|
{
|
|
|
|
return [self setRoles: roles
|
2009-07-01 16:03:58 +02:00
|
|
|
forUser: uid
|
|
|
|
forObjectAtPath: [self pathArrayToFolder]];
|
2007-04-17 16:30:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) removeAclsForUsers: (NSArray *) users
|
|
|
|
{
|
|
|
|
return [self removeAclsForUsers: users
|
2009-07-01 16:03:58 +02:00
|
|
|
forObjectAtPath: [self pathArrayToFolder]];
|
2007-04-17 16:30:12 +02:00
|
|
|
}
|
|
|
|
|
2007-05-22 20:35:17 +02:00
|
|
|
- (NSString *) defaultUserID
|
|
|
|
{
|
|
|
|
return defaultUserID;
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* description */
|
|
|
|
|
2007-07-12 17:55:06 +02:00
|
|
|
- (void) appendAttributesToDescription: (NSMutableString *) _ms
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
[super appendAttributesToDescription:_ms];
|
2009-07-01 16:03:58 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
[_ms appendFormat:@" ocs=%@", [self ocsPath]];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end /* SOGoFolder */
|