]> err.no Git - scalable-opengroupware.org/blob - SoObjects/SOGo/SOGoUserFolder.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1087 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 [@"/Users/" stringByAppendingString: [self login]];
90 }
91
92 - (NSString *) ocsUserPath
93 {
94   return [self ocsPath];
95 }
96
97 - (NSString *) ocsPrivateCalendarPath
98 {
99   return [[self ocsUserPath] stringByAppendingString:@"/Calendar"];
100 }
101
102 - (NSString *) ocsPrivateContactsPath
103 {
104   return [[self ocsUserPath] stringByAppendingString:@"/Contacts"];
105 }
106
107 /* name lookup */
108
109 // - (NSString *) permissionForKey: (NSString *) key
110 // {
111 //   return ([key isEqualToString: @"freebusy.ifb"]
112 //           ? SoPerm_WebDAVAccess
113 //           : [super permissionForKey: key]);
114 // }
115
116 - (SOGoAppointmentFolder *) privateCalendar: (NSString *) _key
117                                   inContext: (WOContext *) _ctx
118 {
119   SOGoAppointmentFolder *calendar;
120   
121   calendar = [$(@"SOGoAppointmentFolder") objectWithName: _key inContainer: self];
122   [calendar setOCSPath: [self ocsPrivateCalendarPath]];
123
124   return calendar;
125 }
126
127 - (SOGoContactFolders *) privateContacts: (NSString *) _key
128                                inContext: (WOContext *) _ctx
129 {
130   SOGoContactFolders *contacts;
131
132   contacts = [$(@"SOGoContactFolders") objectWithName:_key inContainer: self];
133   [contacts setBaseOCSPath: [self ocsPrivateContactsPath]];
134
135   return contacts;
136 }
137
138 // - (id) groupsFolder: (NSString *) _key
139 //           inContext: (WOContext *) _ctx
140 // {
141 //   return [$(@"SOGoGroupsFolder") objectWithName: _key inContainer: self];
142 // }
143
144 - (id) mailAccountsFolder: (NSString *) _key
145                 inContext: (WOContext *) _ctx
146 {
147   return [$(@"SOGoMailAccounts") objectWithName: _key inContainer: self];
148 }
149
150 - (id) freeBusyObject: (NSString *) _key
151             inContext: (WOContext *) _ctx
152 {
153   return [$(@"SOGoFreeBusyObject") objectWithName: _key inContainer: self];
154 }
155
156 - (id) lookupName: (NSString *) _key
157         inContext: (WOContext *) _ctx
158           acquire: (BOOL) _flag
159 {
160   id obj;
161   
162   /* first check attributes directly bound to the application */
163   obj = [super lookupName: _key inContext: _ctx acquire: NO];
164   if (!obj)
165     {
166       if ([_key hasPrefix: @"Calendar"])
167         {
168           obj = [self privateCalendar: @"Calendar" inContext: _ctx];
169           if (![_key isEqualToString: @"Calendar"])
170             obj = [obj lookupName: [_key pathExtension] 
171                        inContext: _ctx acquire: NO];
172         }
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];
181       else
182         obj = [NSException exceptionWithHTTPStatus: 404 /* Not Found */];
183     }
184
185   return obj;
186 }
187
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
193 // {
194 //   NSArray *roles, *traversalPath;
195 //   NSString *objectName, *role;
196
197 //   role = nil;
198 //   traversalPath = [context objectForKey: @"SoRequestTraversalPath"];
199 //   if ([traversalPath count] > 1)
200 //     {
201 //       objectName = [traversalPath objectAtIndex: 1];
202 //       if ([objectName isEqualToString: @"Calendar"]
203 //           || [objectName isEqualToString: @"Contacts"])
204 //         {
205 //           roles = [[context activeUser]
206 //                     rolesForObject: [self lookupName: objectName
207 //                                           inContext: context
208 //                                           acquire: NO]
209 //                     inContext: context];
210 //           if ([roles containsObject: SOGoRole_Assistant]
211 //               || [roles containsObject: SOGoRole_Delegate])
212 //             role = SOGoRole_Assistant;
213 //         }
214 //       else if ([objectName isEqualToString: @"freebusy.ifb"])
215 //         role = SOGoRole_Assistant;
216 //     }
217
218 //   return role;
219 // }
220
221 /* WebDAV */
222
223 - (NSArray *) fetchContentObjectNames
224 {
225   static NSArray *cos = nil;
226   
227   if (!cos)
228     cos = [[NSArray alloc] initWithObjects: @"freebusy.ifb", nil];
229
230   return cos;
231 }
232
233 - (BOOL) davIsCollection
234 {
235   return YES;
236 }
237
238 /* CalDAV support */
239 - (NSArray *) davCalendarHomeSet
240 {
241   /*
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>
246
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.
250   */
251   NSArray *tag;
252
253   tag = [NSArray arrayWithObjects: @"href", @"DAV:", @"D",
254                  [self baseURLInContext: context], nil];
255
256   return [NSArray arrayWithObject: tag];
257 }
258
259 @end /* SOGoUserFolder */