2007-09-11 22:14:18 +02:00
|
|
|
/* SOGoParentFolder.m - this file is part of SOGo
|
|
|
|
*
|
2009-04-21 17:20:52 +02:00
|
|
|
* Copyright (C) 2006-2009 Inverse inc.
|
2007-09-11 22:14:18 +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/NSDictionary.h>
|
2008-07-04 18:06:09 +02:00
|
|
|
#import <Foundation/NSEnumerator.h>
|
2007-09-11 22:14:18 +02:00
|
|
|
#import <Foundation/NSString.h>
|
2007-09-15 00:01:02 +02:00
|
|
|
#import <Foundation/NSUserDefaults.h>
|
2007-09-11 22:14:18 +02:00
|
|
|
|
|
|
|
#import <NGObjWeb/NSException+HTTP.h>
|
2007-11-30 17:43:55 +01:00
|
|
|
#import <NGObjWeb/SoSecurityManager.h>
|
2007-09-15 00:01:02 +02:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
2009-03-18 21:28:35 +01:00
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
2007-09-11 22:14:18 +02:00
|
|
|
#import <GDLContentStore/GCSChannelManager.h>
|
|
|
|
#import <GDLContentStore/GCSFolderManager.h>
|
|
|
|
#import <GDLContentStore/NSURL+GCS.h>
|
|
|
|
#import <GDLAccess/EOAdaptorChannel.h>
|
2008-06-30 20:58:19 +02:00
|
|
|
#import <SaxObjC/XMLNamespaces.h>
|
2007-09-11 22:14:18 +02:00
|
|
|
|
2008-05-03 01:11:21 +02:00
|
|
|
#import "NSObject+DAV.h"
|
2007-11-07 16:58:43 +01:00
|
|
|
#import "SOGoGCSFolder.h"
|
2007-11-08 18:12:30 +01:00
|
|
|
#import "SOGoPermissions.h"
|
2007-09-15 00:01:02 +02:00
|
|
|
#import "SOGoUser.h"
|
2008-05-03 01:11:21 +02:00
|
|
|
#import "SOGoWebDAVAclManager.h"
|
2007-09-11 22:14:18 +02:00
|
|
|
|
|
|
|
#import "SOGoParentFolder.h"
|
|
|
|
|
2007-11-30 17:43:55 +01:00
|
|
|
static SoSecurityManager *sm = nil;
|
|
|
|
|
2007-09-11 22:14:18 +02:00
|
|
|
@implementation SOGoParentFolder
|
|
|
|
|
2007-11-30 17:43:55 +01:00
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
if (!sm)
|
|
|
|
sm = [SoSecurityManager sharedSecurityManager];
|
|
|
|
}
|
|
|
|
|
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",
|
|
|
|
XMLNS_WEBDAV)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"all", XMLNS_WEBDAV)];
|
|
|
|
[aclManager registerDAVPermission:
|
|
|
|
davElement (@"read-current-user-privilege-set",
|
|
|
|
XMLNS_WEBDAV)
|
|
|
|
abstract: NO
|
|
|
|
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_AddFolders
|
|
|
|
asChildOf: davElement (@"write", XMLNS_WEBDAV)];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"unbind",
|
|
|
|
XMLNS_WEBDAV)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: SoPerm_DeleteObjects
|
|
|
|
asChildOf: davElement (@"write", XMLNS_WEBDAV)];
|
|
|
|
[aclManager
|
2008-06-30 20:49:46 +02:00
|
|
|
registerDAVPermission: davElement (@"write-properties", XMLNS_WEBDAV)
|
2008-05-03 01:11:21 +02:00
|
|
|
abstract: YES
|
|
|
|
withEquivalent: nil
|
2008-06-30 20:49:46 +02:00
|
|
|
asChildOf: davElement (@"write", XMLNS_WEBDAV)];
|
2008-07-29 18:36:16 +02:00
|
|
|
[aclManager
|
2008-06-30 20:49:46 +02:00
|
|
|
registerDAVPermission: davElement (@"write-content", XMLNS_WEBDAV)
|
2008-05-03 01:11:21 +02:00
|
|
|
abstract: YES
|
|
|
|
withEquivalent: nil
|
2008-06-30 20:49:46 +02:00
|
|
|
asChildOf: davElement (@"write", XMLNS_WEBDAV)];
|
2008-05-03 01:11:21 +02:00
|
|
|
}
|
|
|
|
|
2008-07-29 18:36:16 +02:00
|
|
|
return aclManager;
|
2008-05-03 01:11:21 +02:00
|
|
|
}
|
|
|
|
|
2007-09-11 22:14:18 +02:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
subFolders = nil;
|
|
|
|
OCSPath = nil;
|
2009-08-27 23:14:54 +02:00
|
|
|
subscribedSubFolders = nil;
|
2007-09-11 22:14:18 +02:00
|
|
|
subFolderClass = Nil;
|
2008-12-17 15:53:16 +01:00
|
|
|
// hasSubscribedSources = NO;
|
2007-09-11 22:14:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2009-08-27 23:14:54 +02:00
|
|
|
[subscribedSubFolders release];
|
2007-09-11 22:14:18 +02:00
|
|
|
[subFolders release];
|
|
|
|
[OCSPath release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (Class) subFolderClass
|
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
|
|
|
return Nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSString *) gcsFolderType
|
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setBaseOCSPath: (NSString *) newOCSPath
|
|
|
|
{
|
|
|
|
ASSIGN (OCSPath, newOCSPath);
|
|
|
|
}
|
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
- (NSString *) defaultFolderName
|
|
|
|
{
|
|
|
|
return @"Personal";
|
|
|
|
}
|
|
|
|
|
2007-11-08 18:12:30 +01:00
|
|
|
- (void) _createPersonalFolder
|
|
|
|
{
|
|
|
|
NSArray *roles;
|
|
|
|
SOGoGCSFolder *folder;
|
|
|
|
|
|
|
|
roles = [[context activeUser] rolesForObject: self inContext: context];
|
|
|
|
if ([roles containsObject: SoRole_Owner])
|
|
|
|
{
|
|
|
|
folder = [subFolderClass objectWithName: @"personal" inContainer: self];
|
|
|
|
[folder setDisplayName: [self defaultFolderName]];
|
|
|
|
[folder
|
|
|
|
setOCSPath: [NSString stringWithFormat: @"%@/personal", OCSPath]];
|
|
|
|
if ([folder create])
|
|
|
|
[subFolders setObject: folder forKey: @"personal"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-18 21:28:35 +01:00
|
|
|
- (NSException *) _fetchPersonalFolders: (NSString *) sql
|
|
|
|
withChannel: (EOAdaptorChannel *) fc
|
2007-09-11 22:14:18 +02:00
|
|
|
{
|
|
|
|
NSArray *attrs;
|
|
|
|
NSDictionary *row;
|
|
|
|
BOOL hasPersonal;
|
2007-11-08 18:12:30 +01:00
|
|
|
SOGoGCSFolder *folder;
|
2007-11-07 16:58:43 +01:00
|
|
|
NSString *key;
|
2009-03-18 21:28:35 +01:00
|
|
|
NSException *error;
|
2007-09-11 22:14:18 +02:00
|
|
|
|
|
|
|
if (!subFolderClass)
|
|
|
|
subFolderClass = [[self class] subFolderClass];
|
|
|
|
|
|
|
|
hasPersonal = NO;
|
2009-03-18 21:28:35 +01:00
|
|
|
error = [fc evaluateExpressionX: sql];
|
|
|
|
if (!error)
|
2007-09-11 22:14:18 +02:00
|
|
|
{
|
2009-03-18 21:28:35 +01:00
|
|
|
attrs = [fc describeResults: NO];
|
|
|
|
row = [fc fetchAttributes: attrs withZone: NULL];
|
|
|
|
while (row)
|
2007-09-17 16:20:22 +02:00
|
|
|
{
|
2009-03-18 21:28:35 +01:00
|
|
|
key = [row objectForKey: @"c_path4"];
|
|
|
|
if ([key isKindOfClass: [NSString class]])
|
|
|
|
{
|
|
|
|
folder = [subFolderClass objectWithName: key inContainer: self];
|
|
|
|
hasPersonal = (hasPersonal || [key isEqualToString: @"personal"]);
|
|
|
|
[folder setOCSPath: [NSString stringWithFormat: @"%@/%@",
|
|
|
|
OCSPath, key]];
|
|
|
|
[subFolders setObject: folder forKey: key];
|
|
|
|
}
|
|
|
|
row = [fc fetchAttributes: attrs withZone: NULL];
|
2007-09-17 16:20:22 +02:00
|
|
|
}
|
2009-03-18 21:28:35 +01:00
|
|
|
|
|
|
|
if (!hasPersonal)
|
|
|
|
[self _createPersonalFolder];
|
2007-09-11 22:14:18 +02:00
|
|
|
}
|
|
|
|
|
2009-03-18 21:28:35 +01:00
|
|
|
return error;
|
2007-09-11 22:14:18 +02:00
|
|
|
}
|
|
|
|
|
2009-03-18 21:28:35 +01:00
|
|
|
- (NSException *) appendPersonalSources
|
2007-09-11 22:14:18 +02:00
|
|
|
{
|
|
|
|
GCSChannelManager *cm;
|
|
|
|
EOAdaptorChannel *fc;
|
|
|
|
NSURL *folderLocation;
|
|
|
|
NSString *sql, *gcsFolderType;
|
2009-03-18 21:28:35 +01:00
|
|
|
NSException *error;
|
2007-09-11 22:14:18 +02:00
|
|
|
|
|
|
|
cm = [GCSChannelManager defaultChannelManager];
|
|
|
|
folderLocation
|
|
|
|
= [[GCSFolderManager defaultFolderManager] folderInfoLocation];
|
|
|
|
fc = [cm acquireOpenChannelForURL: folderLocation];
|
2009-03-18 21:28:35 +01:00
|
|
|
if ([fc isOpen])
|
2007-09-11 22:14:18 +02:00
|
|
|
{
|
|
|
|
gcsFolderType = [[self class] gcsFolderType];
|
|
|
|
|
|
|
|
sql
|
2007-09-15 00:01:02 +02:00
|
|
|
= [NSString stringWithFormat: (@"SELECT c_path4 FROM %@"
|
2007-09-11 22:14:18 +02:00
|
|
|
@" WHERE c_path2 = '%@'"
|
|
|
|
@" AND c_folder_type = '%@'"),
|
|
|
|
[folderLocation gcsTableName],
|
|
|
|
[self ownerInContext: context],
|
|
|
|
gcsFolderType];
|
2009-03-18 21:28:35 +01:00
|
|
|
error = [self _fetchPersonalFolders: sql withChannel: fc];
|
2008-06-30 20:55:45 +02:00
|
|
|
[cm releaseChannel: fc];
|
2007-09-11 22:14:18 +02:00
|
|
|
// sql = [sql stringByAppendingFormat:@" WHERE %@ = '%@'",
|
|
|
|
// uidColumnName, [self uid]];
|
|
|
|
}
|
2009-03-18 21:28:35 +01:00
|
|
|
else
|
|
|
|
error = [NSException exceptionWithName: @"SOGoDBException"
|
|
|
|
reason: @"database connection could not be open"
|
|
|
|
userInfo: nil];
|
|
|
|
|
|
|
|
return error;
|
2007-09-11 22:14:18 +02:00
|
|
|
}
|
|
|
|
|
2009-03-18 21:28:35 +01:00
|
|
|
- (NSException *) appendSystemSources
|
2007-09-11 22:14:18 +02:00
|
|
|
{
|
2009-03-18 21:28:35 +01:00
|
|
|
return nil;
|
2007-09-11 22:14:18 +02:00
|
|
|
}
|
|
|
|
|
2007-11-30 17:43:55 +01:00
|
|
|
- (void) _appendSubscribedSource: (NSString *) sourceKey
|
|
|
|
{
|
|
|
|
SOGoGCSFolder *subscribedFolder;
|
|
|
|
|
|
|
|
subscribedFolder
|
|
|
|
= [subFolderClass folderWithSubscriptionReference: sourceKey
|
|
|
|
inContainer: self];
|
|
|
|
if (subscribedFolder
|
|
|
|
&& ![sm validatePermission: SOGoPerm_AccessObject
|
2009-06-29 21:08:29 +02:00
|
|
|
onObject: subscribedFolder
|
|
|
|
inContext: context])
|
|
|
|
[subscribedSubFolders setObject: subscribedFolder
|
|
|
|
forKey: [subscribedFolder nameInContainer]];
|
2007-11-30 17:43:55 +01:00
|
|
|
}
|
|
|
|
|
2009-03-18 21:28:35 +01:00
|
|
|
- (NSException *) appendSubscribedSources
|
2007-09-15 00:01:02 +02:00
|
|
|
{
|
|
|
|
NSArray *subscribedReferences;
|
|
|
|
NSUserDefaults *settings;
|
|
|
|
NSEnumerator *allKeys;
|
|
|
|
NSString *currentKey;
|
2009-03-18 21:28:35 +01:00
|
|
|
NSException *error;
|
|
|
|
|
|
|
|
error = nil; /* we ignore non-DB errors at this time... */
|
2007-09-15 00:01:02 +02:00
|
|
|
|
|
|
|
settings = [[context activeUser] userSettings];
|
|
|
|
subscribedReferences = [[settings objectForKey: nameInContainer]
|
|
|
|
objectForKey: @"SubscribedFolders"];
|
|
|
|
if ([subscribedReferences isKindOfClass: [NSArray class]])
|
|
|
|
{
|
|
|
|
allKeys = [subscribedReferences objectEnumerator];
|
2007-11-30 17:43:55 +01:00
|
|
|
while ((currentKey = [allKeys nextObject]))
|
|
|
|
[self _appendSubscribedSource: currentKey];
|
2007-09-15 00:01:02 +02:00
|
|
|
}
|
2009-03-18 21:28:35 +01:00
|
|
|
|
|
|
|
return error;
|
2007-09-15 00:01:02 +02:00
|
|
|
}
|
|
|
|
|
2007-09-11 22:14:18 +02:00
|
|
|
- (NSException *) newFolderWithName: (NSString *) name
|
2007-11-07 16:58:43 +01:00
|
|
|
andNameInContainer: (NSString *) newNameInContainer
|
2007-09-11 22:14:18 +02:00
|
|
|
{
|
2007-11-07 16:58:43 +01:00
|
|
|
SOGoGCSFolder *newFolder;
|
2007-09-11 22:14:18 +02:00
|
|
|
NSException *error;
|
|
|
|
|
|
|
|
if (!subFolderClass)
|
|
|
|
subFolderClass = [[self class] subFolderClass];
|
|
|
|
|
2007-11-08 20:56:55 +01:00
|
|
|
newFolder = [subFolderClass objectWithName: newNameInContainer
|
|
|
|
inContainer: self];
|
2007-09-11 22:14:18 +02:00
|
|
|
if ([newFolder isKindOfClass: [NSException class]])
|
|
|
|
error = (NSException *) newFolder;
|
|
|
|
else
|
|
|
|
{
|
2007-09-15 00:01:02 +02:00
|
|
|
[newFolder setDisplayName: name];
|
2007-09-11 22:14:18 +02:00
|
|
|
[newFolder setOCSPath: [NSString stringWithFormat: @"%@/%@",
|
2007-11-08 20:56:55 +01:00
|
|
|
OCSPath, newNameInContainer]];
|
2007-09-11 22:14:18 +02:00
|
|
|
if ([newFolder create])
|
2007-11-08 19:15:07 +01:00
|
|
|
{
|
2007-11-08 20:56:55 +01:00
|
|
|
[subFolders setObject: newFolder forKey: newNameInContainer];
|
2007-11-08 19:15:07 +01:00
|
|
|
error = nil;
|
|
|
|
}
|
2007-09-11 22:14:18 +02:00
|
|
|
else
|
|
|
|
error = [NSException exceptionWithHTTPStatus: 400
|
|
|
|
reason: @"The new folder could not be created"];
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2007-11-07 16:58:43 +01:00
|
|
|
- (NSException *) newFolderWithName: (NSString *) name
|
|
|
|
nameInContainer: (NSString **) newNameInContainer
|
|
|
|
{
|
|
|
|
NSString *newFolderID;
|
|
|
|
NSException *error;
|
|
|
|
|
|
|
|
newFolderID = [self globallyUniqueObjectId];
|
|
|
|
error = [self newFolderWithName: name
|
|
|
|
andNameInContainer: newFolderID];
|
|
|
|
if (error)
|
|
|
|
*newNameInContainer = nil;
|
|
|
|
else
|
|
|
|
*newNameInContainer = newFolderID;
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2009-06-29 21:08:29 +02:00
|
|
|
- (NSException *) initSubFolders;
|
2007-09-11 22:14:18 +02:00
|
|
|
{
|
2009-03-18 21:28:35 +01:00
|
|
|
NSException *error;
|
2008-12-17 15:53:16 +01:00
|
|
|
|
2007-09-11 22:14:18 +02:00
|
|
|
if (!subFolders)
|
|
|
|
{
|
|
|
|
subFolders = [NSMutableDictionary new];
|
2009-03-18 21:28:35 +01:00
|
|
|
error = [self appendPersonalSources];
|
2009-06-29 21:08:29 +02:00
|
|
|
if (!error)
|
|
|
|
error = [self appendSystemSources];
|
2009-03-18 21:28:35 +01:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
[subFolders release];
|
|
|
|
subFolders = nil;
|
|
|
|
}
|
2007-09-11 22:14:18 +02:00
|
|
|
}
|
2009-03-18 21:28:35 +01:00
|
|
|
else
|
|
|
|
error = nil;
|
|
|
|
|
|
|
|
return error;
|
2007-09-11 22:14:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-29 21:08:29 +02:00
|
|
|
- (NSException *) initSubscribedSubFolders
|
|
|
|
{
|
2009-08-27 23:14:54 +02:00
|
|
|
NSString *login;
|
2009-06-29 21:08:29 +02:00
|
|
|
NSException *error;
|
|
|
|
|
2009-08-27 23:14:54 +02:00
|
|
|
if (!subFolderClass)
|
|
|
|
subFolderClass = [[self class] subFolderClass];
|
|
|
|
|
2009-06-29 21:08:29 +02:00
|
|
|
error = nil; /* we ignore non-DB errors at this time... */
|
|
|
|
login = [[context activeUser] login];
|
2008-12-17 15:33:14 +01:00
|
|
|
|
2009-06-29 21:08:29 +02:00
|
|
|
if (!subscribedSubFolders && [login isEqualToString: owner])
|
|
|
|
{
|
|
|
|
subscribedSubFolders = [NSMutableDictionary new];
|
2009-08-27 23:14:54 +02:00
|
|
|
error = [self appendSubscribedSources];
|
2009-06-29 21:08:29 +02:00
|
|
|
}
|
2009-08-27 23:14:54 +02:00
|
|
|
|
2009-06-29 21:08:29 +02:00
|
|
|
return error;
|
|
|
|
}
|
2008-12-17 15:33:14 +01:00
|
|
|
|
2009-03-18 21:28:35 +01:00
|
|
|
- (NSArray *) fetchContentObjectNames
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2007-09-11 22:14:18 +02:00
|
|
|
- (id) lookupName: (NSString *) name
|
|
|
|
inContext: (WOContext *) lookupContext
|
|
|
|
acquire: (BOOL) acquire
|
|
|
|
{
|
|
|
|
id obj;
|
2009-03-18 21:28:35 +01:00
|
|
|
NSException *error;
|
2007-09-11 22:14:18 +02:00
|
|
|
|
|
|
|
/* first check attributes directly bound to the application */
|
|
|
|
obj = [super lookupName: name inContext: lookupContext acquire: NO];
|
|
|
|
if (!obj)
|
|
|
|
{
|
2009-06-29 21:08:29 +02:00
|
|
|
// Lookup in personal folders
|
|
|
|
error = [self initSubFolders];
|
2009-03-18 21:28:35 +01:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
[self errorWithFormat: @"a database error occured: %@", [error reason]];
|
|
|
|
obj = [NSException exceptionWithHTTPStatus: 503];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
obj = [subFolders objectForKey: name];
|
2009-06-29 21:08:29 +02:00
|
|
|
|
|
|
|
if (!obj)
|
|
|
|
{
|
|
|
|
// Lookup in subscribed folders
|
|
|
|
error = [self initSubscribedSubFolders];
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
[self errorWithFormat: @"a database error occured: %@", [error reason]];
|
|
|
|
obj = [NSException exceptionWithHTTPStatus: 503];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
obj = [subscribedSubFolders objectForKey: name];
|
|
|
|
}
|
2007-09-11 22:14:18 +02:00
|
|
|
}
|
2009-06-29 21:08:29 +02:00
|
|
|
|
2007-09-11 22:14:18 +02:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2008-11-24 22:26:36 +01:00
|
|
|
- (NSArray *) subFolders
|
2007-09-11 22:14:18 +02:00
|
|
|
{
|
2009-06-29 21:08:29 +02:00
|
|
|
NSMutableArray *ma;
|
2009-03-18 21:28:35 +01:00
|
|
|
NSException *error;
|
|
|
|
|
2009-06-29 21:08:29 +02:00
|
|
|
error = [self initSubFolders];
|
|
|
|
if (error)
|
2009-03-18 21:28:35 +01:00
|
|
|
{
|
2009-06-29 21:08:29 +02:00
|
|
|
/* We exceptionnally raise the exception here because doPROPFIND:
|
|
|
|
will not care for errors in its response from
|
|
|
|
toManyRelationShipKeys, which may in turn trigger the
|
|
|
|
disappearance of user folders in the SOGo extensions. */
|
|
|
|
[error raise];
|
2009-03-18 21:28:35 +01:00
|
|
|
}
|
2009-06-29 21:08:29 +02:00
|
|
|
|
|
|
|
error = [self initSubscribedSubFolders];
|
|
|
|
if (error)
|
|
|
|
[error raise];
|
|
|
|
|
|
|
|
ma = [NSMutableArray arrayWithArray: [subFolders allValues]];
|
|
|
|
if ([subscribedSubFolders count])
|
|
|
|
[ma addObjectsFromArray: [subscribedSubFolders allValues]];
|
2007-09-11 22:14:18 +02:00
|
|
|
|
2009-06-29 21:08:29 +02:00
|
|
|
return [ma sortedArrayUsingSelector: @selector (compare:)];
|
2007-09-11 22:14:18 +02:00
|
|
|
}
|
|
|
|
|
2009-08-20 15:02:51 +02:00
|
|
|
- (BOOL) hasLocalSubFolderNamed: (NSString *) name
|
|
|
|
{
|
|
|
|
NSArray *subs;
|
|
|
|
NSException *error;
|
|
|
|
int i, count;
|
|
|
|
BOOL rc = NO;
|
|
|
|
|
|
|
|
error = [self initSubFolders];
|
|
|
|
if (error)
|
|
|
|
[error raise];
|
|
|
|
|
|
|
|
subs = [subFolders allValues];
|
|
|
|
count = [subs count];
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
if ([name isEqualToString: [[subs objectAtIndex: i] displayName]])
|
|
|
|
rc = YES;
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2008-11-24 22:26:36 +01:00
|
|
|
- (NSArray *) toManyRelationshipKeys
|
2007-09-11 22:14:18 +02:00
|
|
|
{
|
2008-11-24 22:26:36 +01:00
|
|
|
NSEnumerator *sortedSubFolders;
|
|
|
|
NSMutableArray *keys;
|
|
|
|
SOGoGCSFolder *currentFolder;
|
2007-09-11 22:14:18 +02:00
|
|
|
|
2008-11-24 22:26:36 +01:00
|
|
|
keys = [NSMutableArray array];
|
|
|
|
sortedSubFolders = [[self subFolders] objectEnumerator];
|
|
|
|
while ((currentFolder = [sortedSubFolders nextObject]))
|
|
|
|
[keys addObject: [currentFolder nameInContainer]];
|
|
|
|
|
|
|
|
return keys;
|
2007-09-11 22:14:18 +02:00
|
|
|
}
|
|
|
|
|
2008-01-29 21:48:39 +01:00
|
|
|
- (NSException *) davCreateCollection: (NSString *) pathInfo
|
|
|
|
inContext: (WOContext *) localContext
|
|
|
|
{
|
|
|
|
return [self newFolderWithName: pathInfo
|
|
|
|
andNameInContainer: pathInfo];
|
|
|
|
}
|
|
|
|
|
2007-09-11 22:14:18 +02:00
|
|
|
@end
|