]> err.no Git - scalable-opengroupware.org/blob - SoObjects/SOGo/SOGoUserFolder.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1166 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 <Foundation/NSArray.h>
23 #import <Foundation/NSString.h>
24
25 #import <NGObjWeb/NSException+HTTP.h>
26 #import <NGExtensions/NSObject+Logs.h>
27
28 #import <Appointments/SOGoAppointmentFolder.h>
29 #import <Appointments/SOGoFreeBusyObject.h>
30 #import <Contacts/SOGoContactFolders.h>
31 #import <Mailer/SOGoMailAccounts.h>
32
33 #import "SOGoPermissions.h"
34 #import "SOGoUser.h"
35
36 #import "SOGoUserFolder.h"
37
38 @implementation SOGoUserFolder
39
40 /* accessors */
41
42 - (NSString *) login
43 {
44   return nameInContainer;
45 }
46
47 /* hierarchy */
48
49 - (NSArray *) toManyRelationshipKeys
50 {
51   static NSArray *children = nil;
52
53   if (!children)
54     children = [[NSArray alloc] initWithObjects:
55                                   @"Calendar", @"Contacts", @"Mail", nil];
56
57   return children;
58 }
59
60 /* ownership */
61
62 - (NSString *) ownerInContext: (WOContext *) _ctx
63 {
64   return nameInContainer;
65 }
66
67 /* looking up shared objects */
68
69 - (SOGoUserFolder *) lookupUserFolder
70 {
71   return self;
72 }
73
74 // - (SOGoGroupsFolder *) lookupGroupsFolder
75 // {
76 //   return [self lookupName: @"Groups" inContext: nil acquire: NO];
77 // }
78
79 /* pathes */
80
81 - (void) setOCSPath: (NSString *) _path
82 {
83   [self warnWithFormat:
84           @"rejected attempt to reset user-folder path: '%@'", _path];
85 }
86
87 - (NSString *) ocsPath
88 {
89   return [NSString stringWithFormat: @"/Users/%@", nameInContainer];
90 }
91
92 - (NSString *) ocsUserPath
93 {
94   return [self ocsPath];
95 }
96
97 - (BOOL) folderIsMandatory
98 {
99   return NO;
100 }
101
102 - (NSString *) ocsPrivateCalendarPath
103 {
104   return [[self ocsUserPath] stringByAppendingString:@"/Calendar/personal"];
105 }
106
107 - (NSString *) ocsPrivateContactsPath
108 {
109   return [[self ocsUserPath] stringByAppendingString:@"/Contacts"];
110 }
111
112 /* name lookup */
113
114 // - (NSString *) permissionForKey: (NSString *) key
115 // {
116 //   return ([key isEqualToString: @"freebusy.ifb"]
117 //           ? SoPerm_WebDAVAccess
118 //           : [super permissionForKey: key]);
119 // }
120
121 - (SOGoAppointmentFolder *) privateCalendar: (NSString *) _key
122                                   inContext: (WOContext *) _ctx
123 {
124   SOGoAppointmentFolder *calendar;
125   
126   calendar = [$(@"SOGoAppointmentFolder") objectWithName: _key inContainer: self];
127   [calendar setOCSPath: [self ocsPrivateCalendarPath]];
128
129   return calendar;
130 }
131
132 - (SOGoContactFolders *) privateContacts: (NSString *) _key
133                                inContext: (WOContext *) _ctx
134 {
135   SOGoContactFolders *contacts;
136
137   contacts = [$(@"SOGoContactFolders") objectWithName:_key inContainer: self];
138   [contacts setBaseOCSPath: [self ocsPrivateContactsPath]];
139
140   return contacts;
141 }
142
143 // - (id) groupsFolder: (NSString *) _key
144 //           inContext: (WOContext *) _ctx
145 // {
146 //   return [$(@"SOGoGroupsFolder") objectWithName: _key inContainer: self];
147 // }
148
149 - (id) mailAccountsFolder: (NSString *) _key
150                 inContext: (WOContext *) _ctx
151 {
152   return [$(@"SOGoMailAccounts") objectWithName: _key inContainer: self];
153 }
154
155 - (id) freeBusyObject: (NSString *) _key
156             inContext: (WOContext *) _ctx
157 {
158   return [$(@"SOGoFreeBusyObject") objectWithName: _key inContainer: self];
159 }
160
161 - (id) lookupName: (NSString *) _key
162         inContext: (WOContext *) _ctx
163           acquire: (BOOL) _flag
164 {
165   id obj;
166   
167   /* first check attributes directly bound to the application */
168   obj = [super lookupName: _key inContext: _ctx acquire: NO];
169   if (!obj)
170     {
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];
184       else
185         obj = [NSException exceptionWithHTTPStatus: 404 /* Not Found */];
186     }
187
188   return obj;
189 }
190
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
196 // {
197 //   NSArray *roles, *traversalPath;
198 //   NSString *objectName, *role;
199
200 //   role = nil;
201 //   traversalPath = [context objectForKey: @"SoRequestTraversalPath"];
202 //   if ([traversalPath count] > 1)
203 //     {
204 //       objectName = [traversalPath objectAtIndex: 1];
205 //       if ([objectName isEqualToString: @"Calendar"]
206 //           || [objectName isEqualToString: @"Contacts"])
207 //         {
208 //           roles = [[context activeUser]
209 //                     rolesForObject: [self lookupName: objectName
210 //                                           inContext: context
211 //                                           acquire: NO]
212 //                     inContext: context];
213 //           if ([roles containsObject: SOGoRole_Assistant]
214 //               || [roles containsObject: SOGoRole_Delegate])
215 //             role = SOGoRole_Assistant;
216 //         }
217 //       else if ([objectName isEqualToString: @"freebusy.ifb"])
218 //         role = SOGoRole_Assistant;
219 //     }
220
221 //   return role;
222 // }
223
224 /* WebDAV */
225
226 - (NSArray *) fetchContentObjectNames
227 {
228   static NSArray *cos = nil;
229   
230   if (!cos)
231     cos = [[NSArray alloc] initWithObjects: @"freebusy.ifb", nil];
232
233   return cos;
234 }
235
236 - (BOOL) davIsCollection
237 {
238   return YES;
239 }
240
241 /* CalDAV support */
242 - (NSArray *) davCalendarHomeSet
243 {
244   /*
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>
249
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.
253   */
254   NSArray *tag;
255
256   tag = [NSArray arrayWithObjects: @"href", @"DAV:", @"D",
257                  [self baseURLInContext: context], nil];
258
259   return [NSArray arrayWithObject: tag];
260 }
261
262 @end /* SOGoUserFolder */