2 Copyright (C) 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 #import <Foundation/NSArray.h>
23 #import <Foundation/NSNull.h>
24 #import <Foundation/NSTimeZone.h>
25 #import <Foundation/NSUserDefaults.h>
26 #import <NGObjWeb/WOApplication.h>
27 #import <NGObjWeb/SoObject.h>
28 #import <NGExtensions/NSNull+misc.h>
30 #import "AgenorUserManager.h"
31 #import "SOGoContentObject.h"
33 #import "SOGoPermissions.h"
35 static NSTimeZone *serverTimeZone = nil;
37 @interface NSObject (SOGoRoles)
39 - (NSArray *) rolesOfUser: (NSString *) uid;
43 @implementation SOGoUser
51 tzName = [[NSUserDefaults standardUserDefaults]
52 stringForKey: @"SOGoServerTimeZone"];
54 tzName = @"Canada/Eastern";
55 serverTimeZone = [NSTimeZone timeZoneWithName: tzName];
56 [serverTimeZone retain];
60 + (SOGoUser *) userWithLogin: (NSString *) login
61 andRoles: (NSArray *) roles
65 user = [[self alloc] initWithLogin: login roles: roles];
73 if ((self = [super init]))
84 [userDefaults release];
85 [userSettings release];
93 - (AgenorUserManager *) userManager
95 static AgenorUserManager *um = nil;
96 if (um == nil) um = [[AgenorUserManager sharedUserManager] retain];
107 email = [[self userManager] getEmailForUID: [self login]];
118 cn = [[self userManager] getCNForUID: [self login]];
125 - (NSString *) primaryIMAP4AccountString
127 return [[self userManager] getIMAPAccountStringForUID: [self login]];
130 - (NSString *) primaryMailServer
132 return [[self userManager] getServerForUID: [self login]];
135 - (NSArray *) additionalIMAP4AccountStrings
137 return [[self userManager]getSharedMailboxAccountStringsForUID: [self login]];
140 - (NSArray *) additionalEMailAddresses
142 return [[self userManager] getSharedMailboxEMailsForUID: [self login]];
145 - (NSDictionary *) additionalIMAP4AccountsAndEMails
147 return [[self userManager] getSharedMailboxesAndEMailsForUID: [self login]];
150 - (NSURL *) freeBusyURL
152 return [[self userManager] getFreeBusyURLForUID: [self login]];
157 - (NSUserDefaults *) userDefaults
161 userDefaults = [[self userManager] getUserDefaultsForUID: [self login]];
162 [userDefaults retain];
168 - (NSUserDefaults *) userSettings
172 userSettings = [[self userManager] getUserSettingsForUID: [self login]];
173 [userSettings retain];
179 - (NSTimeZone *) timeZone
181 NSString *timeZoneName;
185 timeZoneName = [[self userDefaults] stringForKey: @"TimeZone"];
186 if ([timeZoneName length] > 0)
187 userTimeZone = [NSTimeZone timeZoneWithName: timeZoneName];
189 userTimeZone = serverTimeZone;
190 [userTimeZone retain];
196 - (NSTimeZone *) serverTimeZone
198 return serverTimeZone;
203 // TODO: those methods should check whether the traversal stack in the context
204 // already contains proper folders to improve caching behaviour
206 - (id) homeFolderInContext: (id) _ctx
208 /* Note: watch out for cyclic references */
209 // TODO: maybe we should add an [activeUser reset] method to SOPE
212 folder = [(WOContext *)_ctx objectForKey:@"ActiveUserHomeFolder"];
214 return [folder isNotNull] ? folder : nil;
216 folder = [[WOApplication application] lookupName:[self login]
217 inContext:_ctx acquire:NO];
218 if ([folder isKindOfClass:[NSException class]])
221 [(WOContext *)_ctx setObject:folder ? folder : [NSNull null]
222 forKey: @"ActiveUserHomeFolder"];
226 - (id) schedulingCalendarInContext: (id) _ctx
228 /* Note: watch out for cyclic references */
231 folder = [(WOContext *)_ctx objectForKey:@"ActiveUserCalendar"];
233 return [folder isNotNull] ? folder : nil;
235 folder = [self homeFolderInContext:_ctx];
236 if ([folder isKindOfClass:[NSException class]])
239 folder = [folder lookupName:@"Calendar" inContext:_ctx acquire:NO];
240 if ([folder isKindOfClass:[NSException class]])
243 [(WOContext *)_ctx setObject:folder ? folder : [NSNull null]
244 forKey:@"ActiveUserCalendar"];
248 - (NSArray *) rolesForObject: (NSObject *) object
249 inContext: (WOContext *) context
251 NSMutableArray *rolesForObject;
254 rolesForObject = [NSMutableArray new];
255 [rolesForObject autorelease];
257 sogoRoles = [super rolesForObject: object inContext: context];
259 [rolesForObject addObjectsFromArray: sogoRoles];
261 if ([[object ownerInContext: context] isEqualToString: [self login]])
262 [rolesForObject addObject: SoRole_Owner];
263 if ([object isKindOfClass: [SOGoObject class]])
265 sogoRoles = [(SOGoObject *) object aclsForUser: login];
267 [rolesForObject addObjectsFromArray: sogoRoles];
270 return rolesForObject;