mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-03-24 07:32:44 +00:00
Monotone-Parent: 530d53ab46bac6f4062942cdd798d31ee1fead30
Monotone-Revision: efaf360dc10f7786b1f239ecc561285c21d9be1a Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-09-11T20:17:39 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
2007-09-11 Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
|
||||
* SoObjects/Contacts/SOGoContactFolders.[hm]: modified class to be
|
||||
a subclass of SOGoParentFolder.
|
||||
|
||||
* SoObjects/SOGo/SOGoParentFolder.[hm]: new class module derived
|
||||
from SOGoContactFolders and modified to be more content-independent.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* SOGoContactFolders.h - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2006 Inverse groupe conseil
|
||||
* Copyright (C) 2006, 2007 Inverse groupe conseil
|
||||
*
|
||||
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
*
|
||||
@@ -23,25 +23,9 @@
|
||||
#ifndef SOGOCONTACTFOLDERS_H
|
||||
#define SOGOCONTACTFOLDERS_H
|
||||
|
||||
#import <SOGo/SOGoObject.h>
|
||||
#import <SoObjects/SOGo/SOGoParentFolder.h>
|
||||
|
||||
@class NSMutableDictionary;
|
||||
@class NSString;
|
||||
@class WOResponse;
|
||||
|
||||
@interface SOGoContactFolders : SOGoObject
|
||||
{
|
||||
NSMutableDictionary *contactFolders;
|
||||
NSString *OCSPath;
|
||||
}
|
||||
|
||||
- (NSString *) defaultSourceName;
|
||||
|
||||
- (void) setBaseOCSPath: (NSString *) newOCSPath;
|
||||
|
||||
- (NSArray *) contactFolders;
|
||||
|
||||
- (WOResponse *) newFolderWithName: (NSString *) name;
|
||||
@interface SOGoContactFolders : SOGoParentFolder
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* SOGoContactFolders.m - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2006 Inverse groupe conseil
|
||||
* Copyright (C) 2006, 2007 Inverse groupe conseil
|
||||
*
|
||||
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
*
|
||||
@@ -20,7 +20,6 @@
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* exchange folder types: */
|
||||
/* MailItems IPF.Note
|
||||
ContactItems IPF.Contact
|
||||
AppointmentItems IPF.Appointment
|
||||
@@ -28,23 +27,25 @@
|
||||
TaskItems IPF.Task
|
||||
JournalItems IPF.Journal */
|
||||
|
||||
#import <Foundation/NSDictionary.h>
|
||||
// #import <Foundation/NSDictionary.h>
|
||||
#import <Foundation/NSArray.h>
|
||||
#import <Foundation/NSString.h>
|
||||
#import <Foundation/NSEnumerator.h>
|
||||
|
||||
#import <NGObjWeb/NSException+HTTP.h>
|
||||
#import <NGObjWeb/WOApplication.h>
|
||||
#import <NGObjWeb/WOContext.h>
|
||||
#import <NGObjWeb/WOContext+SoObjects.h>
|
||||
#import <NGObjWeb/WOResponse.h>
|
||||
#import <NGObjWeb/SoUser.h>
|
||||
// #import <NGObjWeb/NSException+HTTP.h>
|
||||
// #import <NGObjWeb/WOApplication.h>
|
||||
// #import <NGObjWeb/WOContext.h>
|
||||
// #import <NGObjWeb/WOContext+SoObjects.h>
|
||||
// #import <NGObjWeb/WOResponse.h>
|
||||
// #import <NGObjWeb/SoUser.h>
|
||||
|
||||
#import <GDLContentStore/GCSFolderManager.h>
|
||||
#import <GDLContentStore/GCSChannelManager.h>
|
||||
#import <GDLAccess/EOAdaptorChannel.h>
|
||||
#import <GDLContentStore/NSURL+GCS.h>
|
||||
// #import <GDLContentStore/GCSFolderManager.h>
|
||||
// #import <GDLContentStore/GCSChannelManager.h>
|
||||
// #import <GDLAccess/EOAdaptorChannel.h>
|
||||
// #import <GDLContentStore/NSURL+GCS.h>
|
||||
|
||||
#import <SoObjects/SOGo/LDAPUserManager.h>
|
||||
#import <SoObjects/SOGo/SOGoPermissions.h>
|
||||
// #import <SoObjects/SOGo/SOGoPermissions.h>
|
||||
|
||||
#import "SOGoContactGCSFolder.h"
|
||||
#import "SOGoContactLDAPFolder.h"
|
||||
@@ -52,89 +53,14 @@
|
||||
|
||||
@implementation SOGoContactFolders
|
||||
|
||||
- (id) init
|
||||
+ (NSString *) gcsFolderType
|
||||
{
|
||||
if ((self = [super init]))
|
||||
{
|
||||
contactFolders = nil;
|
||||
OCSPath = nil;
|
||||
}
|
||||
|
||||
return self;
|
||||
return @"Contact";
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
+ (Class) subFolderClass
|
||||
{
|
||||
if (contactFolders)
|
||||
[contactFolders release];
|
||||
if (OCSPath)
|
||||
[OCSPath release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void) _fetchPersonalFolders: (NSString *) sql
|
||||
withChannel: (EOAdaptorChannel *) fc
|
||||
{
|
||||
NSArray *attrs;
|
||||
NSDictionary *row;
|
||||
SOGoContactGCSFolder *ab;
|
||||
BOOL hasPersonal;
|
||||
NSString *key, *path;
|
||||
|
||||
hasPersonal = NO;
|
||||
[fc evaluateExpressionX: sql];
|
||||
attrs = [fc describeResults: NO];
|
||||
row = [fc fetchAttributes: attrs withZone: NULL];
|
||||
while (row)
|
||||
{
|
||||
ab = [SOGoContactGCSFolder
|
||||
contactFolderWithName: [row objectForKey: @"c_path4"]
|
||||
andDisplayName: [row objectForKey: @"c_foldername"]
|
||||
inContainer: self];
|
||||
key = [row objectForKey: @"c_path4"];
|
||||
hasPersonal = (hasPersonal || [key isEqualToString: @"personal"]);
|
||||
[ab setOCSPath: [NSString stringWithFormat: @"%@/%@",
|
||||
OCSPath, key]];
|
||||
[contactFolders setObject: ab forKey: key];
|
||||
row = [fc fetchAttributes: attrs withZone: NULL];
|
||||
}
|
||||
|
||||
if (!hasPersonal)
|
||||
{
|
||||
ab = [SOGoContactGCSFolder contactFolderWithName: @"personal"
|
||||
andDisplayName: @"Contacts"
|
||||
inContainer: self];
|
||||
path = [NSString stringWithFormat:
|
||||
@"/Users/%@/Contacts/personal",
|
||||
[self ownerInContext: context]];
|
||||
[ab setOCSPath: path];
|
||||
[contactFolders setObject: ab forKey: @"personal"];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) appendPersonalSources
|
||||
{
|
||||
GCSChannelManager *cm;
|
||||
EOAdaptorChannel *fc;
|
||||
NSURL *folderLocation;
|
||||
NSString *sql;
|
||||
|
||||
cm = [GCSChannelManager defaultChannelManager];
|
||||
folderLocation
|
||||
= [[GCSFolderManager defaultFolderManager] folderInfoLocation];
|
||||
fc = [cm acquireOpenChannelForURL: folderLocation];
|
||||
if (fc)
|
||||
{
|
||||
sql = [NSString
|
||||
stringWithFormat: (@"SELECT c_path4, c_foldername FROM %@"
|
||||
@" WHERE c_path2 = '%@'"
|
||||
@" AND c_folder_type = 'Contact'"),
|
||||
[folderLocation gcsTableName], [self ownerInContext: context]];
|
||||
[self _fetchPersonalFolders: sql withChannel: fc];
|
||||
[cm releaseChannel: fc];
|
||||
// sql = [sql stringByAppendingFormat:@" WHERE %@ = '%@'",
|
||||
// uidColumnName, [self uid]];
|
||||
}
|
||||
return [SOGoContactGCSFolder class];
|
||||
}
|
||||
|
||||
- (void) appendSystemSources
|
||||
@@ -150,119 +76,13 @@
|
||||
while (currentSourceID)
|
||||
{
|
||||
displayName = [um displayNameForSourceWithID: currentSourceID];
|
||||
currentFolder = [SOGoContactLDAPFolder contactFolderWithName: currentSourceID
|
||||
currentFolder = [SOGoContactLDAPFolder folderWithName: currentSourceID
|
||||
andDisplayName: displayName
|
||||
inContainer: self];
|
||||
[currentFolder setLDAPSource: [um sourceWithID: currentSourceID]];
|
||||
[contactFolders setObject: currentFolder forKey: currentSourceID];
|
||||
[subFolders setObject: currentFolder forKey: currentSourceID];
|
||||
currentSourceID = [sourceIDs nextObject];
|
||||
}
|
||||
}
|
||||
|
||||
- (WOResponse *) newFolderWithName: (NSString *) name
|
||||
{
|
||||
SOGoContactGCSFolder *newFolder;
|
||||
WOResponse *response;
|
||||
|
||||
newFolder = [SOGoContactGCSFolder contactFolderWithName: name
|
||||
andDisplayName: name
|
||||
inContainer: self];
|
||||
if ([newFolder isKindOfClass: [NSException class]])
|
||||
response = (WOResponse *) newFolder;
|
||||
else
|
||||
{
|
||||
[newFolder setOCSPath: [NSString stringWithFormat: @"%@/%@",
|
||||
OCSPath, name]];
|
||||
if ([newFolder create])
|
||||
{
|
||||
response = [WOResponse new];
|
||||
[response setStatus: 201];
|
||||
[response autorelease];
|
||||
}
|
||||
else
|
||||
response = [NSException exceptionWithHTTPStatus: 400
|
||||
reason: @"The new folder could not be created"];
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
- (void) initContactSources
|
||||
{
|
||||
if (!contactFolders)
|
||||
{
|
||||
contactFolders = [NSMutableDictionary new];
|
||||
[self appendPersonalSources];
|
||||
[self appendSystemSources];
|
||||
}
|
||||
}
|
||||
|
||||
- (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 (!contactFolders)
|
||||
[self initContactSources];
|
||||
|
||||
obj = [contactFolders objectForKey: name];
|
||||
if (!obj)
|
||||
obj = [NSException exceptionWithHTTPStatus: 404];
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
- (NSArray *) toManyRelationshipKeys
|
||||
{
|
||||
if (!contactFolders)
|
||||
[self initContactSources];
|
||||
|
||||
return [contactFolders allKeys];
|
||||
}
|
||||
|
||||
- (NSArray *) contactFolders
|
||||
{
|
||||
if (!contactFolders)
|
||||
[self initContactSources];
|
||||
|
||||
return [contactFolders allValues];
|
||||
}
|
||||
|
||||
/* acls */
|
||||
- (NSArray *) aclsForUser: (NSString *) uid
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (BOOL) davIsCollection
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSString *) davContentType
|
||||
{
|
||||
return @"httpd/unix-directory";
|
||||
}
|
||||
|
||||
- (void) setBaseOCSPath: (NSString *) newOCSPath
|
||||
{
|
||||
if (OCSPath)
|
||||
[OCSPath release];
|
||||
OCSPath = newOCSPath;
|
||||
if (OCSPath)
|
||||
[OCSPath retain];
|
||||
}
|
||||
|
||||
/* web interface */
|
||||
- (NSString *) defaultSourceName
|
||||
{
|
||||
return @"personal";
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user