2 Copyright (C) 2004-2005 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
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
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.
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
22 #include <NGObjWeb/SoComponent.h>
24 @interface SOGoUserHomePage : SoComponent
29 - (NSString *)ownPath;
30 - (NSString *)userFolderPath;
31 - (NSString *)relativePathToUserFolderSubPath:(NSString *)_sub;
33 - (NSString *)relativeCalendarPath;
34 - (NSString *)relativeContactsPath;
35 - (NSString *)relativeMailPath;
39 #include <SOGo/AgenorUserManager.h>
43 @implementation SOGoUserHomePage
45 static NSArray *internetAccessStates = nil;
48 static BOOL didInit = NO;
53 internetAccessStates = [[NSArray alloc] initWithObjects:@"0", @"1", nil];
63 - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag {
64 // Note: we do no acquisition
67 /* first check attributes directly bound to the object */
68 if ((obj = [super lookupName:_key inContext:_ctx acquire:NO]))
76 - (void)setItem:(id)_item {
77 ASSIGN(self->item, _item);
83 - (NSArray *)internetAccessStates {
84 return internetAccessStates;
87 - (NSString *)internetAccessState {
91 ud = [[[self context] activeUser] userDefaults];
92 value = [ud objectForKey:@"allowinternet"];
93 return [NSString stringWithFormat:@"%d", [value boolValue]];
95 - (void)setInternetAccessState:(NSString *)_internetAccessState {
98 ud = [[[self context] activeUser] userDefaults];
99 [ud setObject:_internetAccessState forKey:@"allowinternet"];
103 - (NSString *)itemInternetAccessStateText {
106 key = [NSString stringWithFormat:@"internetAccessState_%@", self->item];
112 - (NSString *)ownPath {
116 uri = [[[self context] request] uri];
118 /* first: cut off query parameters */
120 r = [uri rangeOfString:@"?" options:NSBackwardsSearch];
122 uri = [uri substringToIndex:r.location];
126 - (NSString *)userFolderPath {
128 NSArray *traversalObjects;
131 ctx = [self context];
132 traversalObjects = [ctx objectTraversalStack];
133 url = [[traversalObjects objectAtIndex:1]
134 baseURLInContext:ctx];
135 return [[NSURL URLWithString:url] path];
138 - (NSString *)relativePathToUserFolderSubPath:(NSString *)_sub {
141 dst = [[self userFolderPath] stringByAppendingPathComponent:_sub];
142 rel = [dst urlPathRelativeToPath:[self ownPath]];
146 - (NSString *)relativeCalendarPath {
147 return [self relativePathToUserFolderSubPath:@"Calendar/"];
150 - (NSString *)relativeContactsPath {
151 return [self relativePathToUserFolderSubPath:@"Contacts/"];
154 - (NSString *)relativeMailPath {
155 return [self relativePathToUserFolderSubPath:@"Mail/"];
160 - (id)calendarFolder {
161 return [[self clientObject] lookupName:@"Calendar"
162 inContext:[self context]
166 /* checking access */
172 ctx = [self context];
173 owner = [[self clientObject] ownerInContext:ctx];
174 return [owner isEqualToString:[[ctx activeUser] login]];
177 - (BOOL)isNotAllowedToChangeInternetAccess {
178 AgenorUserManager *um;
182 ctx = [self context];
183 /* do not allow changes when access is from Internet */
184 if (![ctx isAccessFromIntranet])
186 um = [AgenorUserManager sharedUserManager];
187 uid = [[ctx activeUser] login];
188 return [um isUserAllowedToChangeSOGoInternetAccess:uid] ? NO : YES;
191 - (BOOL)isVacationMessageEnabledForInternet {
195 - (BOOL)isVacationMessageEnabledForIntranet {
202 - (id)defaultAction {
203 return [self redirectToLocation:[self relativeCalendarPath]];
207 /* this is triggered by an XMLHTTPRequest */
208 - (id)saveInternetAccessStateAction {
211 if ([self isNotAllowedToChangeInternetAccess])
212 return [NSException exceptionWithHTTPStatus:403 /* Forbidden */];
214 state = [[[self context] request] formValueForKey:@"allowinternet"];
215 [self setInternetAccessState:state];
216 return [NSException exceptionWithHTTPStatus:200 /* OK */];
219 @end /* SOGoUserHomePage */