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/WOApplication.h>
35 #import <NGObjWeb/WOContext.h>
36 #import <NGObjWeb/WOContext+SoObjects.h>
37 #import <NGObjWeb/SoUser.h>
39 #import <SoObjects/SOGo/SOGoPermissions.h>
43 #import "SOGoContactGCSFolder.h"
44 #import "SOGoContactLDAPFolder.h"
45 #import "SOGoContactFolders.h"
47 @implementation SOGoContactFolders
51 if ((self = [super init]))
63 [contactFolders release];
69 - (void) appendPersonalSourcesInContext: (WOContext *) context;
71 SOGoContactGCSFolder *ab;
73 ab = [SOGoContactGCSFolder contactFolderWithName: @"personal"
74 andDisplayName: @"Personal Addressbook"
76 [ab setOCSPath: [NSString stringWithFormat: @"%@/%@",
77 OCSPath, @"personal"]];
78 [contactFolders setObject: ab forKey: @"personal"];
81 - (void) appendSystemSourcesInContext: (WOContext *) context;
84 NSEnumerator *ldapABs;
86 SOGoContactLDAPFolder *ab;
88 ud = [NSUserDefaults standardUserDefaults];
89 ldapABs = [[ud objectForKey: @"SOGoLDAPAddressBooks"] objectEnumerator];
90 udAB = [ldapABs nextObject];
93 ab = [SOGoContactLDAPFolder contactFolderWithName:
94 [udAB objectForKey: @"id"]
96 [udAB objectForKey: @"displayName"]
98 [ab LDAPSetHostname: [udAB objectForKey: @"hostname"]
99 setPort: [[udAB objectForKey: @"port"] intValue]
100 setBindDN: [udAB objectForKey: @"bindDN"]
101 setBindPW: [udAB objectForKey: @"bindPW"]
102 setContactIdentifier: [udAB objectForKey: @"idField"]
103 setUserIdentifier: [udAB objectForKey: @"userIdField"]
104 setRootDN: [udAB objectForKey: @"rootDN"]];
105 [contactFolders setObject: ab forKey: [udAB objectForKey: @"id"]];
106 udAB = [ldapABs nextObject];
110 - (void) initContactSourcesInContext: (WOContext *) context;
114 contactFolders = [NSMutableDictionary new];
115 [self appendPersonalSourcesInContext: context];
116 [self appendSystemSourcesInContext: context];
120 - (id) lookupName: (NSString *) name
121 inContext: (WOContext *) context
122 acquire: (BOOL) acquire
127 /* first check attributes directly bound to the application */
128 obj = [super lookupName: name inContext: context acquire: NO];
132 [self initContactSourcesInContext: context];
134 folder = [contactFolders objectForKey: name];
137 : [NSException exceptionWithHTTPStatus: 404]);
143 - (NSArray *) toManyRelationshipKeys
149 context = [[WOApplication application] context];
150 [self initContactSourcesInContext: context];
153 return [contactFolders allKeys];
156 - (NSArray *) contactFolders
162 context = [[WOApplication application] context];
163 [self initContactSourcesInContext: context];
166 return [contactFolders allValues];
169 - (NSString *) roleOfUser: (NSString *) uid
170 inContext: (WOContext *) context
172 NSArray *roles, *traversalPath;
173 NSString *objectName, *role;
176 traversalPath = [context objectForKey: @"SoRequestTraversalPath"];
177 if ([traversalPath count] > 2)
179 objectName = [traversalPath objectAtIndex: 2];
180 if ([objectName isEqualToString: @"personal"])
182 roles = [[context activeUser]
183 rolesForObject: [self lookupName: objectName
187 if ([roles containsObject: SOGoRole_Assistant]
188 || [roles containsObject: SOGoRole_Delegate])
189 role = SOGoRole_Assistant;
196 - (BOOL) davIsCollection
201 - (void) setBaseOCSPath: (NSString *) newOCSPath
205 OCSPath = newOCSPath;
211 - (NSString *) defaultSourceName