2 Copyright (C) 2004-2005 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #import <Foundation/NSArray.h>
23 #import <Foundation/NSString.h>
25 #import <NGObjWeb/NSException+HTTP.h>
26 #import <NGObjWeb/SoClassSecurityInfo.h>
27 #import <NGExtensions/NSObject+Logs.h>
29 #import <Appointments/SOGoAppointmentFolders.h>
30 #import <Appointments/SOGoFreeBusyObject.h>
31 #import <Contacts/SOGoContactFolders.h>
32 #import <Mailer/SOGoMailAccounts.h>
34 #import "SOGoPermissions.h"
37 #import "SOGoUserFolder.h"
39 @implementation SOGoUserFolder
43 SoClassSecurityInfo *sInfo;
46 sInfo = [self soClassSecurityInfo];
47 [sInfo declareObjectProtected: SoPerm_View];
49 basicRoles = [NSArray arrayWithObject: SoRole_Authenticated];
51 /* require Authenticated role for View and WebDAV */
52 [sInfo declareRoles: basicRoles asDefaultForPermission: SoPerm_View];
53 [sInfo declareRoles: basicRoles asDefaultForPermission: SoPerm_WebDAVAccess];
60 return nameInContainer;
65 - (NSArray *) toManyRelationshipKeys
67 static NSArray *children = nil;
70 children = [[NSArray alloc] initWithObjects:
71 @"Calendar", @"Contacts", @"Mail", nil];
78 - (NSString *) ownerInContext: (WOContext *) _ctx
80 return nameInContainer;
83 /* looking up shared objects */
85 - (SOGoUserFolder *) lookupUserFolder
90 // - (SOGoGroupsFolder *) lookupGroupsFolder
92 // return [self lookupName: @"Groups" inContext: nil acquire: NO];
97 - (void) setOCSPath: (NSString *) _path
100 @"rejected attempt to reset user-folder path: '%@'", _path];
103 - (NSString *) ocsPath
105 return [NSString stringWithFormat: @"/Users/%@", nameInContainer];
108 - (NSString *) ocsUserPath
110 return [self ocsPath];
113 - (BOOL) folderIsMandatory
118 - (NSString *) ocsPrivateCalendarPath
120 return [[self ocsUserPath] stringByAppendingString:@"/Calendar"];
123 - (NSString *) ocsPrivateContactsPath
125 return [[self ocsUserPath] stringByAppendingString:@"/Contacts"];
130 // - (NSString *) permissionForKey: (NSString *) key
132 // return ([key isEqualToString: @"freebusy.ifb"]
133 // ? SoPerm_WebDAVAccess
134 // : [super permissionForKey: key]);
137 - (SOGoAppointmentFolders *) privateCalendars: (NSString *) _key
138 inContext: (WOContext *) _ctx
140 SOGoAppointmentFolders *calendars;
142 calendars = [$(@"SOGoAppointmentFolders") objectWithName: _key inContainer: self];
143 [calendars setBaseOCSPath: [self ocsPrivateCalendarPath]];
148 - (SOGoContactFolders *) privateContacts: (NSString *) _key
149 inContext: (WOContext *) _ctx
151 SOGoContactFolders *contacts;
153 contacts = [$(@"SOGoContactFolders") objectWithName:_key inContainer: self];
154 [contacts setBaseOCSPath: [self ocsPrivateContactsPath]];
159 // - (id) groupsFolder: (NSString *) _key
160 // inContext: (WOContext *) _ctx
162 // return [$(@"SOGoGroupsFolder") objectWithName: _key inContainer: self];
165 - (id) mailAccountsFolder: (NSString *) _key
166 inContext: (WOContext *) _ctx
168 return [$(@"SOGoMailAccounts") objectWithName: _key inContainer: self];
171 - (id) freeBusyObject: (NSString *) _key
172 inContext: (WOContext *) _ctx
174 return [$(@"SOGoFreeBusyObject") objectWithName: _key inContainer: self];
177 - (id) lookupName: (NSString *) _key
178 inContext: (WOContext *) _ctx
179 acquire: (BOOL) _flag
183 /* first check attributes directly bound to the application */
184 obj = [super lookupName: _key inContext: _ctx acquire: NO];
187 if ([_key isEqualToString: @"Calendar"])
188 obj = [self privateCalendars: @"Calendar" inContext: _ctx];
189 // if (![_key isEqualToString: @"Calendar"])
190 // obj = [obj lookupName: [_key pathExtension]
191 // inContext: _ctx acquire: NO];
192 else if ([_key isEqualToString: @"Contacts"])
193 obj = [self privateContacts: _key inContext: _ctx];
194 // else if ([_key isEqualToString: @"Groups"])
195 // obj = [self groupsFolder: _key inContext: _ctx];
196 else if ([_key isEqualToString: @"Mail"])
197 obj = [self mailAccountsFolder: _key inContext: _ctx];
198 else if ([_key isEqualToString: @"freebusy.ifb"])
199 obj = [self freeBusyObject:_key inContext: _ctx];
201 obj = [NSException exceptionWithHTTPStatus: 404 /* Not Found */];
207 // /* FIXME: here is a vault of hackish ways to gain access to subobjects by
208 // granting ro access to the homepage depending on the subobject in question.
209 // This is wrong and dangerous. */
210 // - (NSString *) roleOfUser: (NSString *) uid
211 // inContext: (WOContext *) context
213 // NSArray *roles, *traversalPath;
214 // NSString *objectName, *role;
217 // traversalPath = [context objectForKey: @"SoRequestTraversalPath"];
218 // if ([traversalPath count] > 1)
220 // objectName = [traversalPath objectAtIndex: 1];
221 // if ([objectName isEqualToString: @"Calendar"]
222 // || [objectName isEqualToString: @"Contacts"])
224 // roles = [[context activeUser]
225 // rolesForObject: [self lookupName: objectName
226 // inContext: context
228 // inContext: context];
229 // if ([roles containsObject: SOGoRole_Assistant]
230 // || [roles containsObject: SOGoRole_Delegate])
231 // role = SOGoRole_Assistant;
233 // else if ([objectName isEqualToString: @"freebusy.ifb"])
234 // role = SOGoRole_Assistant;
242 - (NSArray *) fetchContentObjectNames
244 static NSArray *cos = nil;
247 cos = [[NSArray alloc] initWithObjects: @"freebusy.ifb", nil];
252 - (BOOL) davIsCollection
258 - (NSArray *) davCalendarHomeSet
261 <C:calendar-home-set xmlns:D="DAV:"
262 xmlns:C="urn:ietf:params:xml:ns:caldav">
263 <D:href>http://cal.example.com/home/bernard/calendars/</D:href>
264 </C:calendar-home-set>
266 Note: this is the *container* for calendar collections, not the
267 collections itself. So for use its the home folder, the
268 public folder and the groups folder.
272 tag = [NSArray arrayWithObjects: @"href", @"DAV:", @"D",
273 [self baseURLInContext: context], nil];
275 return [NSArray arrayWithObject: tag];
278 @end /* SOGoUserFolder */