]> err.no Git - scalable-opengroupware.org/blob - SoObjects/SOGo/SOGoUserFolder.m
initial sync
[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 - (NSString *) roleOfUser: (NSString *) uid
185                 inContext: (WOContext *) context
186 {
187   NSArray *roles, *traversalPath;
188   NSString *objectName, *role;
189
190   role = nil;
191   traversalPath = [context objectForKey: @"SoRequestTraversalPath"];
192   if ([traversalPath count] > 1)
193     {
194       objectName = [traversalPath objectAtIndex: 1];
195       if ([objectName isEqualToString: @"Calendar"]
196           || [objectName isEqualToString: @"Contacts"])
197         {
198           roles = [[context activeUser]
199                     rolesForObject: [self lookupName: objectName
200                                           inContext: context
201                                           acquire: NO]
202                     inContext: context];
203           if ([roles containsObject: SOGoRole_Assistant]
204               || [roles containsObject: SOGoRole_Delegate])
205             role = SOGoRole_Assistant;
206         }
207     }
208
209   return role;
210 }
211
212 /* WebDAV */
213
214 - (NSArray *) fetchContentObjectNames
215 {
216   static NSArray *cos = nil;
217   
218   if (!cos)
219     cos = [[NSArray alloc] initWithObjects: @"freebusy.ifb", nil];
220
221   return cos;
222 }
223
224 - (BOOL) davIsCollection
225 {
226   return YES;
227 }
228
229 @end /* SOGoUserFolder */