2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2005 SKYRIX Software AG
|
|
|
|
|
|
|
|
This file is part of OpenGroupware.org.
|
|
|
|
|
|
|
|
OGo is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
|
|
|
OGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with OGo; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2007-04-17 16:34:31 +02:00
|
|
|
#import <Foundation/NSArray.h>
|
|
|
|
#import <Foundation/NSNull.h>
|
|
|
|
#import <Foundation/NSTimeZone.h>
|
|
|
|
#import <Foundation/NSUserDefaults.h>
|
|
|
|
#import <NGObjWeb/WOApplication.h>
|
2006-12-14 22:20:13 +01:00
|
|
|
#import <NGObjWeb/SoObject.h>
|
2007-04-17 16:34:31 +02:00
|
|
|
#import <NGExtensions/NSNull+misc.h>
|
2006-12-14 22:20:13 +01:00
|
|
|
|
2007-04-17 16:34:31 +02:00
|
|
|
#import "AgenorUserManager.h"
|
|
|
|
#import "SOGoContentObject.h"
|
2006-12-14 22:20:13 +01:00
|
|
|
#import "SOGoUser.h"
|
2007-04-17 16:34:31 +02:00
|
|
|
#import "SOGoPermissions.h"
|
2006-12-14 22:20:13 +01:00
|
|
|
|
2007-04-11 21:07:54 +02:00
|
|
|
static NSTimeZone *serverTimeZone = nil;
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
@interface NSObject (SOGoRoles)
|
|
|
|
|
2007-04-11 21:07:54 +02:00
|
|
|
- (NSArray *) rolesOfUser: (NSString *) uid;
|
2006-12-14 22:20:13 +01:00
|
|
|
|
|
|
|
@end
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
@implementation SOGoUser
|
|
|
|
|
2007-04-11 21:07:54 +02:00
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
NSString *tzName;
|
|
|
|
|
|
|
|
if (!serverTimeZone)
|
|
|
|
{
|
|
|
|
tzName = [[NSUserDefaults standardUserDefaults]
|
|
|
|
stringForKey: @"SOGoServerTimeZone"];
|
|
|
|
if (!tzName)
|
|
|
|
tzName = @"Canada/Eastern";
|
|
|
|
serverTimeZone = [NSTimeZone timeZoneWithName: tzName];
|
|
|
|
[serverTimeZone retain];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (SOGoUser *) userWithLogin: (NSString *) login
|
|
|
|
andRoles: (NSArray *) roles
|
|
|
|
{
|
|
|
|
SOGoUser *user;
|
|
|
|
|
|
|
|
user = [[self alloc] initWithLogin: login roles: roles];
|
|
|
|
[user autorelease];
|
|
|
|
|
|
|
|
return user;
|
|
|
|
}
|
|
|
|
|
2007-03-27 20:16:52 +02:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
userDefaults = nil;
|
|
|
|
userSettings = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2007-04-11 21:07:54 +02:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[userDefaults release];
|
|
|
|
[userSettings release];
|
|
|
|
[cn release];
|
|
|
|
[email release];
|
2006-06-15 21:34:10 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* internals */
|
|
|
|
|
2007-04-11 21:07:54 +02:00
|
|
|
- (AgenorUserManager *) userManager
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
static AgenorUserManager *um = nil;
|
|
|
|
if (um == nil) um = [[AgenorUserManager sharedUserManager] retain];
|
2007-04-11 21:07:54 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return um;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
|
2007-04-11 21:07:54 +02:00
|
|
|
- (NSString *) email
|
|
|
|
{
|
2007-05-03 20:39:03 +02:00
|
|
|
if (!email)
|
2007-04-11 21:07:54 +02:00
|
|
|
{
|
|
|
|
email = [[self userManager] getEmailForUID: [self login]];
|
|
|
|
[email retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return email;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-05-03 20:39:03 +02:00
|
|
|
- (NSString *) systemEmail
|
|
|
|
{
|
|
|
|
if (!systemEmail)
|
|
|
|
{
|
|
|
|
systemEmail = [[self userManager] getSystemEmailForUID: [self login]];
|
|
|
|
[systemEmail retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return systemEmail;
|
|
|
|
}
|
|
|
|
|
2007-04-11 21:07:54 +02:00
|
|
|
- (NSString *) cn
|
|
|
|
{
|
|
|
|
if (cn == nil)
|
|
|
|
{
|
|
|
|
cn = [[self userManager] getCNForUID: [self login]];
|
|
|
|
[cn retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return cn;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-04-11 21:07:54 +02:00
|
|
|
- (NSString *) primaryIMAP4AccountString
|
|
|
|
{
|
|
|
|
return [[self userManager] getIMAPAccountStringForUID: [self login]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-04-11 21:07:54 +02:00
|
|
|
|
|
|
|
- (NSString *) primaryMailServer
|
|
|
|
{
|
|
|
|
return [[self userManager] getServerForUID: [self login]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-04-11 21:07:54 +02:00
|
|
|
- (NSArray *) additionalIMAP4AccountStrings
|
|
|
|
{
|
|
|
|
return [[self userManager]getSharedMailboxAccountStringsForUID: [self login]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-04-11 21:07:54 +02:00
|
|
|
|
|
|
|
- (NSArray *) additionalEMailAddresses
|
|
|
|
{
|
|
|
|
return [[self userManager] getSharedMailboxEMailsForUID: [self login]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-04-11 21:07:54 +02:00
|
|
|
- (NSDictionary *) additionalIMAP4AccountsAndEMails
|
|
|
|
{
|
|
|
|
return [[self userManager] getSharedMailboxesAndEMailsForUID: [self login]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-04-11 21:07:54 +02:00
|
|
|
- (NSURL *) freeBusyURL
|
|
|
|
{
|
|
|
|
return [[self userManager] getFreeBusyURLForUID: [self login]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* defaults */
|
|
|
|
|
2007-03-27 20:16:52 +02:00
|
|
|
- (NSUserDefaults *) userDefaults
|
|
|
|
{
|
|
|
|
if (!userDefaults)
|
|
|
|
{
|
|
|
|
userDefaults = [[self userManager] getUserDefaultsForUID: [self login]];
|
|
|
|
[userDefaults retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return userDefaults;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSUserDefaults *) userSettings
|
|
|
|
{
|
|
|
|
if (!userSettings)
|
|
|
|
{
|
|
|
|
userSettings = [[self userManager] getUserSettingsForUID: [self login]];
|
|
|
|
[userSettings retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return userSettings;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-04-11 21:07:54 +02:00
|
|
|
- (NSTimeZone *) timeZone
|
|
|
|
{
|
|
|
|
NSString *timeZoneName;
|
|
|
|
|
|
|
|
if (!userTimeZone)
|
|
|
|
{
|
|
|
|
timeZoneName = [[self userDefaults] stringForKey: @"TimeZone"];
|
|
|
|
if ([timeZoneName length] > 0)
|
|
|
|
userTimeZone = [NSTimeZone timeZoneWithName: timeZoneName];
|
|
|
|
if (!userTimeZone)
|
2007-04-27 21:02:01 +02:00
|
|
|
userTimeZone = serverTimeZone;
|
2007-04-11 21:07:54 +02:00
|
|
|
[userTimeZone retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return userTimeZone;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSTimeZone *) serverTimeZone
|
|
|
|
{
|
|
|
|
return serverTimeZone;
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* folders */
|
|
|
|
|
|
|
|
// TODO: those methods should check whether the traversal stack in the context
|
|
|
|
// already contains proper folders to improve caching behaviour
|
|
|
|
|
2007-04-11 21:07:54 +02:00
|
|
|
- (id) homeFolderInContext: (id) _ctx
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
/* Note: watch out for cyclic references */
|
|
|
|
// TODO: maybe we should add an [activeUser reset] method to SOPE
|
|
|
|
id folder;
|
|
|
|
|
|
|
|
folder = [(WOContext *)_ctx objectForKey:@"ActiveUserHomeFolder"];
|
|
|
|
if (folder != nil)
|
|
|
|
return [folder isNotNull] ? folder : nil;
|
|
|
|
|
|
|
|
folder = [[WOApplication application] lookupName:[self login]
|
|
|
|
inContext:_ctx acquire:NO];
|
|
|
|
if ([folder isKindOfClass:[NSException class]])
|
|
|
|
return folder;
|
|
|
|
|
|
|
|
[(WOContext *)_ctx setObject:folder ? folder : [NSNull null]
|
2006-12-15 23:21:51 +01:00
|
|
|
forKey: @"ActiveUserHomeFolder"];
|
2006-06-15 21:34:10 +02:00
|
|
|
return folder;
|
|
|
|
}
|
|
|
|
|
2007-04-11 21:07:54 +02:00
|
|
|
- (id) schedulingCalendarInContext: (id) _ctx
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
/* Note: watch out for cyclic references */
|
|
|
|
id folder;
|
|
|
|
|
|
|
|
folder = [(WOContext *)_ctx objectForKey:@"ActiveUserCalendar"];
|
|
|
|
if (folder != nil)
|
|
|
|
return [folder isNotNull] ? folder : nil;
|
|
|
|
|
|
|
|
folder = [self homeFolderInContext:_ctx];
|
|
|
|
if ([folder isKindOfClass:[NSException class]])
|
|
|
|
return folder;
|
|
|
|
|
|
|
|
folder = [folder lookupName:@"Calendar" inContext:_ctx acquire:NO];
|
|
|
|
if ([folder isKindOfClass:[NSException class]])
|
|
|
|
return folder;
|
|
|
|
|
|
|
|
[(WOContext *)_ctx setObject:folder ? folder : [NSNull null]
|
2006-12-15 23:21:51 +01:00
|
|
|
forKey:@"ActiveUserCalendar"];
|
2006-06-15 21:34:10 +02:00
|
|
|
return folder;
|
|
|
|
}
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
- (NSArray *) rolesForObject: (NSObject *) object
|
|
|
|
inContext: (WOContext *) context
|
|
|
|
{
|
|
|
|
NSMutableArray *rolesForObject;
|
|
|
|
NSArray *sogoRoles;
|
|
|
|
|
2007-02-21 22:13:33 +01:00
|
|
|
rolesForObject = [NSMutableArray new];
|
|
|
|
[rolesForObject autorelease];
|
|
|
|
|
|
|
|
sogoRoles = [super rolesForObject: object inContext: context];
|
|
|
|
if (sogoRoles)
|
|
|
|
[rolesForObject addObjectsFromArray: sogoRoles];
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
if ([[object ownerInContext: context] isEqualToString: [self login]])
|
|
|
|
[rolesForObject addObject: SoRole_Owner];
|
|
|
|
if ([object isKindOfClass: [SOGoObject class]])
|
|
|
|
{
|
2007-04-17 16:34:31 +02:00
|
|
|
sogoRoles = [(SOGoObject *) object aclsForUser: login];
|
2007-02-16 17:55:48 +01:00
|
|
|
if (sogoRoles)
|
|
|
|
[rolesForObject addObjectsFromArray: sogoRoles];
|
|
|
|
}
|
2006-12-14 22:20:13 +01:00
|
|
|
|
|
|
|
return rolesForObject;
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@end /* SOGoUser */
|