2007-09-11 22:14:18 +02:00
|
|
|
/* SOGoParentFolder.m - this file is part of SOGo
|
|
|
|
*
|
2008-09-27 03:13:41 +02:00
|
|
|
* Copyright (C) 2006, 2007 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>
|
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;
|
|
|
|
subFolderClass = Nil;
|
2008-12-17 15:53:16 +01:00
|
|
|
// hasSubscribedSources = NO;
|
2007-09-11 22:14:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[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"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-11 22:14:18 +02:00
|
|
|
- (void) _fetchPersonalFolders: (NSString *) sql
|
|
|
|
withChannel: (EOAdaptorChannel *) fc
|
|
|
|
{
|
|
|
|
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;
|
2007-09-11 22:14:18 +02:00
|
|
|
|
|
|
|
if (!subFolderClass)
|
|
|
|
subFolderClass = [[self class] subFolderClass];
|
|
|
|
|
|
|
|
hasPersonal = NO;
|
|
|
|
[fc evaluateExpressionX: sql];
|
|
|
|
attrs = [fc describeResults: NO];
|
|
|
|
row = [fc fetchAttributes: attrs withZone: NULL];
|
|
|
|
while (row)
|
|
|
|
{
|
|
|
|
key = [row objectForKey: @"c_path4"];
|
2007-09-17 16:20:22 +02:00
|
|
|
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];
|
|
|
|
}
|
2007-09-11 22:14:18 +02:00
|
|
|
row = [fc fetchAttributes: attrs withZone: NULL];
|
|
|
|
}
|
|
|
|
|
2007-11-08 18:12:30 +01:00
|
|
|
if (!hasPersonal)
|
|
|
|
[self _createPersonalFolder];
|
2007-09-11 22:14:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) appendPersonalSources
|
|
|
|
{
|
|
|
|
GCSChannelManager *cm;
|
|
|
|
EOAdaptorChannel *fc;
|
|
|
|
NSURL *folderLocation;
|
|
|
|
NSString *sql, *gcsFolderType;
|
|
|
|
|
2008-12-19 17:31:03 +01:00
|
|
|
#if 0
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
2007-09-11 22:14:18 +02:00
|
|
|
cm = [GCSChannelManager defaultChannelManager];
|
|
|
|
folderLocation
|
|
|
|
= [[GCSFolderManager defaultFolderManager] folderInfoLocation];
|
|
|
|
fc = [cm acquireOpenChannelForURL: folderLocation];
|
|
|
|
if (fc)
|
|
|
|
{
|
|
|
|
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];
|
|
|
|
[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]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) appendSystemSources
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-11-29 22:10:39 +01:00
|
|
|
- (void) _removeSubscribedSource: (NSString *) key
|
|
|
|
{
|
|
|
|
#warning TO BE IMPLEMENTED SOON FIXME
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
onObject: subscribedFolder
|
|
|
|
inContext: context])
|
|
|
|
[subFolders setObject: subscribedFolder
|
|
|
|
forKey: [subscribedFolder nameInContainer]];
|
|
|
|
else
|
|
|
|
[self _removeSubscribedSource: sourceKey];
|
|
|
|
}
|
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
- (void) appendSubscribedSources
|
|
|
|
{
|
|
|
|
NSArray *subscribedReferences;
|
|
|
|
NSUserDefaults *settings;
|
|
|
|
NSEnumerator *allKeys;
|
|
|
|
NSString *currentKey;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-09-11 22:14:18 +02:00
|
|
|
- (void) initSubFolders
|
|
|
|
{
|
2008-12-17 15:53:16 +01:00
|
|
|
NSString *login;
|
|
|
|
|
2007-09-11 22:14:18 +02:00
|
|
|
if (!subFolders)
|
|
|
|
{
|
|
|
|
subFolders = [NSMutableDictionary new];
|
2008-12-19 17:31:03 +01:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
SOGoGCSFolder *folder;
|
|
|
|
if (!subFolderClass)
|
|
|
|
subFolderClass = [[self class] subFolderClass];
|
|
|
|
|
|
|
|
folder = [subFolderClass objectWithName: @"personal" inContainer: self];
|
|
|
|
[folder setDisplayName: [self defaultFolderName]];
|
|
|
|
[folder
|
|
|
|
setOCSPath: [NSString stringWithFormat: @"%@/personal", OCSPath]];
|
|
|
|
[subFolders setObject: folder forKey: @"personal"];
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
2007-09-11 22:14:18 +02:00
|
|
|
[self appendPersonalSources];
|
|
|
|
[self appendSystemSources];
|
2008-12-17 15:53:16 +01:00
|
|
|
login = [[context activeUser] login];
|
|
|
|
if ([login isEqualToString: owner])
|
|
|
|
[self appendSubscribedSources];
|
2007-09-11 22:14:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-17 15:53:16 +01:00
|
|
|
// - (void) _appendSubscribedSourcesIfNeeded
|
|
|
|
// {
|
|
|
|
// NSString *login;
|
2008-12-17 15:33:14 +01:00
|
|
|
|
2008-12-17 15:53:16 +01:00
|
|
|
// login = [[context activeUser] login];
|
|
|
|
// if ([login isEqualToString: owner])
|
|
|
|
// [self appendSubscribedSources];
|
|
|
|
// hasSubscribedSources = YES;
|
|
|
|
// }
|
2008-12-17 15:33:14 +01:00
|
|
|
|
2007-09-11 22:14:18 +02:00
|
|
|
- (id) lookupName: (NSString *) name
|
|
|
|
inContext: (WOContext *) lookupContext
|
|
|
|
acquire: (BOOL) acquire
|
|
|
|
{
|
|
|
|
id obj;
|
|
|
|
|
|
|
|
/* first check attributes directly bound to the application */
|
|
|
|
obj = [super lookupName: name inContext: lookupContext acquire: NO];
|
|
|
|
if (!obj)
|
|
|
|
{
|
|
|
|
if (!subFolders)
|
|
|
|
[self initSubFolders];
|
|
|
|
|
|
|
|
obj = [subFolders objectForKey: name];
|
2008-12-17 15:53:16 +01:00
|
|
|
// if (!obj && !hasSubscribedSources)
|
|
|
|
// {
|
|
|
|
// [self _appendSubscribedSourcesIfNeeded];
|
|
|
|
// obj = [subFolders objectForKey: name];
|
|
|
|
// }
|
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
|
|
|
{
|
|
|
|
if (!subFolders)
|
|
|
|
[self initSubFolders];
|
2008-12-17 15:53:16 +01:00
|
|
|
// if (!!hasSubscribedSources)
|
|
|
|
// [self _appendSubscribedSourcesIfNeeded];
|
2007-09-11 22:14:18 +02:00
|
|
|
|
2008-11-24 22:26:36 +01:00
|
|
|
return [[subFolders allValues]
|
|
|
|
sortedArrayUsingSelector: @selector (compare:)];
|
2007-09-11 22:14:18 +02:00
|
|
|
}
|
|
|
|
|
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
|