2006-12-14 21:20:40 +01:00
|
|
|
/* UIxAclEditor.m - this file is part of SOGo
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Inverse groupe conseil
|
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Foundation/NSArray.h>
|
2007-01-31 19:42:59 +01:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2006-12-14 21:20:40 +01:00
|
|
|
#import <Foundation/NSKeyValueCoding.h>
|
|
|
|
#import <NGObjWeb/SoUser.h>
|
|
|
|
#import <NGObjWeb/WORequest.h>
|
|
|
|
#import <NGCards/iCalPerson.h>
|
|
|
|
#import <SoObjects/SOGo/AgenorUserManager.h>
|
|
|
|
#import <SoObjects/SOGo/SOGoAclsFolder.h>
|
|
|
|
#import <SoObjects/SOGo/SOGoPermissions.h>
|
|
|
|
|
|
|
|
#import "UIxAclEditor.h"
|
|
|
|
|
|
|
|
@implementation UIxAclEditor
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
acls = nil;
|
|
|
|
prepared = NO;
|
2006-12-20 17:43:55 +01:00
|
|
|
publishInFreeBusy = NO;
|
2006-12-14 21:20:40 +01:00
|
|
|
users = [NSMutableArray new];
|
2007-01-03 22:13:28 +01:00
|
|
|
delegates = [NSMutableArray new];
|
|
|
|
assistants = [NSMutableArray new];
|
2007-03-29 20:09:18 +02:00
|
|
|
ownerLogin = nil;
|
|
|
|
currentUser = nil;
|
2006-12-14 21:20:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[users release];
|
2007-01-03 22:13:28 +01:00
|
|
|
[delegates release];
|
|
|
|
[assistants release];
|
2007-03-29 20:09:18 +02:00
|
|
|
[ownerLogin release];
|
|
|
|
[currentUser release];
|
2006-12-14 21:20:40 +01:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) aclsForFolder
|
|
|
|
{
|
|
|
|
SOGoAclsFolder *folder;
|
|
|
|
|
|
|
|
if (!acls)
|
|
|
|
{
|
|
|
|
folder = [SOGoAclsFolder aclsFolder];
|
|
|
|
acls = [folder aclsForObject: [self clientObject]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return acls;
|
|
|
|
}
|
|
|
|
|
2007-03-29 20:09:18 +02:00
|
|
|
- (NSString *) ownerLogin
|
2006-12-14 21:20:40 +01:00
|
|
|
{
|
2007-03-29 20:09:18 +02:00
|
|
|
if (!ownerLogin)
|
2006-12-14 21:20:40 +01:00
|
|
|
{
|
2007-03-29 20:09:18 +02:00
|
|
|
ownerLogin = [[self clientObject] ownerInContext: context];
|
|
|
|
[ownerLogin retain];
|
2006-12-14 21:20:40 +01:00
|
|
|
}
|
|
|
|
|
2007-03-29 20:09:18 +02:00
|
|
|
return ownerLogin;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) _displayNameForUID: (NSString *) uid
|
|
|
|
{
|
|
|
|
AgenorUserManager *um;
|
|
|
|
|
|
|
|
um = [AgenorUserManager sharedUserManager];
|
|
|
|
|
|
|
|
return [NSString stringWithFormat: @"%@ <%@>",
|
|
|
|
[um getCNForUID: uid],
|
|
|
|
[um getEmailForUID: uid]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) ownerName
|
|
|
|
{
|
|
|
|
return [self _displayNameForUID: [self ownerLogin]];
|
2006-12-14 21:20:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _prepareUsers
|
|
|
|
{
|
|
|
|
NSEnumerator *aclsEnum;
|
|
|
|
AgenorUserManager *um;
|
|
|
|
NSDictionary *currentAcl;
|
|
|
|
NSString *currentUID;
|
|
|
|
|
|
|
|
aclsEnum = [[self aclsForFolder] objectEnumerator];
|
|
|
|
um = [AgenorUserManager sharedUserManager];
|
|
|
|
currentAcl = [aclsEnum nextObject];
|
|
|
|
while (currentAcl)
|
|
|
|
{
|
2006-12-15 23:22:44 +01:00
|
|
|
currentUID = [currentAcl objectForKey: @"c_uid"];
|
2006-12-20 17:43:55 +01:00
|
|
|
if ([currentUID isEqualToString: @"freebusy"])
|
|
|
|
publishInFreeBusy = YES;
|
|
|
|
else
|
2006-12-14 21:20:40 +01:00
|
|
|
{
|
2007-03-29 20:09:18 +02:00
|
|
|
if (![[um getCNForUID: currentUID]
|
|
|
|
isEqualToString: [self ownerLogin]])
|
2006-12-14 21:20:40 +01:00
|
|
|
{
|
2006-12-15 23:22:44 +01:00
|
|
|
if ([[currentAcl objectForKey: @"c_role"]
|
2006-12-14 21:20:40 +01:00
|
|
|
isEqualToString: SOGoRole_Delegate])
|
2007-03-29 20:09:18 +02:00
|
|
|
[delegates addObject: currentUID];
|
2007-01-03 22:13:28 +01:00
|
|
|
else
|
2007-03-29 20:09:18 +02:00
|
|
|
[assistants addObject: currentUID];
|
|
|
|
[users addObject: currentUID];
|
2006-12-14 21:20:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
currentAcl = [aclsEnum nextObject];
|
|
|
|
|
|
|
|
prepared = YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) usersForFolder
|
|
|
|
{
|
|
|
|
if (!prepared)
|
|
|
|
[self _prepareUsers];
|
|
|
|
|
|
|
|
return users;
|
|
|
|
}
|
|
|
|
|
2007-03-29 20:09:18 +02:00
|
|
|
- (void) setCurrentUser: (NSString *) newCurrentUser
|
|
|
|
{
|
|
|
|
ASSIGN (currentUser, newCurrentUser);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) currentUser
|
|
|
|
{
|
|
|
|
return currentUser;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) currentUserDisplayName
|
|
|
|
{
|
|
|
|
return [self _displayNameForUID: currentUser];
|
|
|
|
}
|
|
|
|
|
2007-01-03 22:13:28 +01:00
|
|
|
- (NSArray *) delegates
|
2006-12-14 21:20:40 +01:00
|
|
|
{
|
|
|
|
if (!prepared)
|
|
|
|
[self _prepareUsers];
|
|
|
|
|
2007-01-03 22:13:28 +01:00
|
|
|
return delegates;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) assistantsValue
|
|
|
|
{
|
|
|
|
if (!prepared)
|
|
|
|
[self _prepareUsers];
|
|
|
|
|
|
|
|
return [assistants componentsJoinedByString: @","];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) delegatesValue
|
|
|
|
{
|
|
|
|
if (!prepared)
|
|
|
|
[self _prepareUsers];
|
|
|
|
|
|
|
|
return [delegates componentsJoinedByString: @","];
|
2006-12-14 21:20:40 +01:00
|
|
|
}
|
|
|
|
|
2006-12-20 17:43:55 +01:00
|
|
|
- (BOOL) publishInFreeBusy
|
|
|
|
{
|
|
|
|
if (!prepared)
|
|
|
|
[self _prepareUsers];
|
|
|
|
|
|
|
|
return publishInFreeBusy;
|
|
|
|
}
|
|
|
|
|
2006-12-14 21:20:40 +01:00
|
|
|
- (NSString *) toolbar
|
|
|
|
{
|
2007-03-29 20:09:18 +02:00
|
|
|
NSString *currentLogin;
|
|
|
|
|
|
|
|
currentLogin = [[context activeUser] login];
|
|
|
|
|
|
|
|
return (([[self ownerLogin] isEqualToString: currentLogin])
|
2006-12-14 21:20:40 +01:00
|
|
|
? @"SOGoAclOwner.toolbar" : @"SOGoAclAssistant.toolbar");
|
|
|
|
}
|
|
|
|
|
2006-12-20 17:43:55 +01:00
|
|
|
- (BOOL) clientIsCalendar
|
|
|
|
{
|
|
|
|
return [NSStringFromClass ([[self clientObject] class])
|
|
|
|
isEqualToString: @"SOGoAppointmentFolder"];
|
|
|
|
}
|
|
|
|
|
2006-12-14 21:20:40 +01:00
|
|
|
- (id) saveAclsAction
|
|
|
|
{
|
|
|
|
NSString *uids;
|
2006-12-20 17:43:55 +01:00
|
|
|
NSArray *fbUsers;
|
2006-12-14 21:20:40 +01:00
|
|
|
WORequest *request;
|
|
|
|
SOGoAclsFolder *folder;
|
|
|
|
SOGoObject *clientObject;
|
|
|
|
|
|
|
|
folder = [SOGoAclsFolder aclsFolder];
|
|
|
|
request = [context request];
|
|
|
|
clientObject = [self clientObject];
|
|
|
|
uids = [request formValueForKey: @"delegates"];
|
|
|
|
[folder setRoleForObject: clientObject
|
|
|
|
forUsers: [uids componentsSeparatedByString: @","]
|
|
|
|
to: SOGoRole_Delegate];
|
|
|
|
uids = [request formValueForKey: @"assistants"];
|
|
|
|
[folder setRoleForObject: clientObject
|
|
|
|
forUsers: [uids componentsSeparatedByString: @","]
|
|
|
|
to: SOGoRole_Assistant];
|
2006-12-20 17:43:55 +01:00
|
|
|
if ([self clientIsCalendar]) {
|
|
|
|
if ([[request formValueForKey: @"freebusy"] intValue])
|
|
|
|
fbUsers = [NSArray arrayWithObject: @"freebusy"];
|
|
|
|
else
|
|
|
|
fbUsers = nil;
|
|
|
|
[folder setRoleForObject: clientObject
|
|
|
|
forUsers: fbUsers
|
|
|
|
to: SOGoRole_FreeBusy];
|
|
|
|
}
|
2006-12-14 21:20:40 +01:00
|
|
|
|
|
|
|
return [self jsCloseWithRefreshMethod: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|