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 <NGExtensions/NSObject+Logs.h>
28 #import <Appointments/SOGoAppointmentFolder.h>
29 #import <Appointments/SOGoFreeBusyObject.h>
30 #import <Contacts/SOGoContactFolders.h>
31 #import <Mailer/SOGoMailAccounts.h>
33 #import "SOGoPermissions.h"
36 #import "SOGoUserFolder.h"
38 @implementation SOGoUserFolder
44 return nameInContainer;
49 - (NSArray *) toManyRelationshipKeys
51 static NSArray *children = nil;
54 children = [[NSArray alloc] initWithObjects:
55 @"Calendar", @"Contacts", @"Mail", nil];
62 - (NSString *) ownerInContext: (WOContext *) _ctx
64 return nameInContainer;
67 /* looking up shared objects */
69 - (SOGoUserFolder *) lookupUserFolder
74 // - (SOGoGroupsFolder *) lookupGroupsFolder
76 // return [self lookupName: @"Groups" inContext: nil acquire: NO];
81 - (void) setOCSPath: (NSString *) _path
84 @"rejected attempt to reset user-folder path: '%@'", _path];
87 - (NSString *) ocsPath
89 return [@"/Users/" stringByAppendingString: [self login]];
92 - (NSString *) ocsUserPath
94 return [self ocsPath];
97 - (NSString *) ocsPrivateCalendarPath
99 return [[self ocsUserPath] stringByAppendingString:@"/Calendar"];
102 - (NSString *) ocsPrivateContactsPath
104 return [[self ocsUserPath] stringByAppendingString:@"/Contacts"];
109 // - (NSString *) permissionForKey: (NSString *) key
111 // return ([key isEqualToString: @"freebusy.ifb"]
112 // ? SoPerm_WebDAVAccess
113 // : [super permissionForKey: key]);
116 - (SOGoAppointmentFolder *) privateCalendar: (NSString *) _key
117 inContext: (WOContext *) _ctx
119 SOGoAppointmentFolder *calendar;
121 calendar = [$(@"SOGoAppointmentFolder") objectWithName: _key inContainer: self];
122 [calendar setOCSPath: [self ocsPrivateCalendarPath]];
127 - (SOGoContactFolders *) privateContacts: (NSString *) _key
128 inContext: (WOContext *) _ctx
130 SOGoContactFolders *contacts;
132 contacts = [$(@"SOGoContactFolders") objectWithName:_key inContainer: self];
133 [contacts setBaseOCSPath: [self ocsPrivateContactsPath]];
138 // - (id) groupsFolder: (NSString *) _key
139 // inContext: (WOContext *) _ctx
141 // return [$(@"SOGoGroupsFolder") objectWithName: _key inContainer: self];
144 - (id) mailAccountsFolder: (NSString *) _key
145 inContext: (WOContext *) _ctx
147 return [$(@"SOGoMailAccounts") objectWithName: _key inContainer: self];
150 - (id) freeBusyObject: (NSString *) _key
151 inContext: (WOContext *) _ctx
153 return [$(@"SOGoFreeBusyObject") objectWithName: _key inContainer: self];
156 - (id) lookupName: (NSString *) _key
157 inContext: (WOContext *) _ctx
158 acquire: (BOOL) _flag
162 /* first check attributes directly bound to the application */
163 obj = [super lookupName: _key inContext: _ctx acquire: NO];
166 if ([_key hasPrefix: @"Calendar"])
168 obj = [self privateCalendar: @"Calendar" inContext: _ctx];
169 if (![_key isEqualToString: @"Calendar"])
170 obj = [obj lookupName: [_key pathExtension]
171 inContext: _ctx acquire: NO];
173 else if ([_key isEqualToString: @"Contacts"])
174 obj = [self privateContacts: _key inContext: _ctx];
175 // else if ([_key isEqualToString: @"Groups"])
176 // obj = [self groupsFolder: _key inContext: _ctx];
177 else if ([_key isEqualToString: @"Mail"])
178 obj = [self mailAccountsFolder: _key inContext: _ctx];
179 else if ([_key isEqualToString: @"freebusy.ifb"])
180 obj = [self freeBusyObject:_key inContext: _ctx];
182 obj = [NSException exceptionWithHTTPStatus: 404 /* Not Found */];
188 // /* FIXME: here is a vault of hackish ways to gain access to subobjects by
189 // granting ro access to the homepage depending on the subobject in question.
190 // This is wrong and dangerous. */
191 // - (NSString *) roleOfUser: (NSString *) uid
192 // inContext: (WOContext *) context
194 // NSArray *roles, *traversalPath;
195 // NSString *objectName, *role;
198 // traversalPath = [context objectForKey: @"SoRequestTraversalPath"];
199 // if ([traversalPath count] > 1)
201 // objectName = [traversalPath objectAtIndex: 1];
202 // if ([objectName isEqualToString: @"Calendar"]
203 // || [objectName isEqualToString: @"Contacts"])
205 // roles = [[context activeUser]
206 // rolesForObject: [self lookupName: objectName
207 // inContext: context
209 // inContext: context];
210 // if ([roles containsObject: SOGoRole_Assistant]
211 // || [roles containsObject: SOGoRole_Delegate])
212 // role = SOGoRole_Assistant;
214 // else if ([objectName isEqualToString: @"freebusy.ifb"])
215 // role = SOGoRole_Assistant;
223 - (NSArray *) fetchContentObjectNames
225 static NSArray *cos = nil;
228 cos = [[NSArray alloc] initWithObjects: @"freebusy.ifb", nil];
233 - (BOOL) davIsCollection
239 - (NSArray *) davCalendarHomeSet
242 <C:calendar-home-set xmlns:D="DAV:"
243 xmlns:C="urn:ietf:params:xml:ns:caldav">
244 <D:href>http://cal.example.com/home/bernard/calendars/</D:href>
245 </C:calendar-home-set>
247 Note: this is the *container* for calendar collections, not the
248 collections itself. So for use its the home folder, the
249 public folder and the groups folder.
253 tag = [NSArray arrayWithObjects: @"href", @"DAV:", @"D",
254 [self baseURLInContext: context], nil];
256 return [NSArray arrayWithObject: tag];
259 @end /* SOGoUserFolder */