2006-08-05 00:46:19 +02:00
|
|
|
/* SOGoContactFolders.m - this file is part of SOGo
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Inverse groupe conseil
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2006-08-09 23:31:28 +02:00
|
|
|
/* exchange folder types: */
|
|
|
|
/* MailItems IPF.Note
|
|
|
|
ContactItems IPF.Contact
|
|
|
|
AppointmentItems IPF.Appointment
|
|
|
|
NoteItems IPF.StickyNote
|
|
|
|
TaskItems IPF.Task
|
|
|
|
JournalItems IPF.Journal */
|
|
|
|
|
2006-08-05 00:46:19 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
|
|
|
|
#import <NGObjWeb/WOApplication.h>
|
|
|
|
#import <NGObjWeb/WOContext.h>
|
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
|
|
|
#import <NGObjWeb/SoUser.h>
|
|
|
|
|
2007-02-09 22:18:28 +01:00
|
|
|
#import <GDLContentStore/GCSFolderManager.h>
|
|
|
|
#import <GDLContentStore/GCSChannelManager.h>
|
|
|
|
#import <GDLAccess/EOAdaptorChannel.h>
|
|
|
|
#import <GDLContentStore/NSURL+GCS.h>
|
|
|
|
|
2006-12-15 23:18:55 +01:00
|
|
|
#import <SoObjects/SOGo/SOGoPermissions.h>
|
|
|
|
|
2006-08-05 00:46:19 +02:00
|
|
|
#import "common.h"
|
|
|
|
|
2006-08-09 23:31:28 +02:00
|
|
|
#import "SOGoContactGCSFolder.h"
|
|
|
|
#import "SOGoContactLDAPFolder.h"
|
2006-08-05 00:46:19 +02:00
|
|
|
#import "SOGoContactFolders.h"
|
|
|
|
|
|
|
|
@implementation SOGoContactFolders
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
2006-08-09 23:31:28 +02:00
|
|
|
contactFolders = nil;
|
2006-08-05 00:46:19 +02:00
|
|
|
OCSPath = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2006-08-09 23:31:28 +02:00
|
|
|
if (contactFolders)
|
|
|
|
[contactFolders release];
|
2006-08-05 00:46:19 +02:00
|
|
|
if (OCSPath)
|
|
|
|
[OCSPath release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) appendPersonalSourcesInContext: (WOContext *) context;
|
|
|
|
{
|
2006-08-09 23:31:28 +02:00
|
|
|
SOGoContactGCSFolder *ab;
|
2007-02-09 22:18:28 +01:00
|
|
|
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_path4, c_foldername FROM %@"
|
|
|
|
@" WHERE c_path2 = '%@' AND c_folder_type = 'Contact'",
|
|
|
|
[folderLocation gcsTableName],
|
|
|
|
[self ownerInContext: nil]];
|
|
|
|
[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];
|
|
|
|
[ab setOCSPath: [NSString stringWithFormat: @"%@/%@",
|
|
|
|
OCSPath, [row objectForKey: @"c_path4"]]];
|
|
|
|
[contactFolders setObject: ab forKey: [row objectForKey: @"c_path4"]];
|
|
|
|
row = [fc fetchAttributes: attrs withZone: NULL];
|
|
|
|
}
|
|
|
|
|
2007-02-09 23:46:18 +01:00
|
|
|
[cm releaseChannel: fc];
|
2007-02-09 22:18:28 +01:00
|
|
|
// sql = [sql stringByAppendingFormat:@" WHERE %@ = '%@'",
|
|
|
|
// uidColumnName, [self uid]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) newFolderWithName: (NSString *) name
|
|
|
|
{
|
|
|
|
SOGoContactGCSFolder *newFolder;
|
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
newFolder = [SOGoContactGCSFolder contactFolderWithName: name
|
|
|
|
andDisplayName: name
|
|
|
|
inContainer: [self clientObject]];
|
|
|
|
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"];
|
|
|
|
}
|
2006-08-09 23:31:28 +02:00
|
|
|
|
2007-02-09 22:18:28 +01:00
|
|
|
return response;
|
2006-08-05 00:46:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) appendSystemSourcesInContext: (WOContext *) context;
|
|
|
|
{
|
2006-08-09 23:31:28 +02:00
|
|
|
NSUserDefaults *ud;
|
|
|
|
NSEnumerator *ldapABs;
|
|
|
|
NSDictionary *udAB;
|
|
|
|
SOGoContactLDAPFolder *ab;
|
|
|
|
|
|
|
|
ud = [NSUserDefaults standardUserDefaults];
|
|
|
|
ldapABs = [[ud objectForKey: @"SOGoLDAPAddressBooks"] objectEnumerator];
|
|
|
|
udAB = [ldapABs nextObject];
|
|
|
|
while (udAB)
|
|
|
|
{
|
|
|
|
ab = [SOGoContactLDAPFolder contactFolderWithName:
|
|
|
|
[udAB objectForKey: @"id"]
|
|
|
|
andDisplayName:
|
|
|
|
[udAB objectForKey: @"displayName"]
|
|
|
|
inContainer: self];
|
|
|
|
[ab LDAPSetHostname: [udAB objectForKey: @"hostname"]
|
|
|
|
setPort: [[udAB objectForKey: @"port"] intValue]
|
|
|
|
setBindDN: [udAB objectForKey: @"bindDN"]
|
|
|
|
setBindPW: [udAB objectForKey: @"bindPW"]
|
|
|
|
setContactIdentifier: [udAB objectForKey: @"idField"]
|
2006-08-14 22:36:36 +02:00
|
|
|
setUserIdentifier: [udAB objectForKey: @"userIdField"]
|
2006-08-09 23:31:28 +02:00
|
|
|
setRootDN: [udAB objectForKey: @"rootDN"]];
|
|
|
|
[contactFolders setObject: ab forKey: [udAB objectForKey: @"id"]];
|
|
|
|
udAB = [ldapABs nextObject];
|
|
|
|
}
|
2006-08-05 00:46:19 +02:00
|
|
|
}
|
|
|
|
|
2007-04-11 21:08:58 +02:00
|
|
|
- (void) initContactSources
|
2006-08-05 00:46:19 +02:00
|
|
|
{
|
2006-08-09 23:31:28 +02:00
|
|
|
if (!contactFolders)
|
2006-08-05 00:46:19 +02:00
|
|
|
{
|
2006-08-09 23:31:28 +02:00
|
|
|
contactFolders = [NSMutableDictionary new];
|
2006-08-05 00:46:19 +02:00
|
|
|
[self appendPersonalSourcesInContext: context];
|
|
|
|
[self appendSystemSourcesInContext: context];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) lookupName: (NSString *) name
|
2007-04-11 21:08:58 +02:00
|
|
|
inContext: (WOContext *) lookupContext
|
2006-08-05 00:46:19 +02:00
|
|
|
acquire: (BOOL) acquire
|
|
|
|
{
|
|
|
|
id obj;
|
2006-08-09 23:31:28 +02:00
|
|
|
id folder;
|
2006-08-05 00:46:19 +02:00
|
|
|
|
|
|
|
/* first check attributes directly bound to the application */
|
2007-04-11 21:08:58 +02:00
|
|
|
obj = [super lookupName: name inContext: lookupContext acquire: NO];
|
2006-08-05 00:46:19 +02:00
|
|
|
if (!obj)
|
|
|
|
{
|
2006-08-09 23:31:28 +02:00
|
|
|
if (!contactFolders)
|
2007-04-11 21:08:58 +02:00
|
|
|
[self initContactSources];
|
2006-08-05 00:46:19 +02:00
|
|
|
|
2006-08-09 23:31:28 +02:00
|
|
|
folder = [contactFolders objectForKey: name];
|
|
|
|
obj = ((folder)
|
|
|
|
? folder
|
|
|
|
: [NSException exceptionWithHTTPStatus: 404]);
|
2006-08-05 00:46:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) toManyRelationshipKeys
|
|
|
|
{
|
2006-08-09 23:31:28 +02:00
|
|
|
if (!contactFolders)
|
2007-04-11 21:08:58 +02:00
|
|
|
[self initContactSources];
|
2006-08-09 23:31:28 +02:00
|
|
|
|
|
|
|
return [contactFolders allKeys];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) contactFolders
|
|
|
|
{
|
|
|
|
if (!contactFolders)
|
2007-04-11 21:08:58 +02:00
|
|
|
[self initContactSources];
|
2006-08-05 00:46:19 +02:00
|
|
|
|
2006-08-09 23:31:28 +02:00
|
|
|
return [contactFolders allValues];
|
2006-08-05 00:46:19 +02:00
|
|
|
}
|
|
|
|
|
2007-04-25 00:43:33 +02:00
|
|
|
/* acls */
|
|
|
|
- (NSArray *) aclsForUser: (NSString *) uid
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2007-04-12 02:34:43 +02:00
|
|
|
// - (NSString *) roleOfUser: (NSString *) uid
|
|
|
|
// {
|
|
|
|
// NSArray *roles, *traversalPath;
|
|
|
|
// NSString *objectName, *role;
|
|
|
|
|
|
|
|
// role = nil;
|
|
|
|
// traversalPath = [context objectForKey: @"SoRequestTraversalPath"];
|
|
|
|
// if ([traversalPath count] > 2)
|
|
|
|
// {
|
|
|
|
// objectName = [traversalPath objectAtIndex: 2];
|
|
|
|
// roles = [[context activeUser]
|
|
|
|
// rolesForObject: [self lookupName: objectName
|
|
|
|
// inContext: context
|
|
|
|
// acquire: NO]
|
|
|
|
// inContext: context];
|
|
|
|
// if ([roles containsObject: SOGoRole_Assistant]
|
|
|
|
// || [roles containsObject: SOGoRole_Delegate])
|
|
|
|
// role = SOGoRole_Assistant;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return role;
|
|
|
|
// }
|
2006-12-15 23:18:55 +01:00
|
|
|
|
2006-08-05 00:46:19 +02:00
|
|
|
- (BOOL) davIsCollection
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setBaseOCSPath: (NSString *) newOCSPath
|
|
|
|
{
|
|
|
|
if (OCSPath)
|
|
|
|
[OCSPath release];
|
|
|
|
OCSPath = newOCSPath;
|
|
|
|
if (OCSPath)
|
|
|
|
[OCSPath retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* web interface */
|
|
|
|
- (NSString *) defaultSourceName
|
|
|
|
{
|
|
|
|
return @"personal";
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|