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>
40 #include <SOGo/WOContext+Agenor.h>
41 #include <SOGo/SOGoUser.h>
44 @implementation SOGoUserHomePage
46 static NSArray *internetAccessStates = nil;
49 static BOOL didInit = NO;
54 internetAccessStates = [[NSArray alloc] initWithObjects:@"0", @"1", nil];
64 - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag {
65 // Note: we do no acquisition
68 /* first check attributes directly bound to the object */
69 if ((obj = [super lookupName:_key inContext:_ctx acquire:NO]))
77 - (void)setItem:(id)_item {
78 ASSIGN(self->item, _item);
84 - (NSArray *)internetAccessStates {
85 return internetAccessStates;
88 - (NSString *)internetAccessState {
92 ud = [[[self context] activeUser] userDefaults];
93 value = [ud objectForKey:@"allowinternet"];
94 return [NSString stringWithFormat:@"%d", [value boolValue]];
96 - (void)setInternetAccessState:(NSString *)_internetAccessState {
99 ud = [[[self context] activeUser] userDefaults];
100 [ud setObject:_internetAccessState forKey:@"allowinternet"];
104 - (NSString *)itemInternetAccessStateText {
107 key = [NSString stringWithFormat:@"internetAccessState_%@", self->item];
113 - (NSString *)ownPath {
117 uri = [[[self context] request] uri];
119 /* first: cut off query parameters */
121 r = [uri rangeOfString:@"?" options:NSBackwardsSearch];
123 uri = [uri substringToIndex:r.location];
127 - (NSString *)userFolderPath {
129 NSArray *traversalObjects;
132 ctx = [self context];
133 traversalObjects = [ctx objectTraversalStack];
134 url = [[traversalObjects objectAtIndex:1]
135 baseURLInContext:ctx];
136 return [[NSURL URLWithString:url] path];
139 - (NSString *)relativePathToUserFolderSubPath:(NSString *)_sub {
142 dst = [[self userFolderPath] stringByAppendingPathComponent:_sub];
143 rel = [dst urlPathRelativeToPath:[self ownPath]];
147 - (NSString *)relativeCalendarPath {
148 return [self relativePathToUserFolderSubPath:@"Calendar/"];
151 - (NSString *)relativeContactsPath {
152 return [self relativePathToUserFolderSubPath:@"Contacts/"];
155 - (NSString *)relativeMailPath {
156 return [self relativePathToUserFolderSubPath:@"Mail/"];
161 - (id)calendarFolder {
162 return [[self clientObject] lookupName:@"Calendar"
163 inContext:[self context]
167 /* checking access */
173 ctx = [self context];
174 owner = [[self clientObject] ownerInContext:ctx];
175 return [owner isEqualToString:[[ctx activeUser] login]];
178 - (BOOL)isNotAllowedToChangeInternetAccess {
179 // TODO: should be a SOGoUser method
180 AgenorUserManager *um;
184 ctx = [self context];
185 /* do not allow changes when access is from Internet */
186 if (![ctx isAccessFromIntranet])
188 um = [AgenorUserManager sharedUserManager];
189 uid = [[ctx activeUser] login];
190 return [um isUserAllowedToChangeSOGoInternetAccess:uid] ? NO : YES;
193 - (BOOL)isVacationMessageEnabledForInternet {
194 // TODO: should be a SOGoUser method
195 AgenorUserManager *um;
198 um = [AgenorUserManager sharedUserManager];
199 uid = [[[self context] activeUser] login];
200 return [um isInternetAutoresponderEnabledForUser:uid];
203 - (BOOL)isVacationMessageEnabledForIntranet {
204 // TODO: should be a SOGoUser method
205 AgenorUserManager *um;
208 um = [AgenorUserManager sharedUserManager];
209 uid = [[[self context] activeUser] login];
210 return [um isIntranetAutoresponderEnabledForUser:uid];
216 - (id)defaultAction {
217 return [self redirectToLocation:[self relativeCalendarPath]];
221 /* this is triggered by an XMLHTTPRequest */
222 - (id)saveInternetAccessStateAction {
225 if ([self isNotAllowedToChangeInternetAccess])
226 return [NSException exceptionWithHTTPStatus:403 /* Forbidden */];
228 state = [[[self context] request] formValueForKey:@"allowinternet"];
229 [self setInternetAccessState:state];
230 return [NSException exceptionWithHTTPStatus:200 /* OK */];
233 @end /* SOGoUserHomePage */