1 /* SOGoContactFolders.m - this file is part of SOGo
3 * Copyright (C) 2006 Inverse groupe conseil
5 * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
7 * This file is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This file is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 /* exchange folder types: */
25 ContactItems IPF.Contact
26 AppointmentItems IPF.Appointment
27 NoteItems IPF.StickyNote
29 JournalItems IPF.Journal */
31 #import <Foundation/NSDictionary.h>
32 #import <Foundation/NSString.h>
34 #import <NGObjWeb/NSException+HTTP.h>
35 #import <NGObjWeb/WOApplication.h>
36 #import <NGObjWeb/WOContext.h>
37 #import <NGObjWeb/WOContext+SoObjects.h>
38 #import <NGObjWeb/WOResponse.h>
39 #import <NGObjWeb/SoUser.h>
41 #import <GDLContentStore/GCSFolderManager.h>
42 #import <GDLContentStore/GCSChannelManager.h>
43 #import <GDLAccess/EOAdaptorChannel.h>
44 #import <GDLContentStore/NSURL+GCS.h>
46 #import <SoObjects/SOGo/LDAPUserManager.h>
47 #import <SoObjects/SOGo/SOGoPermissions.h>
49 #import "SOGoContactGCSFolder.h"
50 #import "SOGoContactLDAPFolder.h"
51 #import "SOGoContactFolders.h"
53 @implementation SOGoContactFolders
57 if ((self = [super init]))
69 [contactFolders release];
75 - (void) appendPersonalSources
77 SOGoContactGCSFolder *ab;
78 GCSChannelManager *cm;
80 NSURL *folderLocation;
85 cm = [GCSChannelManager defaultChannelManager];
87 = [[GCSFolderManager defaultFolderManager] folderInfoLocation];
88 fc = [cm acquireOpenChannelForURL: folderLocation];
92 stringWithFormat: (@"SELECT c_path4, c_foldername FROM %@"
93 @" WHERE c_path2 = '%@'"
94 @" AND c_folder_type = 'Contact'"),
95 [folderLocation gcsTableName], [self ownerInContext: context]];
96 [fc evaluateExpressionX: sql];
97 attrs = [fc describeResults: NO];
98 row = [fc fetchAttributes: attrs withZone: NULL];
101 ab = [SOGoContactGCSFolder contactFolderWithName: [row objectForKey: @"c_path4"]
102 andDisplayName: [row objectForKey: @"c_foldername"]
104 [ab setOCSPath: [NSString stringWithFormat: @"%@/%@",
105 OCSPath, [row objectForKey: @"c_path4"]]];
106 [contactFolders setObject: ab forKey: [row objectForKey: @"c_path4"]];
107 row = [fc fetchAttributes: attrs withZone: NULL];
110 [cm releaseChannel: fc];
111 // sql = [sql stringByAppendingFormat:@" WHERE %@ = '%@'",
112 // uidColumnName, [self uid]];
116 - (void) appendSystemSources
119 NSEnumerator *sourceIDs;
120 NSString *currentSourceID, *displayName;
121 SOGoContactLDAPFolder *currentFolder;
123 um = [LDAPUserManager sharedUserManager];
124 sourceIDs = [[um addressBookSourceIDs] objectEnumerator];
125 currentSourceID = [sourceIDs nextObject];
126 while (currentSourceID)
128 displayName = [um displayNameForSourceWithID: currentSourceID];
129 currentFolder = [SOGoContactLDAPFolder contactFolderWithName: currentSourceID
130 andDisplayName: displayName
132 [currentFolder setLDAPSource: [um sourceWithID: currentSourceID]];
133 [contactFolders setObject: currentFolder forKey: currentSourceID];
134 currentSourceID = [sourceIDs nextObject];
138 - (WOResponse *) newFolderWithName: (NSString *) name
140 SOGoContactGCSFolder *newFolder;
141 WOResponse *response;
143 newFolder = [SOGoContactGCSFolder contactFolderWithName: name
146 if ([newFolder isKindOfClass: [NSException class]])
147 response = (WOResponse *) newFolder;
150 [newFolder setOCSPath: [NSString stringWithFormat: @"%@/%@",
152 if ([newFolder create])
154 response = [WOResponse new];
155 [response setStatus: 201];
156 [response autorelease];
159 response = [NSException exceptionWithHTTPStatus: 400
160 reason: @"The new folder could not be created"];
166 - (void) initContactSources
170 contactFolders = [NSMutableDictionary new];
171 [self appendPersonalSources];
172 [self appendSystemSources];
176 - (id) lookupName: (NSString *) name
177 inContext: (WOContext *) lookupContext
178 acquire: (BOOL) acquire
182 /* first check attributes directly bound to the application */
183 obj = [super lookupName: name inContext: lookupContext acquire: NO];
187 [self initContactSources];
189 obj = [contactFolders objectForKey: name];
191 obj = [NSException exceptionWithHTTPStatus: 404];
197 - (NSArray *) toManyRelationshipKeys
200 [self initContactSources];
202 return [contactFolders allKeys];
205 - (NSArray *) contactFolders
208 [self initContactSources];
210 return [contactFolders allValues];
214 - (NSArray *) aclsForUser: (NSString *) uid
219 // - (NSString *) roleOfUser: (NSString *) uid
221 // NSArray *roles, *traversalPath;
222 // NSString *objectName, *role;
225 // traversalPath = [context objectForKey: @"SoRequestTraversalPath"];
226 // if ([traversalPath count] > 2)
228 // objectName = [traversalPath objectAtIndex: 2];
229 // roles = [[context activeUser]
230 // rolesForObject: [self lookupName: objectName
231 // inContext: context
233 // inContext: context];
234 // if ([roles containsObject: SOGoRole_Assistant]
235 // || [roles containsObject: SOGoRole_Delegate])
236 // role = SOGoRole_Assistant;
242 - (BOOL) davIsCollection
247 - (void) setBaseOCSPath: (NSString *) newOCSPath
251 OCSPath = newOCSPath;
257 - (NSString *) defaultSourceName