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