From 7d6d5aa0fcc01c73f3cec67bd3815a8165cf371e Mon Sep 17 00:00:00 2001 From: helge Date: Mon, 15 Jan 2007 19:15:46 +0000 Subject: [PATCH] added ACL support git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1400 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-gdl1/GDLContentStore/ChangeLog | 5 + sope-gdl1/GDLContentStore/GCSFolder.h | 9 +- sope-gdl1/GDLContentStore/GCSFolder.m | 114 ++++++++++++++++++- sope-gdl1/GDLContentStore/GCSFolderManager.m | 12 +- sope-gdl1/GDLContentStore/Version | 2 +- 5 files changed, 135 insertions(+), 7 deletions(-) diff --git a/sope-gdl1/GDLContentStore/ChangeLog b/sope-gdl1/GDLContentStore/ChangeLog index b7826499..f5fec6eb 100644 --- a/sope-gdl1/GDLContentStore/ChangeLog +++ b/sope-gdl1/GDLContentStore/ChangeLog @@ -1,3 +1,8 @@ +2007-01-15 Wolfgang Sourdeau + + * GCSFolder.[hm], GCSFolderManager.m: added support for content table + ACLs (v4.5.38) + 2006-08-31 Wolfgang Sourdeau * EOQualifier+GCS.m: added support for OR qualifiers and for case diff --git a/sope-gdl1/GDLContentStore/GCSFolder.h b/sope-gdl1/GDLContentStore/GCSFolder.h index 3fe9cd38..6abd810d 100644 --- a/sope-gdl1/GDLContentStore/GCSFolder.h +++ b/sope-gdl1/GDLContentStore/GCSFolder.h @@ -1,5 +1,6 @@ /* - Copyright (C) 2004-2005 SKYRIX Software AG + Copyright (C) 2004-2007 SKYRIX Software AG + Copyright (C) 2007 Helge Hess This file is part of OpenGroupware.org. @@ -54,6 +55,7 @@ NSString *path; NSURL *location; NSURL *quickLocation; + NSURL *aclLocation; NSString *folderTypeName; struct { @@ -66,6 +68,7 @@ - (id)initWithPath:(NSString *)_path primaryKey:(id)_folderId folderTypeName:(NSString *)_ftname folderType:(GCSFolderType *)_ftype location:(NSURL *)_loc quickLocation:(NSURL *)_qloc + aclLocation: (NSURL *)_aloc folderManager:(GCSFolderManager *)_fm; /* accessors */ @@ -75,6 +78,7 @@ - (NSString *)path; - (NSURL *)location; - (NSURL *)quickLocation; +- (NSURL *)aclLocation; - (NSString *)folderTypeName; - (GCSFolderManager *)folderManager; @@ -82,12 +86,14 @@ - (NSString *)storeTableName; - (NSString *)quickTableName; +- (NSString *)aclTableName; - (BOOL)isQuickInfoStoredInContentTable; /* connection */ - (EOAdaptorChannel *)acquireStoreChannel; - (EOAdaptorChannel *)acquireQuickChannel; +- (EOAdaptorChannel *)acquireAclChannel; - (void)releaseChannel:(EOAdaptorChannel *)_channel; - (BOOL)canConnectStore; @@ -111,6 +117,7 @@ - (NSArray *)fetchFields:(NSArray *)_flds fetchSpecification:(EOFetchSpecification *)_fs; - (NSArray *)fetchFields:(NSArray *)_flds matchingQualifier:(EOQualifier *)_q; +- (NSArray *)fetchAclMatchingQualifier:(EOQualifier *)_q; @end diff --git a/sope-gdl1/GDLContentStore/GCSFolder.m b/sope-gdl1/GDLContentStore/GCSFolder.m index b4c1647c..31dfae7c 100644 --- a/sope-gdl1/GDLContentStore/GCSFolder.m +++ b/sope-gdl1/GDLContentStore/GCSFolder.m @@ -1,5 +1,6 @@ /* - Copyright (C) 2004-2005 SKYRIX Software AG + Copyright (C) 2004-2007 SKYRIX Software AG + Copyright (C) 2007 Helge Hess This file is part of OpenGroupware.org. @@ -57,6 +58,7 @@ static GCSStringFormatter *stringFormatter = nil; - (id)initWithPath:(NSString *)_path primaryKey:(id)_folderId folderTypeName:(NSString *)_ftname folderType:(GCSFolderType *)_ftype location:(NSURL *)_loc quickLocation:(NSURL *)_qloc + aclLocation:(NSURL *)_aloc folderManager:(GCSFolderManager *)_fm { if (![_loc isNotNull]) { @@ -75,8 +77,9 @@ static GCSStringFormatter *stringFormatter = nil; self->path = [_path copy]; self->location = [_loc retain]; self->quickLocation = _qloc ? [_qloc retain] : [_loc retain]; + self->aclLocation = [_aloc retain]; self->folderTypeName = [_ftname copy]; - + self->ofFlags.requiresFolderSelect = 0; self->ofFlags.sameTableForQuick = [self->location isEqualTo:self->quickLocation] ? 1 : 0; @@ -87,8 +90,19 @@ static GCSStringFormatter *stringFormatter = nil; return [self initWithPath:nil primaryKey:nil folderTypeName:nil folderType:nil location:nil quickLocation:nil + aclLocation:nil folderManager:nil]; } +- (id)initWithPath:(NSString *)_path primaryKey:(id)_folderId + folderTypeName:(NSString *)_ftname folderType:(GCSFolderType *)_ftype + location:(NSURL *)_loc quickLocation:(NSURL *)_qloc + folderManager:(GCSFolderManager *)_fm +{ + return [self initWithPath:_path primaryKey:_folderId folderTypeName:_ftname + folderType:_ftype location:_loc quickLocation:_qloc + aclLocation:nil + folderManager:_fm]; +} - (void)dealloc { [self->folderManager release]; @@ -98,6 +112,7 @@ static GCSStringFormatter *stringFormatter = nil; [self->path release]; [self->location release]; [self->quickLocation release]; + [self->aclLocation release]; [self->folderTypeName release]; [super dealloc]; } @@ -121,6 +136,9 @@ static GCSStringFormatter *stringFormatter = nil; - (NSURL *)quickLocation { return self->quickLocation; } +- (NSURL *)aclLocation { + return self->aclLocation; +} - (NSString *)folderTypeName { return self->folderTypeName; @@ -139,6 +157,9 @@ static GCSStringFormatter *stringFormatter = nil; - (NSString *)quickTableName { return [[self quickLocation] gcsTableName]; } +- (NSString *)aclTableName { + return [[self aclLocation] gcsTableName]; +} - (BOOL)isQuickInfoStoredInContentTable { return self->ofFlags.sameTableForQuick ? YES : NO; @@ -152,6 +173,9 @@ static GCSStringFormatter *stringFormatter = nil; - (EOAdaptorChannel *)acquireQuickChannel { return [[self channelManager] acquireOpenChannelForURL:[self quickLocation]]; } +- (EOAdaptorChannel *)acquireAclChannel { + return [[self channelManager] acquireOpenChannelForURL:[self aclLocation]]; +} - (void)releaseChannel:(EOAdaptorChannel *)_channel { [[self channelManager] releaseChannel:_channel]; @@ -164,6 +188,9 @@ static GCSStringFormatter *stringFormatter = nil; - (BOOL)canConnectQuick { return [[self channelManager] canConnect:[self quickLocation]]; } +- (BOOL)canConnectAcl { + return [[self channelManager] canConnect:[self quickLocation]]; +} /* errors */ @@ -826,6 +853,89 @@ static GCSStringFormatter *stringFormatter = nil; return [self fetchFields:_flds fetchSpecification:fs]; } +- (NSArray *)fetchAclWithSpecification:(EOFetchSpecification *)_fs +{ + EOQualifier *qualifier; + NSArray *sortOrderings; + EOAdaptorChannel *channel; + NSException *error; + NSMutableString *sql; + NSArray *attrs; + NSMutableArray *results; + NSDictionary *row; + + qualifier = [_fs qualifier]; + sortOrderings = [_fs sortOrderings]; + +#if 0 + [self logWithFormat:@"FETCH: %@", _flds]; + [self logWithFormat:@" MATCH: %@", _q]; +#endif + + /* generate SQL */ + + sql = [NSMutableString stringWithCapacity:256]; + [sql appendString:@"SELECT c_uid, c_object, c_role"]; + [sql appendString:@" FROM "]; + [sql appendString:[self aclTableName]]; + + if (qualifier != nil) { + [sql appendString:@" WHERE "]; + [sql appendString:[self generateSQLForQualifier:qualifier]]; + } + if ([sortOrderings count] > 0) { + [sql appendString:@" ORDER BY "]; + [sql appendString:[self generateSQLForSortOrderings:sortOrderings]]; + } +#if 0 + /* limit */ + [sql appendString:@" LIMIT "]; // count + [sql appendString:@" OFFSET "]; // index from 0 +#endif + + /* open channel */ + + if ((channel = [self acquireAclChannel]) == nil) { + [self logWithFormat:@"ERROR(%s): could not open acl channel!"]; + return nil; + } + + /* run SQL */ + + if ((error = [channel evaluateExpressionX:sql]) != nil) { + [self logWithFormat:@"ERROR(%s): cannot execute acl-fetch SQL '%@': %@", + __PRETTY_FUNCTION__, sql, error]; + [self releaseChannel:channel]; + return nil; + } + + /* fetch results */ + + results = [NSMutableArray arrayWithCapacity:64]; + attrs = [channel describeResults:NO /* do not beautify names */]; + while ((row = [channel fetchAttributes:attrs withZone:NULL]) != nil) + [results addObject:row]; + + /* release channels */ + + [self releaseChannel:channel]; + + return results; +} +- (NSArray *) fetchAclMatchingQualifier:(EOQualifier *)_q { + EOFetchSpecification *fs; + + if (_q == nil) + fs = nil; + else { + fs = [EOFetchSpecification fetchSpecificationWithEntityName: + [self folderName] + qualifier:_q + sortOrderings:nil]; + } + return [self fetchAclWithSpecification:fs]; +} + /* description */ - (NSString *)description { diff --git a/sope-gdl1/GDLContentStore/GCSFolderManager.m b/sope-gdl1/GDLContentStore/GCSFolderManager.m index 68c9a9dc..3d1adeff 100644 --- a/sope-gdl1/GDLContentStore/GCSFolderManager.m +++ b/sope-gdl1/GDLContentStore/GCSFolderManager.m @@ -229,7 +229,7 @@ static const char *GCSPathColumnPattern = "c_path%i"; GCSFolderType *folderType; NSString *folderTypeName, *locationString, *folderName, *path; NSNumber *folderId; - NSURL *location, *quickLocation; + NSURL *location, *quickLocation, *aclLocation; if (_record == nil) return nil; @@ -270,11 +270,17 @@ static const char *GCSPathColumnPattern = "c_path%i"; [self logWithFormat:@"WARNING(%s): missing quick location in record: %@", __PRETTY_FUNCTION__, _record]; } + + locationString = [_record objectForKey:@"c_acl_location"]; + aclLocation = [locationString isNotNull] + ? [NSURL URLWithString:locationString] + : nil; folder = [[GCSFolder alloc] initWithPath:path primaryKey:folderId folderTypeName:folderTypeName folderType:folderType location:location quickLocation:quickLocation + aclLocation:aclLocation folderManager:self]; return [folder autorelease]; } @@ -561,8 +567,8 @@ static const char *GCSPathColumnPattern = "c_path%i"; [sql appendString:@"SELECT "]; [sql appendString:@"c_folder_id, "]; [sql appendString:@"c_path, "]; - [sql appendString:@"c_location, c_quick_location, "]; - [sql appendString:@"c_folder_type"]; + [sql appendString:@"c_location, c_quick_location, c_acl_location,"]; + [sql appendString:@" c_folder_type"]; [sql appendString:@" FROM "]; [sql appendString:[self folderInfoTableName]]; [sql appendString:@" WHERE "]; diff --git a/sope-gdl1/GDLContentStore/Version b/sope-gdl1/GDLContentStore/Version index cc3cbaec..5d9ca27c 100644 --- a/sope-gdl1/GDLContentStore/Version +++ b/sope-gdl1/GDLContentStore/Version @@ -2,7 +2,7 @@ MAJOR_VERSION:=4 MINOR_VERSION:=5 -SUBMINOR_VERSION:=37 +SUBMINOR_VERSION:=38 # v4.5.29 requires libNGExtensions v4.5.161 # v4.5.26 does not require libNGiCal anymore -- 2.39.5