2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004-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.
|
|
|
|
*/
|
|
|
|
|
2006-08-05 01:02:13 +02:00
|
|
|
#import "WOContext+Agenor.h"
|
|
|
|
#import "common.h"
|
2006-08-31 01:11:12 +02:00
|
|
|
#import "SOGoUser.h"
|
2006-08-05 01:02:13 +02:00
|
|
|
|
2006-08-31 01:11:12 +02:00
|
|
|
#import "Appointments/SOGoAppointmentFolder.h"
|
2006-12-14 22:20:13 +01:00
|
|
|
#import "Appointments/SOGoFreeBusyObject.h"
|
2006-08-05 01:02:13 +02:00
|
|
|
#import "Contacts/SOGoContactFolders.h"
|
2006-12-14 22:20:13 +01:00
|
|
|
#import "Mailer/SOGoMailAccounts.h"
|
2006-12-15 23:22:32 +01:00
|
|
|
#import "SOGoPermissions.h"
|
2006-12-14 22:20:13 +01:00
|
|
|
|
|
|
|
#import "SOGoUserFolder.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
@implementation SOGoUserFolder
|
|
|
|
|
|
|
|
/* accessors */
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
- (NSString *) login
|
|
|
|
{
|
|
|
|
return nameInContainer;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* hierarchy */
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
- (NSArray *) toManyRelationshipKeys
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
static NSArray *children = nil;
|
2006-12-14 22:20:13 +01:00
|
|
|
|
|
|
|
if (!children)
|
2006-06-15 21:34:10 +02:00
|
|
|
children = [[NSArray alloc] initWithObjects:
|
|
|
|
@"Calendar", @"Contacts", @"Mail", nil];
|
2006-12-14 22:20:13 +01:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return children;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ownership */
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
- (NSString *) ownerInContext: (WOContext *) _ctx
|
|
|
|
{
|
|
|
|
return nameInContainer;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* looking up shared objects */
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
- (SOGoUserFolder *) lookupUserFolder
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return self;
|
|
|
|
}
|
2006-08-05 01:02:13 +02:00
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
- (SOGoGroupsFolder *) lookupGroupsFolder
|
|
|
|
{
|
|
|
|
return [self lookupName: @"Groups" inContext: nil acquire: NO];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* pathes */
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
- (void) setOCSPath: (NSString *) _path
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
[self warnWithFormat:
|
|
|
|
@"rejected attempt to reset user-folder path: '%@'", _path];
|
|
|
|
}
|
2006-12-14 22:20:13 +01:00
|
|
|
|
|
|
|
- (NSString *) ocsPath
|
|
|
|
{
|
|
|
|
return [@"/Users/" stringByAppendingString: [self login]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
- (NSString *) ocsUserPath
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [self ocsPath];
|
|
|
|
}
|
2006-12-14 22:20:13 +01:00
|
|
|
|
|
|
|
- (NSString *) ocsPrivateCalendarPath
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [[self ocsUserPath] stringByAppendingString:@"/Calendar"];
|
|
|
|
}
|
2006-12-14 22:20:13 +01:00
|
|
|
|
|
|
|
- (NSString *) ocsPrivateContactsPath
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [[self ocsUserPath] stringByAppendingString:@"/Contacts"];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* name lookup */
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
// - (NSString *) permissionForKey: (NSString *) key
|
|
|
|
// {
|
|
|
|
// return ([key isEqualToString: @"freebusy.ifb"]
|
|
|
|
// ? SoPerm_WebDAVAccess
|
|
|
|
// : [super permissionForKey: key]);
|
|
|
|
// }
|
2006-08-31 01:11:12 +02:00
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
- (SOGoAppointmentFolder *) privateCalendar: (NSString *) _key
|
|
|
|
inContext: (WOContext *) _ctx
|
|
|
|
{
|
|
|
|
SOGoAppointmentFolder *calendar;
|
|
|
|
|
|
|
|
calendar = [$(@"SOGoAppointmentFolder") objectWithName: _key inContainer: self];
|
|
|
|
[calendar setOCSPath: [self ocsPrivateCalendarPath]];
|
2006-08-31 01:11:12 +02:00
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
return calendar;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
- (SOGoContactFolders *) privateContacts: (NSString *) _key
|
|
|
|
inContext: (WOContext *) _ctx
|
2006-08-05 01:02:13 +02:00
|
|
|
{
|
|
|
|
SOGoContactFolders *contacts;
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
contacts = [$(@"SOGoContactFolders") objectWithName:_key inContainer: self];
|
|
|
|
[contacts setBaseOCSPath: [self ocsPrivateContactsPath]];
|
2006-08-05 01:02:13 +02:00
|
|
|
|
|
|
|
return contacts;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
- (id) groupsFolder: (NSString *) _key
|
|
|
|
inContext: (WOContext *) _ctx
|
|
|
|
{
|
|
|
|
return [$(@"SOGoGroupsFolder") objectWithName: _key inContainer: self];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
- (id) mailAccountsFolder: (NSString *) _key
|
|
|
|
inContext: (WOContext *) _ctx
|
|
|
|
{
|
|
|
|
return [$(@"SOGoMailAccounts") objectWithName: _key inContainer: self];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
- (id) freeBusyObject: (NSString *) _key
|
|
|
|
inContext: (WOContext *) _ctx
|
|
|
|
{
|
|
|
|
return [$(@"SOGoFreeBusyObject") objectWithName: _key inContainer: self];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
- (id) lookupName: (NSString *) _key
|
|
|
|
inContext: (WOContext *) _ctx
|
|
|
|
acquire: (BOOL) _flag
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
id obj;
|
|
|
|
|
|
|
|
/* first check attributes directly bound to the application */
|
2006-12-14 22:20:13 +01:00
|
|
|
obj = [super lookupName: _key inContext: _ctx acquire: NO];
|
|
|
|
if (!obj)
|
|
|
|
{
|
|
|
|
if ([_key hasPrefix: @"Calendar"])
|
|
|
|
{
|
|
|
|
obj = [self privateCalendar: @"Calendar" inContext: _ctx];
|
|
|
|
if (![_key isEqualToString: @"Calendar"])
|
|
|
|
obj = [obj lookupName: [_key pathExtension]
|
|
|
|
inContext: _ctx acquire: NO];
|
|
|
|
}
|
|
|
|
else if ([_key isEqualToString: @"Contacts"])
|
|
|
|
obj = [self privateContacts: _key inContext: _ctx];
|
|
|
|
else if ([_key isEqualToString: @"Groups"])
|
|
|
|
obj = [self groupsFolder: _key inContext: _ctx];
|
|
|
|
else if ([_key isEqualToString: @"Mail"])
|
|
|
|
obj = [self mailAccountsFolder: _key inContext: _ctx];
|
|
|
|
else if ([_key isEqualToString: @"freebusy.ifb"])
|
|
|
|
obj = [self freeBusyObject:_key inContext:_ctx];
|
|
|
|
else
|
|
|
|
obj = [NSException exceptionWithHTTPStatus: 404 /* Not Found */];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
return obj;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-12-15 23:22:32 +01:00
|
|
|
- (NSString *) roleOfUser: (NSString *) uid
|
|
|
|
inContext: (WOContext *) context
|
|
|
|
{
|
2006-12-15 23:45:30 +01:00
|
|
|
NSArray *roles, *traversalPath;
|
2006-12-15 23:22:32 +01:00
|
|
|
NSString *objectName, *role;
|
|
|
|
|
|
|
|
role = nil;
|
2006-12-15 23:45:30 +01:00
|
|
|
traversalPath = [context objectForKey: @"SoRequestTraversalPath"];
|
|
|
|
if ([traversalPath count] > 1)
|
2006-12-15 23:22:32 +01:00
|
|
|
{
|
2006-12-15 23:45:30 +01:00
|
|
|
objectName = [traversalPath objectAtIndex: 1];
|
|
|
|
if ([objectName isEqualToString: @"Calendar"]
|
|
|
|
|| [objectName isEqualToString: @"Contacts"])
|
|
|
|
{
|
|
|
|
roles = [[context activeUser]
|
|
|
|
rolesForObject: [self lookupName: objectName
|
|
|
|
inContext: context
|
|
|
|
acquire: NO]
|
|
|
|
inContext: context];
|
|
|
|
if ([roles containsObject: SOGoRole_Assistant]
|
|
|
|
|| [roles containsObject: SOGoRole_Delegate])
|
|
|
|
role = SOGoRole_Assistant;
|
|
|
|
}
|
2006-12-15 23:22:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return role;
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* WebDAV */
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
- (NSArray *) fetchContentObjectNames
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
static NSArray *cos = nil;
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
if (!cos)
|
|
|
|
cos = [[NSArray alloc] initWithObjects: @"freebusy.ifb", nil];
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return cos;
|
|
|
|
}
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
- (BOOL) davIsCollection
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end /* SOGoUserFolder */
|