Added the modifications specified by extrafu

This commit is contained in:
Alexandre Cloutier
2014-03-25 14:53:42 -04:00
parent 76307cfaaf
commit bce701208a
8 changed files with 137 additions and 161 deletions
+6
View File
@@ -51,4 +51,10 @@ typedef enum
EventUpdated = 2,
} SOGoEventOperation;
typedef enum
{
SOGoPersonalFolder = 0,
SOGoCollectedFolder = 1,
} SOGoFolderType;
#endif /* _SOGOCONSTANTS_H_ */
+1
View File
@@ -22,6 +22,7 @@
#define SOGOPARENTFOLDERS_H
#import "SOGoFolder.h"
#import "SOGoConstants.h"
@class NSMutableDictionary;
@class NSString;
+60 -38
View File
@@ -153,9 +153,15 @@ static SoSecurityManager *sm = nil;
return @"Personal";
}
- (void) _createPersonalFolder
- (NSString *) collectedFolderName
{
return @"Collected";
}
- (void) createSpecialFolder: (SOGoFolderType) folderType
{
NSArray *roles;
NSString *folderName;
SOGoGCSFolder *folder;
SOGoUser *folderOwner;
@@ -165,20 +171,32 @@ static SoSecurityManager *sm = nil;
// We autocreate the calendars if the user is the owner, a superuser or
// if it's a resource as we won't necessarily want to login as a resource
// in order to create its database tables.
// FolderType is an Enum where 0 = Personal and 1 = collected
if ([roles containsObject: SoRole_Owner] ||
(folderOwner && [folderOwner isResource]))
{
folder = [subFolderClass objectWithName: @"personal" inContainer: self];
[folder setDisplayName: [self defaultFolderName]];
[folder
setOCSPath: [NSString stringWithFormat: @"%@/personal", OCSPath]];
folder = [subFolderClass objectWithName: folderName inContainer: self];
if (folderType == 0)
{
folderName = @"personal";
[folder setDisplayName: [self defaultFolderName]];
}
else if (folderType == 1)
{
folderName = @"Collected Address Book";
[folder setDisplayName: [self collectedFolderName]];
}
[folder setOCSPath: [NSString stringWithFormat: @"%@/%@", OCSPath, folderName]];
if ([folder create])
[subFolders setObject: folder forKey: @"personal"];
[subFolders setObject: folder forKey: folderName];
}
}
- (NSException *) _fetchPersonalFolders: (NSString *) sql
withChannel: (EOAdaptorChannel *) fc
- (NSException *) fetchSpecialFolders: (NSString *) sql
withChannel: (EOAdaptorChannel *) fc
andFolderType: (SOGoFolderType) folderType
{
NSArray *attrs;
NSDictionary *row;
@@ -191,24 +209,29 @@ static SoSecurityManager *sm = nil;
error = [fc evaluateExpressionX: sql];
if (!error)
{
attrs = [fc describeResults: NO];
while ((row = [fc fetchAttributes: attrs withZone: NULL]))
{
attrs = [fc describeResults: NO];
while ((row = [fc fetchAttributes: attrs withZone: NULL]))
{
key = [row objectForKey: @"c_path4"];
if ([key isKindOfClass: [NSString class]])
{
folder = [subFolderClass objectWithName: key inContainer: self];
[folder setOCSPath: [NSString stringWithFormat: @"%@/%@",
OCSPath, key]];
[subFolders setObject: folder forKey: key];
}
}
if (![subFolders objectForKey: @"personal"])
[self _createPersonalFolder];
key = [row objectForKey: @"c_path4"];
if ([key isKindOfClass: [NSString class]])
{
folder = [subFolderClass objectWithName: key inContainer: self];
[folder setOCSPath: [NSString stringWithFormat: @"%@/%@", OCSPath, key]];
[subFolders setObject: folder forKey: key];
}
}
if (folderType == 0)
{
if (![subFolders objectForKey: @"personal"])
[self createSpecialFolder: SOGoPersonalFolder];
}
else if (folderType == 1)
{
if (![subFolders objectForKey: @"collected"])
[self createSpecialFolder: SOGoCollectedFolder];
}
}
return error;
}
@@ -224,19 +247,18 @@ static SoSecurityManager *sm = nil;
folderLocation = [[GCSFolderManager defaultFolderManager] folderInfoLocation];
fc = [cm acquireOpenChannelForURL: folderLocation];
if ([fc isOpen])
{
gcsFolderType = [[self class] gcsFolderType];
sql = [NSString stringWithFormat: (@"SELECT c_path4 FROM %@"
@" WHERE c_path2 = '%@'"
@" AND c_folder_type = '%@'"),
[folderLocation gcsTableName], owner, gcsFolderType];
error = [self _fetchPersonalFolders: sql withChannel: fc];
[cm releaseChannel: fc];
// sql = [sql stringByAppendingFormat:@" WHERE %@ = '%@'",
// uidColumnName, [self uid]];
}
{
gcsFolderType = [[self class] gcsFolderType];
sql = [NSString stringWithFormat: (@"SELECT c_path4 FROM %@"
@" WHERE c_path2 = '%@'"
@" AND c_folder_type = '%@'"),
[folderLocation gcsTableName], owner, gcsFolderType];
error = [self fetchSpecialFolders: sql withChannel: fc andFolderType: SOGoPersonalFolder];
[cm releaseChannel: fc];
}
else
error = [NSException exceptionWithName: @"SOGoDBException"
reason: @"database connection could not be open"
@@ -384,7 +406,7 @@ static SoSecurityManager *sm = nil;
if (!subFolders)
{
subFolders = [NSMutableDictionary new];
error = [self appendPersonalSources];
error = [self appendPersonalSources];
if (!error)
if ([self respondsToSelector:@selector(appendCollectedSources)])
error = [self appendCollectedSources];