2006-12-14 21:20:40 +01:00
|
|
|
/* UIxAclEditor.m - this file is part of SOGo
|
|
|
|
*
|
2007-04-17 15:56:19 +02:00
|
|
|
* Copyright (C) 2006, 2007 Inverse groupe conseil
|
2006-12-14 21:20:40 +01:00
|
|
|
*
|
|
|
|
* 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>
|
2007-05-09 20:25:51 +02:00
|
|
|
#import <SoObjects/SOGo/LDAPUserManager.h>
|
2007-04-17 15:56:19 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoContentObject.h>
|
2006-12-14 21:20:40 +01:00
|
|
|
#import <SoObjects/SOGo/SOGoPermissions.h>
|
2007-05-19 02:43:40 +02:00
|
|
|
#import <SoObjects/SOGo/NSArray+Utilities.h>
|
2006-12-14 21:20:40 +01:00
|
|
|
|
|
|
|
#import "UIxAclEditor.h"
|
|
|
|
|
|
|
|
@implementation UIxAclEditor
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
2007-05-19 02:43:40 +02:00
|
|
|
aclUsers = nil;
|
2006-12-14 21:20:40 +01:00
|
|
|
prepared = NO;
|
2006-12-20 17:43:55 +01:00
|
|
|
publishInFreeBusy = NO;
|
2006-12-14 21:20:40 +01:00
|
|
|
users = [NSMutableArray new];
|
2007-03-29 20:09:18 +02:00
|
|
|
currentUser = nil;
|
2007-05-22 21:30:36 +02:00
|
|
|
defaultUserID = nil;
|
2007-04-17 15:56:19 +02:00
|
|
|
savedUIDs = nil;
|
2006-12-14 21:20:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2007-04-17 15:56:19 +02:00
|
|
|
[savedUIDs release];
|
2006-12-14 21:20:40 +01:00
|
|
|
[users release];
|
2007-03-29 20:09:18 +02:00
|
|
|
[currentUser release];
|
2007-05-22 21:30:36 +02:00
|
|
|
[defaultUserID release];
|
2006-12-14 21:20:40 +01:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2007-04-17 15:56:19 +02:00
|
|
|
- (NSArray *) aclsForObject
|
2006-12-14 21:20:40 +01:00
|
|
|
{
|
2007-05-19 02:43:40 +02:00
|
|
|
if (!aclUsers)
|
|
|
|
aclUsers = [[self clientObject] aclUsers];
|
2006-12-14 21:20:40 +01:00
|
|
|
|
2007-05-19 02:43:40 +02:00
|
|
|
return aclUsers;
|
2006-12-14 21:20:40 +01:00
|
|
|
}
|
|
|
|
|
2007-03-29 20:09:18 +02:00
|
|
|
- (NSString *) _displayNameForUID: (NSString *) uid
|
|
|
|
{
|
2007-05-09 20:25:51 +02:00
|
|
|
LDAPUserManager *um;
|
2007-03-29 20:09:18 +02:00
|
|
|
|
2007-05-09 20:25:51 +02:00
|
|
|
um = [LDAPUserManager sharedUserManager];
|
2007-03-29 20:09:18 +02:00
|
|
|
|
|
|
|
return [NSString stringWithFormat: @"%@ <%@>",
|
2007-05-09 20:25:51 +02:00
|
|
|
[um getCNForUID: uid], [um getEmailForUID: uid]];
|
2007-03-29 20:09:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) ownerName
|
|
|
|
{
|
2007-04-17 15:56:19 +02:00
|
|
|
NSString *ownerLogin;
|
|
|
|
|
|
|
|
ownerLogin = [[self clientObject] ownerInContext: context];
|
|
|
|
|
|
|
|
return [self _displayNameForUID: ownerLogin];
|
2006-12-14 21:20:40 +01:00
|
|
|
}
|
|
|
|
|
2007-10-17 00:29:08 +02:00
|
|
|
- (BOOL) hasOwner
|
|
|
|
{
|
|
|
|
NSString *ownerLogin;
|
|
|
|
|
|
|
|
ownerLogin = [[self clientObject] ownerInContext: context];
|
|
|
|
|
|
|
|
return (![ownerLogin isEqualToString: @"nobody"]);
|
|
|
|
}
|
|
|
|
|
2007-05-18 01:07:31 +02:00
|
|
|
- (NSString *) defaultUserID
|
|
|
|
{
|
2007-05-22 20:40:45 +02:00
|
|
|
if (!defaultUserID)
|
|
|
|
ASSIGN (defaultUserID, [[self clientObject] defaultUserID]);
|
|
|
|
|
|
|
|
return defaultUserID;
|
2007-05-18 01:07:31 +02:00
|
|
|
}
|
|
|
|
|
2006-12-14 21:20:40 +01:00
|
|
|
- (void) _prepareUsers
|
|
|
|
{
|
|
|
|
NSEnumerator *aclsEnum;
|
2007-04-17 15:56:19 +02:00
|
|
|
NSString *currentUID, *ownerLogin;
|
2006-12-14 21:20:40 +01:00
|
|
|
|
2007-04-17 15:56:19 +02:00
|
|
|
ownerLogin = [[self clientObject] ownerInContext: context];
|
2007-05-22 20:40:45 +02:00
|
|
|
if (!defaultUserID)
|
|
|
|
ASSIGN (defaultUserID, [[self clientObject] defaultUserID]);
|
2007-04-17 15:56:19 +02:00
|
|
|
|
|
|
|
aclsEnum = [[self aclsForObject] objectEnumerator];
|
2007-05-19 02:43:40 +02:00
|
|
|
currentUID = [aclsEnum nextObject];
|
|
|
|
while (currentUID)
|
2006-12-14 21:20:40 +01:00
|
|
|
{
|
2007-04-25 00:46:52 +02:00
|
|
|
if (!([currentUID isEqualToString: ownerLogin]
|
2007-05-22 20:40:45 +02:00
|
|
|
|| [currentUID isEqualToString: defaultUserID]))
|
2007-05-19 02:43:40 +02:00
|
|
|
[users addObjectUniquely: currentUID];
|
|
|
|
currentUID = [aclsEnum nextObject];
|
2006-12-14 21:20:40 +01:00
|
|
|
}
|
2007-05-22 20:40:45 +02:00
|
|
|
|
2007-05-19 02:43:40 +02:00
|
|
|
prepared = YES;
|
2006-12-14 21:20:40 +01:00
|
|
|
}
|
|
|
|
|
2007-04-17 15:56:19 +02:00
|
|
|
- (NSArray *) usersForObject
|
2006-12-14 21:20:40 +01:00
|
|
|
{
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2006-12-14 21:20:40 +01:00
|
|
|
- (NSString *) toolbar
|
|
|
|
{
|
2007-04-17 15:56:19 +02:00
|
|
|
NSString *currentLogin, *ownerLogin;
|
2007-03-29 20:09:18 +02:00
|
|
|
|
|
|
|
currentLogin = [[context activeUser] login];
|
2007-04-17 15:56:19 +02:00
|
|
|
ownerLogin = [[self clientObject] ownerInContext: context];
|
2007-03-29 20:09:18 +02:00
|
|
|
|
2007-04-17 15:56:19 +02:00
|
|
|
return (([ownerLogin isEqualToString: currentLogin])
|
2006-12-14 21:20:40 +01:00
|
|
|
? @"SOGoAclOwner.toolbar" : @"SOGoAclAssistant.toolbar");
|
|
|
|
}
|
|
|
|
|
2007-04-17 15:56:19 +02:00
|
|
|
- (void) setUserUIDS: (NSString *) retainedUsers
|
|
|
|
{
|
|
|
|
if ([retainedUsers length] > 0)
|
|
|
|
savedUIDs = [retainedUsers componentsSeparatedByString: @","];
|
|
|
|
else
|
|
|
|
savedUIDs = [NSArray new];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) shouldTakeValuesFromRequest: (WORequest *) request
|
|
|
|
inContext: (WOContext *) context
|
2006-12-20 17:43:55 +01:00
|
|
|
{
|
2007-04-17 15:56:19 +02:00
|
|
|
return ([[request method] isEqualToString: @"POST"]);
|
2006-12-20 17:43:55 +01:00
|
|
|
}
|
|
|
|
|
2007-04-17 15:56:19 +02:00
|
|
|
- (id <WOActionResults>) saveAclsAction
|
2006-12-14 21:20:40 +01:00
|
|
|
{
|
2007-04-17 15:56:19 +02:00
|
|
|
NSEnumerator *aclsEnum;
|
2006-12-14 21:20:40 +01:00
|
|
|
SOGoObject *clientObject;
|
2007-04-17 15:56:19 +02:00
|
|
|
NSString *currentUID, *ownerLogin;
|
2006-12-14 21:20:40 +01:00
|
|
|
|
|
|
|
clientObject = [self clientObject];
|
2007-04-17 15:56:19 +02:00
|
|
|
ownerLogin = [clientObject ownerInContext: context];
|
|
|
|
aclsEnum = [[self aclsForObject] objectEnumerator];
|
|
|
|
currentUID = [[aclsEnum nextObject] objectForKey: @"c_uid"];
|
|
|
|
while (currentUID)
|
|
|
|
{
|
|
|
|
if ([currentUID isEqualToString: ownerLogin]
|
|
|
|
|| [savedUIDs containsObject: currentUID])
|
|
|
|
[users removeObject: currentUID];
|
|
|
|
currentUID = [[aclsEnum nextObject] objectForKey: @"c_uid"];
|
|
|
|
}
|
|
|
|
[clientObject removeAclsForUsers: users];
|
2006-12-14 21:20:40 +01:00
|
|
|
|
|
|
|
return [self jsCloseWithRefreshMethod: nil];
|
|
|
|
}
|
|
|
|
|
2007-05-04 17:57:12 +02:00
|
|
|
- (BOOL) currentUserIsOwner
|
|
|
|
{
|
|
|
|
SOGoObject *clientObject;
|
|
|
|
NSString *currentUserLogin, *ownerLogin;
|
|
|
|
|
|
|
|
clientObject = [self clientObject];
|
|
|
|
ownerLogin = [clientObject ownerInContext: context];
|
|
|
|
currentUserLogin = [[context activeUser] login];
|
|
|
|
|
|
|
|
return [ownerLogin isEqualToString: currentUserLogin];
|
|
|
|
}
|
|
|
|
|
2007-04-17 15:56:19 +02:00
|
|
|
// - (id <WOActionResults>) addUserInAcls
|
|
|
|
// {
|
|
|
|
// SOGoObject *clientObject;
|
|
|
|
// NSString *uid;
|
|
|
|
|
|
|
|
// uid = [self queryParameterForKey: @"uid"];
|
|
|
|
|
|
|
|
// clientObject = [self clientObject];
|
|
|
|
// }
|
|
|
|
|
2006-12-14 21:20:40 +01:00
|
|
|
@end
|