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 [NSString stringWithFormat: @"/Users/%@", nameInContainer];
92 - (NSString *) ocsUserPath
94 return [self ocsPath];
97 - (BOOL) folderIsMandatory
102 - (NSString *) ocsPrivateCalendarPath
104 return [[self ocsUserPath] stringByAppendingString:@"/Calendar"];
107 - (NSString *) ocsPrivateContactsPath
109 return [[self ocsUserPath] stringByAppendingString:@"/Contacts"];
114 // - (NSString *) permissionForKey: (NSString *) key
116 // return ([key isEqualToString: @"freebusy.ifb"]
117 // ? SoPerm_WebDAVAccess
118 // : [super permissionForKey: key]);
121 - (SOGoAppointmentFolder *) privateCalendar: (NSString *) _key
122 inContext: (WOContext *) _ctx
124 SOGoAppointmentFolder *calendar;
126 calendar = [$(@"SOGoAppointmentFolder") objectWithName: _key inContainer: self];
127 [calendar setOCSPath: [self ocsPrivateCalendarPath]];
132 - (SOGoContactFolders *) privateContacts: (NSString *) _key
133 inContext: (WOContext *) _ctx
135 SOGoContactFolders *contacts;
137 contacts = [$(@"SOGoContactFolders") objectWithName:_key inContainer: self];
138 [contacts setBaseOCSPath: [self ocsPrivateContactsPath]];
143 // - (id) groupsFolder: (NSString *) _key
144 // inContext: (WOContext *) _ctx
146 // return [$(@"SOGoGroupsFolder") objectWithName: _key inContainer: self];
149 - (id) mailAccountsFolder: (NSString *) _key
150 inContext: (WOContext *) _ctx
152 return [$(@"SOGoMailAccounts") objectWithName: _key inContainer: self];
155 - (id) freeBusyObject: (NSString *) _key
156 inContext: (WOContext *) _ctx
158 return [$(@"SOGoFreeBusyObject") objectWithName: _key inContainer: self];
161 - (id) lookupName: (NSString *) _key
162 inContext: (WOContext *) _ctx
163 acquire: (BOOL) _flag
167 /* first check attributes directly bound to the application */
168 obj = [super lookupName: _key inContext: _ctx acquire: NO];
171 if ([_key isEqualToString: @"Calendar"])
172 obj = [self privateCalendar: @"Calendar" inContext: _ctx];
173 // if (![_key isEqualToString: @"Calendar"])
174 // obj = [obj lookupName: [_key pathExtension]
175 // inContext: _ctx acquire: NO];
176 else if ([_key isEqualToString: @"Contacts"])
177 obj = [self privateContacts: _key inContext: _ctx];
178 // else if ([_key isEqualToString: @"Groups"])
179 // obj = [self groupsFolder: _key inContext: _ctx];
180 else if ([_key isEqualToString: @"Mail"])
181 obj = [self mailAccountsFolder: _key inContext: _ctx];
182 else if ([_key isEqualToString: @"freebusy.ifb"])
183 obj = [self freeBusyObject:_key inContext: _ctx];
185 obj = [NSException exceptionWithHTTPStatus: 404 /* Not Found */];
191 // /* FIXME: here is a vault of hackish ways to gain access to subobjects by
192 // granting ro access to the homepage depending on the subobject in question.
193 // This is wrong and dangerous. */
194 // - (NSString *) roleOfUser: (NSString *) uid
195 // inContext: (WOContext *) context
197 // NSArray *roles, *traversalPath;
198 // NSString *objectName, *role;
201 // traversalPath = [context objectForKey: @"SoRequestTraversalPath"];
202 // if ([traversalPath count] > 1)
204 // objectName = [traversalPath objectAtIndex: 1];
205 // if ([objectName isEqualToString: @"Calendar"]
206 // || [objectName isEqualToString: @"Contacts"])
208 // roles = [[context activeUser]
209 // rolesForObject: [self lookupName: objectName
210 // inContext: context
212 // inContext: context];
213 // if ([roles containsObject: SOGoRole_Assistant]
214 // || [roles containsObject: SOGoRole_Delegate])
215 // role = SOGoRole_Assistant;
217 // else if ([objectName isEqualToString: @"freebusy.ifb"])
218 // role = SOGoRole_Assistant;
226 - (NSArray *) fetchContentObjectNames
228 static NSArray *cos = nil;
231 cos = [[NSArray alloc] initWithObjects: @"freebusy.ifb", nil];
236 - (BOOL) davIsCollection
242 - (NSArray *) davCalendarHomeSet
245 <C:calendar-home-set xmlns:D="DAV:"
246 xmlns:C="urn:ietf:params:xml:ns:caldav">
247 <D:href>http://cal.example.com/home/bernard/calendars/</D:href>
248 </C:calendar-home-set>
250 Note: this is the *container* for calendar collections, not the
251 collections itself. So for use its the home folder, the
252 public folder and the groups folder.
256 tag = [NSArray arrayWithObjects: @"href", @"DAV:", @"D",
257 [self baseURLInContext: context], nil];
259 return [NSArray arrayWithObject: tag];
262 @end /* SOGoUserFolder */