2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004-2005 SKYRIX Software AG
|
|
|
|
|
|
|
|
This file is part of OpenGroupware.org.
|
|
|
|
|
|
|
|
OGo is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
|
|
|
OGo 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 Lesser General Public
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with OGo; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2007-06-18 17:37:37 +02:00
|
|
|
#import <Foundation/NSArray.h>
|
2007-08-15 22:27:32 +02:00
|
|
|
#import <Foundation/NSDate.h>
|
2007-06-18 17:37:37 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#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-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-06-18 17:37:37 +02:00
|
|
|
#import <NGExtensions/NSNull+misc.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
|
|
|
#import <EOControl/EOQualifier.h>
|
2007-04-17 16:30:12 +02:00
|
|
|
#import <GDLAccess/EOAdaptorChannel.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>
|
|
|
|
#import <GDLContentStore/GCSFolderType.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"
|
2007-07-22 22:40:34 +02:00
|
|
|
#import "NSString+Utilities.h"
|
|
|
|
|
2007-09-15 01:16:48 +02:00
|
|
|
#import "SOGoContentObject.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"
|
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-11-07 16:58:43 +01:00
|
|
|
@implementation SOGoGCSFolder
|
2006-06-15 21:34:10 +02: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;
|
2007-11-09 00:04:42 +01:00
|
|
|
NSString *path, *objectPath, *login, *ocsName, *folderName;
|
2007-09-15 00:01:02 +02:00
|
|
|
|
|
|
|
elements = [reference componentsSeparatedByString: @":"];
|
2007-11-08 21:35:09 +01:00
|
|
|
login = [elements objectAtIndex: 0];
|
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];
|
2007-11-08 21:35:09 +01:00
|
|
|
folderName = [NSString stringWithFormat: @"%@_%@", login, 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];
|
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]))
|
|
|
|
{
|
2007-09-11 22:25:57 +02:00
|
|
|
displayName = nil;
|
2007-04-27 21:45:12 +02:00
|
|
|
ocsPath = nil;
|
|
|
|
ocsFolder = nil;
|
|
|
|
aclCache = [NSMutableDictionary new];
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[ocsFolder release];
|
|
|
|
[ocsPath release];
|
|
|
|
[aclCache release];
|
2007-09-11 22:25:57 +02:00
|
|
|
[displayName 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"];
|
|
|
|
displayName = [NSMutableString string];
|
|
|
|
if ([primaryDN isEqualToString: [container defaultFolderName]])
|
|
|
|
[displayName appendString: [self labelForKey: primaryDN]];
|
|
|
|
else
|
|
|
|
[displayName appendString: primaryDN];
|
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
currentLogin = [[context activeUser] login];
|
|
|
|
ownerLogin = [self ownerInContext: context];
|
|
|
|
if (![currentLogin isEqualToString: ownerLogin])
|
|
|
|
{
|
|
|
|
ownerIdentity = [[SOGoUser userWithLogin: ownerLogin roles: nil]
|
|
|
|
primaryIdentity];
|
2007-11-09 00:07:30 +01:00
|
|
|
[displayName
|
|
|
|
appendString: [ownerIdentity keysWithFormat:
|
|
|
|
@" (%{fullName} <%{email}>)"]];
|
2007-09-15 00:01:02 +02:00
|
|
|
}
|
2007-09-17 06:22:59 +02:00
|
|
|
[displayName retain];
|
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-09-15 00:01:02 +02: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"];
|
|
|
|
}
|
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
- (NSString *) davDisplayName
|
|
|
|
{
|
|
|
|
return [self displayName];
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2007-10-22 23:52:13 +02:00
|
|
|
user = [context activeUser];
|
2007-10-14 18:07:22 +02:00
|
|
|
pageName = [NSString stringWithFormat: @"SOGoFolder%@%@Advisory",
|
2007-10-22 23:52:13 +02:00
|
|
|
[user language], template];
|
2007-10-14 18:07:22 +02:00
|
|
|
|
2007-10-22 23:52:13 +02:00
|
|
|
page = [[WOApplication application] pageWithName: pageName
|
|
|
|
inContext: context];
|
2007-10-14 18:07:22 +02:00
|
|
|
[page setFolderObject: self];
|
2007-10-22 23:52:13 +02:00
|
|
|
[page setRecipientUID: [user login]];
|
2007-10-14 18:07:22 +02:00
|
|
|
[page send];
|
|
|
|
}
|
|
|
|
|
2007-10-22 23:52:13 +02:00
|
|
|
// if (!result) [self sendFolderAdvisoryTemplate: @"Addition"];
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
return error;
|
2007-03-21 15:27:04 +01:00
|
|
|
}
|
|
|
|
|
2007-10-22 23:52:13 +02:00
|
|
|
// if (!error) [self sendFolderAdvisoryTemplate: @"Removal"];
|
|
|
|
|
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 = '%@'"),
|
|
|
|
[folderLocation gcsTableName], newName, ocsPath];
|
|
|
|
[fc evaluateExpressionX: sql];
|
|
|
|
[cm releaseChannel: fc];
|
|
|
|
// sql = [sql stringByAppendingFormat:@" WHERE %@ = '%@'",
|
|
|
|
// uidColumnName, [self uid]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-29 23:58:23 +02:00
|
|
|
- (NSArray *) fetchContentObjectNames
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSArray *fields, *records;
|
|
|
|
|
2007-06-29 23:58:23 +02:00
|
|
|
fields = [NSArray arrayWithObject: @"c_name"];
|
2006-06-15 21:34:10 +02:00
|
|
|
records = [[self ocsFolder] fetchFields:fields 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;
|
2007-08-24 22:38:44 +02:00
|
|
|
return [records objectsForKey: @"c_name"];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-08-09 23:32:39 +02:00
|
|
|
|
2007-02-21 22:11:40 +01:00
|
|
|
- (BOOL) nameExistsInFolder: (NSString *) objectName
|
|
|
|
{
|
|
|
|
NSArray *fields, *records;
|
|
|
|
EOQualifier *qualifier;
|
|
|
|
|
|
|
|
qualifier
|
|
|
|
= [EOQualifier qualifierWithQualifierFormat:
|
|
|
|
[NSString stringWithFormat: @"c_name='%@'", objectName]];
|
|
|
|
|
|
|
|
fields = [NSArray arrayWithObject: @"c_name"];
|
|
|
|
records = [[self ocsFolder] fetchFields: fields
|
|
|
|
matchingQualifier: qualifier];
|
|
|
|
return (records
|
|
|
|
&& ![records isKindOfClass:[NSException class]]
|
|
|
|
&& [records count] > 0);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-29 23:58:23 +02:00
|
|
|
- (NSDictionary *) fetchContentStringsAndNamesOfAllObjects
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSDictionary *files;
|
|
|
|
|
|
|
|
files = [[self ocsFolder] fetchContentsOfAllFiles];
|
2007-06-29 23:58:23 +02:00
|
|
|
if (![files isNotNull])
|
|
|
|
{
|
|
|
|
[self errorWithFormat:@"(%s): fetch failed!", __PRETTY_FUNCTION__];
|
|
|
|
return nil;
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
if ([files isKindOfClass:[NSException class]])
|
|
|
|
return files;
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reflection */
|
|
|
|
|
2007-06-29 23:58:23 +02:00
|
|
|
- (NSString *) defaultFilenameExtension
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Override to add an extension to a filename
|
|
|
|
|
|
|
|
Note: be careful with that, needs to be consistent with object lookup!
|
|
|
|
*/
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2007-06-29 23:58:23 +02:00
|
|
|
- (NSArray *) toOneRelationshipKeys
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
/* toOneRelationshipKeys are the 'files' contained in a folder */
|
|
|
|
NSMutableArray *ma;
|
|
|
|
NSArray *names;
|
2006-12-14 22:20:13 +01:00
|
|
|
NSString *name, *ext;
|
2006-06-15 21:34:10 +02:00
|
|
|
unsigned i, count;
|
2006-12-14 22:20:13 +01:00
|
|
|
NSRange r;
|
|
|
|
|
|
|
|
names = [self fetchContentObjectNames];
|
|
|
|
count = [names count];
|
|
|
|
ext = [self defaultFilenameExtension];
|
|
|
|
if (count && [ext length] > 0)
|
|
|
|
{
|
|
|
|
ma = [NSMutableArray arrayWithCapacity: count];
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
name = [names objectAtIndex: i];
|
|
|
|
r = [name rangeOfString: @"."];
|
|
|
|
if (r.length == 0)
|
2007-07-12 17:55:06 +02:00
|
|
|
name = [NSMutableString stringWithFormat: @"%@.%@", name, ext];
|
|
|
|
[ma addObject: name];
|
2006-12-14 22:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
names = ma;
|
|
|
|
}
|
|
|
|
|
|
|
|
return names;
|
2006-06-15 21:34:10 +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;
|
2007-05-19 02:49:05 +02:00
|
|
|
NSArray *records;
|
2007-04-17 16:30:12 +02:00
|
|
|
|
|
|
|
qs = [NSString stringWithFormat: @"c_object = '/%@'",
|
|
|
|
[objectPathArray componentsJoinedByString: @"/"]];
|
|
|
|
qualifier = [EOQualifier qualifierWithQualifierFormat: qs];
|
2007-05-19 02:49:05 +02:00
|
|
|
records = [[self ocsFolder] fetchAclMatchingQualifier: qualifier];
|
2007-04-17 16:30:12 +02:00
|
|
|
|
2007-05-19 02:49:05 +02:00
|
|
|
return [records valueForKey: @"c_uid"];
|
2007-04-17 16:30:12 +02:00
|
|
|
}
|
|
|
|
|
2007-04-27 21:45:12 +02:00
|
|
|
- (NSArray *) _fetchAclsForUser: (NSString *) uid
|
|
|
|
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;
|
|
|
|
|
|
|
|
qs = [NSString stringWithFormat: @"(c_object = '/%@') AND (c_uid = '%@')",
|
2007-04-27 21:45:12 +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];
|
|
|
|
if ([records count] > 0)
|
2007-11-29 17:14:11 +01:00
|
|
|
[acls addObjectsFromArray: [records valueForKey: @"c_role"]];
|
2007-04-26 03:16:19 +02:00
|
|
|
|
|
|
|
return acls;
|
2007-04-17 16:30:12 +02:00
|
|
|
}
|
|
|
|
|
2007-04-27 21:45:12 +02:00
|
|
|
- (void) _cacheRoles: (NSArray *) roles
|
|
|
|
forUser: (NSString *) uid
|
|
|
|
forObjectAtPath: (NSString *) objectPath
|
|
|
|
{
|
|
|
|
NSMutableDictionary *aclsForObject;
|
|
|
|
|
|
|
|
aclsForObject = [aclCache objectForKey: objectPath];
|
|
|
|
if (!aclsForObject)
|
|
|
|
{
|
|
|
|
aclsForObject = [NSMutableDictionary dictionary];
|
|
|
|
[aclCache setObject: aclsForObject
|
|
|
|
forKey: objectPath];
|
|
|
|
}
|
|
|
|
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];
|
|
|
|
[self _cacheRoles: acls forUser: uid forObjectAtPath: objectPath];
|
|
|
|
}
|
|
|
|
|
2007-05-22 20:35:17 +02:00
|
|
|
if (!([acls count] || [uid isEqualToString: defaultUserID]))
|
|
|
|
acls = [self aclsForUser: defaultUserID
|
2007-05-18 01:09:46 +02:00
|
|
|
forObjectAtPath: objectPathArray];
|
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;
|
2007-04-27 21:45:12 +02:00
|
|
|
NSString *uids, *qs, *objectPath;
|
|
|
|
NSMutableDictionary *aclsForObject;
|
2007-04-17 16:30:12 +02:00
|
|
|
|
|
|
|
if ([users count] > 0)
|
|
|
|
{
|
2007-04-27 21:45:12 +02:00
|
|
|
objectPath = [objectPathArray componentsJoinedByString: @"/"];
|
|
|
|
aclsForObject = [aclCache objectForKey: objectPath];
|
|
|
|
if (aclsForObject)
|
|
|
|
[aclsForObject removeObjectsForKeys: users];
|
2007-04-17 16:30:12 +02:00
|
|
|
uids = [users componentsJoinedByString: @"') OR (c_uid = '"];
|
|
|
|
qs = [NSString
|
|
|
|
stringWithFormat: @"(c_object = '/%@') AND ((c_uid = '%@'))",
|
2007-04-27 21:45:12 +02:00
|
|
|
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
|
|
|
|
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];
|
2007-04-25 00:45:38 +02:00
|
|
|
userRoles = [roles objectEnumerator];
|
|
|
|
currentRole = [userRoles nextObject];
|
|
|
|
while (currentRole)
|
|
|
|
{
|
2007-05-18 01:09:46 +02:00
|
|
|
SQL = [NSString stringWithFormat: @"INSERT INTO %@"
|
|
|
|
@" (c_object, c_uid, c_role)"
|
|
|
|
@" VALUES ('/%@', '%@', '%@')",
|
|
|
|
[folder aclTableName],
|
|
|
|
objectPath, uid, currentRole];
|
|
|
|
[channel evaluateExpressionX: SQL];
|
2007-04-25 00:45:38 +02:00
|
|
|
currentRole = [userRoles nextObject];
|
|
|
|
}
|
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
|
|
|
|
{
|
|
|
|
NSString *objectPath;
|
|
|
|
NSMutableArray *newRoles;
|
|
|
|
|
|
|
|
[self removeAclsForUsers: [NSArray arrayWithObject: uid]
|
|
|
|
forObjectAtPath: objectPathArray];
|
|
|
|
|
|
|
|
newRoles = [NSMutableArray arrayWithArray: roles];
|
|
|
|
[newRoles removeObject: SOGoRole_AuthorizedSubscriber];
|
|
|
|
[newRoles removeObject: SOGoRole_None];
|
|
|
|
objectPath = [objectPathArray componentsJoinedByString: @"/"];
|
|
|
|
[self _cacheRoles: newRoles forUser: uid
|
|
|
|
forObjectAtPath: objectPath];
|
|
|
|
if (![newRoles count])
|
|
|
|
[newRoles addObject: SOGoRole_None];
|
|
|
|
|
|
|
|
[self _commitRoles: newRoles forUID: uid forObject: objectPath];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2007-09-15 00:01:02 +02:00
|
|
|
return [self aclUsersForObjectAtPath: [self pathArrayToSOGoObject]];
|
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];
|
|
|
|
ownAcls = [self aclsForUser: uid
|
2007-09-15 00:01:02 +02:00
|
|
|
forObjectAtPath: [self pathArrayToSOGoObject]];
|
2007-06-01 23:03:50 +02:00
|
|
|
[acls addObjectsFromArray: ownAcls];
|
|
|
|
if ([container respondsToSelector: @selector (aclsForUser:)])
|
|
|
|
{
|
|
|
|
containerAcls = [container aclsForUser: uid];
|
|
|
|
if ([containerAcls count] > 0)
|
|
|
|
{
|
|
|
|
#warning this should be checked
|
|
|
|
if ([containerAcls containsObject: SOGoRole_ObjectEraser])
|
|
|
|
[acls addObject: SOGoRole_ObjectEraser];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
forUser: uid
|
2007-09-15 00:01:02 +02:00
|
|
|
forObjectAtPath: [self pathArrayToSOGoObject]];
|
2007-04-17 16:30:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) removeAclsForUsers: (NSArray *) users
|
|
|
|
{
|
|
|
|
return [self removeAclsForUsers: users
|
2007-09-15 00:01:02 +02:00
|
|
|
forObjectAtPath: [self pathArrayToSOGoObject]];
|
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];
|
|
|
|
|
|
|
|
[_ms appendFormat:@" ocs=%@", [self ocsPath]];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end /* SOGoFolder */
|