]> err.no Git - scalable-opengroupware.org/blob - SOGo/SoObjects/SOGo/SOGoUserFolder.m
added class versions to some files
[scalable-opengroupware.org] / SOGo / 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 #include "SOGoUserFolder.h"
23 #include "WOContext+Agenor.h"
24 #include "common.h"
25
26 @implementation SOGoUserFolder
27
28 /* accessors */
29
30 - (NSString *)login {
31   return [self nameInContainer];
32 }
33
34 /* hierarchy */
35
36 - (NSArray *)toManyRelationshipKeys {
37   static NSArray *children = nil;
38   
39   if (children == nil) {
40     children = [[NSArray alloc] initWithObjects:
41                                   @"Calendar", @"Contacts", @"Mail", nil];
42   }
43   return children;
44 }
45
46 /* ownership */
47
48 - (NSString *)ownerInContext:(id)_ctx {
49   return [self login];
50 }
51
52 /* looking up shared objects */
53
54 - (SOGoUserFolder *)lookupUserFolder {
55   return self;
56 }
57 - (SOGoGroupsFolder *)lookupGroupsFolder {
58   return [self lookupName:@"Groups" inContext:nil acquire:NO];
59 }
60
61 /* pathes */
62
63 - (void)setOCSPath:(NSString *)_path {
64   [self warnWithFormat:
65           @"rejected attempt to reset user-folder path: '%@'", _path];
66 }
67 - (NSString *)ocsPath {
68   return [@"/Users/" stringByAppendingString:[self login]];
69 }
70
71 - (NSString *)ocsUserPath {
72   return [self ocsPath];
73 }
74 - (NSString *)ocsPrivateCalendarPath {
75   return [[self ocsUserPath] stringByAppendingString:@"/Calendar"];
76 }
77 - (NSString *)ocsPrivateContactsPath {
78   return [[self ocsUserPath] stringByAppendingString:@"/Contacts"];
79 }
80
81 /* name lookup */
82
83 - (id)privateCalendar:(NSString *)_key inContext:(id)_ctx {
84   static Class calClass = Nil;
85   id calendar;
86   
87   if (calClass == Nil)
88     calClass = NSClassFromString(@"SOGoAppointmentFolder");
89   if (calClass == Nil) {
90     [self errorWithFormat:@"missing SOGoAppointmentFolder class!"];
91     return nil;
92   }
93   
94   calendar = [[calClass alloc] initWithName:_key inContainer:self];
95   [calendar setOCSPath:[self ocsPrivateCalendarPath]];
96   return [calendar autorelease];
97 }
98
99 - (id)privateContacts:(NSString *)_key inContext:(id)_ctx {
100   static Class calClass = Nil;
101   id calendar;
102   
103   if (calClass == Nil)
104     calClass = NSClassFromString(@"SOGoContactFolder");
105   if (calClass == Nil) {
106     [self errorWithFormat:@"missing SOGoContactFolder class!"];
107     return nil;
108   }
109   
110   calendar = [[calClass alloc] initWithName:_key inContainer:self];
111   [calendar setOCSPath:[self ocsPrivateContactsPath]];
112   return [calendar autorelease];
113 }
114
115 - (id)groupsFolder:(NSString *)_key inContext:(id)_ctx {
116   static Class fldClass = Nil;
117   id folder;
118   
119   if (fldClass == Nil)
120     fldClass = NSClassFromString(@"SOGoGroupsFolder");
121   if (fldClass == Nil) {
122     [self errorWithFormat:@"missing SOGoGroupsFolder class!"];
123     return nil;
124   }
125   
126   folder = [[fldClass alloc] initWithName:_key inContainer:self];
127   return [folder autorelease];
128 }
129
130 - (id)mailAccountsFolder:(NSString *)_key inContext:(id)_ctx {
131   static Class fldClass = Nil;
132   id folder;
133   
134   if (fldClass == Nil)
135     fldClass = NSClassFromString(@"SOGoMailAccounts");
136   if (fldClass == Nil) {
137     [self errorWithFormat:@"missing SOGoMailAccounts class!"];
138     return nil;
139   }
140   
141   folder = [[fldClass alloc] initWithName:_key inContainer:self];
142   return [folder autorelease];
143 }
144
145 - (id)freeBusyObject:(NSString *)_key inContext:(id)_ctx {
146   static Class fbClass = Nil;
147   id fb;
148
149   if (fbClass == Nil)
150     fbClass = NSClassFromString(@"SOGoFreeBusyObject");
151   if (fbClass == Nil) {
152     [self errorWithFormat:@"missing SOGoFreeBusyObject class!"];
153     return nil;
154   }
155   
156   fb = [[fbClass alloc] initWithName:_key inContainer:self];
157   return [fb autorelease];
158 }
159
160 - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag {
161   id obj;
162   
163   /* first check attributes directly bound to the application */
164   if ((obj = [super lookupName:_key inContext:_ctx acquire:NO]))
165     return obj;
166   
167   if ([_key hasPrefix:@"Calendar"]) {
168     id calendar;
169     
170     calendar = [self privateCalendar:@"Calendar" inContext:_ctx];
171     if ([_key isEqualToString:@"Calendar"])
172       return calendar;
173     
174     return [calendar lookupName:[_key pathExtension] 
175                      inContext:_ctx acquire:NO];
176   }
177
178   if ([_key isEqualToString:@"Contacts"])
179     return [self privateContacts:_key inContext:_ctx];
180   
181   if ([_key isEqualToString:@"Groups"]) {
182     /* Agenor requirement, return 403 to stop acquisition */
183     if (![_ctx isAccessFromIntranet]) {
184       return [NSException exceptionWithHTTPStatus:403 /* Forbidden */];
185     }
186     return [self groupsFolder:_key inContext:_ctx];
187   }
188
189   if ([_key isEqualToString:@"Mail"])
190     return [self mailAccountsFolder:_key inContext:_ctx];
191
192   if ([_key isEqualToString:@"freebusy.ifb"])
193     return [self freeBusyObject:_key inContext:_ctx];
194
195   /* return 404 to stop acquisition */
196   return [NSException exceptionWithHTTPStatus:404 /* Not Found */];
197 }
198
199 /* WebDAV */
200
201 - (NSArray *)fetchContentObjectNames {
202   static NSArray *cos = nil;
203   
204   if (!cos) {
205     cos = [[NSArray alloc] initWithObjects:@"freebusy.ifb", nil];
206   }
207   return cos;
208 }
209
210 - (BOOL)davIsCollection {
211   return YES;
212 }
213
214 @end /* SOGoUserFolder */