]> err.no Git - scalable-opengroupware.org/blob - SoObjects/SOGo/SOGoUserFolder.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1081 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / SoObjects / SOGo / SOGoUserFolder.m
1 /*
2   Copyright (C) 2004-2005 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #import "WOContext+Agenor.h"
23 #import "common.h"
24 #import "SOGoUser.h"
25
26 #import "Appointments/SOGoAppointmentFolder.h"
27 #import "Appointments/SOGoFreeBusyObject.h"
28 #import "Contacts/SOGoContactFolders.h"
29 #import "Mailer/SOGoMailAccounts.h"
30 #import "SOGoPermissions.h"
31
32 #import "SOGoUserFolder.h"
33
34 @implementation SOGoUserFolder
35
36 /* accessors */
37
38 - (NSString *) login
39 {
40   return nameInContainer;
41 }
42
43 /* hierarchy */
44
45 - (NSArray *) toManyRelationshipKeys
46 {
47   static NSArray *children = nil;
48
49   if (!children)
50     children = [[NSArray alloc] initWithObjects:
51                                   @"Calendar", @"Contacts", @"Mail", nil];
52
53   return children;
54 }
55
56 /* ownership */
57
58 - (NSString *) ownerInContext: (WOContext *) _ctx
59 {
60   return nameInContainer;
61 }
62
63 /* looking up shared objects */
64
65 - (SOGoUserFolder *) lookupUserFolder
66 {
67   return self;
68 }
69
70 // - (SOGoGroupsFolder *) lookupGroupsFolder
71 // {
72 //   return [self lookupName: @"Groups" inContext: nil acquire: NO];
73 // }
74
75 /* pathes */
76
77 - (void) setOCSPath: (NSString *) _path
78 {
79   [self warnWithFormat:
80           @"rejected attempt to reset user-folder path: '%@'", _path];
81 }
82
83 - (NSString *) ocsPath
84 {
85   return [@"/Users/" stringByAppendingString: [self login]];
86 }
87
88 - (NSString *) ocsUserPath
89 {
90   return [self ocsPath];
91 }
92
93 - (NSString *) ocsPrivateCalendarPath
94 {
95   return [[self ocsUserPath] stringByAppendingString:@"/Calendar"];
96 }
97
98 - (NSString *) ocsPrivateContactsPath
99 {
100   return [[self ocsUserPath] stringByAppendingString:@"/Contacts"];
101 }
102
103 /* name lookup */
104
105 // - (NSString *) permissionForKey: (NSString *) key
106 // {
107 //   return ([key isEqualToString: @"freebusy.ifb"]
108 //           ? SoPerm_WebDAVAccess
109 //           : [super permissionForKey: key]);
110 // }
111
112 - (SOGoAppointmentFolder *) privateCalendar: (NSString *) _key
113                                   inContext: (WOContext *) _ctx
114 {
115   SOGoAppointmentFolder *calendar;
116   
117   calendar = [$(@"SOGoAppointmentFolder") objectWithName: _key inContainer: self];
118   [calendar setOCSPath: [self ocsPrivateCalendarPath]];
119
120   return calendar;
121 }
122
123 - (SOGoContactFolders *) privateContacts: (NSString *) _key
124                                inContext: (WOContext *) _ctx
125 {
126   SOGoContactFolders *contacts;
127
128   contacts = [$(@"SOGoContactFolders") objectWithName:_key inContainer: self];
129   [contacts setBaseOCSPath: [self ocsPrivateContactsPath]];
130
131   return contacts;
132 }
133
134 // - (id) groupsFolder: (NSString *) _key
135 //           inContext: (WOContext *) _ctx
136 // {
137 //   return [$(@"SOGoGroupsFolder") objectWithName: _key inContainer: self];
138 // }
139
140 - (id) mailAccountsFolder: (NSString *) _key
141                 inContext: (WOContext *) _ctx
142 {
143   return [$(@"SOGoMailAccounts") objectWithName: _key inContainer: self];
144 }
145
146 - (id) freeBusyObject: (NSString *) _key
147             inContext: (WOContext *) _ctx
148 {
149   return [$(@"SOGoFreeBusyObject") objectWithName: _key inContainer: self];
150 }
151
152 - (id) lookupName: (NSString *) _key
153         inContext: (WOContext *) _ctx
154           acquire: (BOOL) _flag
155 {
156   id obj;
157   
158   /* first check attributes directly bound to the application */
159   obj = [super lookupName: _key inContext: _ctx acquire: NO];
160   if (!obj)
161     {
162       if ([_key hasPrefix: @"Calendar"])
163         {
164           obj = [self privateCalendar: @"Calendar" inContext: _ctx];
165           if (![_key isEqualToString: @"Calendar"])
166             obj = [obj lookupName: [_key pathExtension] 
167                        inContext: _ctx acquire: NO];
168         }
169       else if ([_key isEqualToString: @"Contacts"])
170         obj = [self privateContacts: _key inContext: _ctx];
171 //       else if ([_key isEqualToString: @"Groups"])
172 //         obj = [self groupsFolder: _key inContext: _ctx];
173       else if ([_key isEqualToString: @"Mail"])
174         obj = [self mailAccountsFolder: _key inContext: _ctx];
175       else if ([_key isEqualToString: @"freebusy.ifb"])
176         obj = [self freeBusyObject:_key inContext: _ctx];
177       else
178         obj = [NSException exceptionWithHTTPStatus: 404 /* Not Found */];
179     }
180
181   return obj;
182 }
183
184 // /* FIXME: here is a vault of hackish ways to gain access to subobjects by
185 //    granting ro access to the homepage depending on the subobject in question.
186 //    This is wrong and dangerous. */
187 // - (NSString *) roleOfUser: (NSString *) uid
188 //                 inContext: (WOContext *) context
189 // {
190 //   NSArray *roles, *traversalPath;
191 //   NSString *objectName, *role;
192
193 //   role = nil;
194 //   traversalPath = [context objectForKey: @"SoRequestTraversalPath"];
195 //   if ([traversalPath count] > 1)
196 //     {
197 //       objectName = [traversalPath objectAtIndex: 1];
198 //       if ([objectName isEqualToString: @"Calendar"]
199 //           || [objectName isEqualToString: @"Contacts"])
200 //         {
201 //           roles = [[context activeUser]
202 //                     rolesForObject: [self lookupName: objectName
203 //                                           inContext: context
204 //                                           acquire: NO]
205 //                     inContext: context];
206 //           if ([roles containsObject: SOGoRole_Assistant]
207 //               || [roles containsObject: SOGoRole_Delegate])
208 //             role = SOGoRole_Assistant;
209 //         }
210 //       else if ([objectName isEqualToString: @"freebusy.ifb"])
211 //         role = SOGoRole_Assistant;
212 //     }
213
214 //   return role;
215 // }
216
217 /* WebDAV */
218
219 - (NSArray *) fetchContentObjectNames
220 {
221   static NSArray *cos = nil;
222   
223   if (!cos)
224     cos = [[NSArray alloc] initWithObjects: @"freebusy.ifb", nil];
225
226   return cos;
227 }
228
229 - (BOOL) davIsCollection
230 {
231   return YES;
232 }
233
234 /* CalDAV support */
235 - (NSArray *) davCalendarHomeSet
236 {
237   /*
238     <C:calendar-home-set xmlns:D="DAV:"
239         xmlns:C="urn:ietf:params:xml:ns:caldav">
240       <D:href>http://cal.example.com/home/bernard/calendars/</D:href>
241     </C:calendar-home-set>
242
243     Note: this is the *container* for calendar collections, not the
244           collections itself. So for use its the home folder, the
245           public folder and the groups folder.
246   */
247   NSArray *tag;
248
249   tag = [NSArray arrayWithObjects: @"href", @"DAV:", @"D",
250                  [self baseURLInContext: context], nil];
251
252   return [NSArray arrayWithObject: tag];
253 }
254
255 @end /* SOGoUserFolder */