2006-12-14 21:20:40 +01:00
|
|
|
/* UIxAclEditor.m - this file is part of SOGo
|
|
|
|
*
|
2009-09-25 16:42:33 +02:00
|
|
|
* Copyright (C) 2006-2009 Inverse inc.
|
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>
|
2008-07-04 18:06:09 +02:00
|
|
|
#import <Foundation/NSEnumerator.h>
|
2006-12-14 21:20:40 +01:00
|
|
|
#import <Foundation/NSKeyValueCoding.h>
|
2008-07-04 18:06:09 +02:00
|
|
|
|
2006-12-14 21:20:40 +01:00
|
|
|
#import <NGObjWeb/SoUser.h>
|
|
|
|
#import <NGObjWeb/WORequest.h>
|
2007-12-07 00:09:58 +01:00
|
|
|
#import <NGObjWeb/SoSecurityManager.h>
|
2006-12-14 21:20:40 +01:00
|
|
|
#import <NGCards/iCalPerson.h>
|
2009-09-25 16:42:33 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoUserManager.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>
|
2007-11-21 17:05:07 +01:00
|
|
|
#import <SoObjects/SOGo/SOGoUser.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
|
|
|
|
{
|
2009-09-25 16:42:33 +02:00
|
|
|
SOGoUserManager *um;
|
2009-05-03 19:50:57 +02:00
|
|
|
NSString *s;
|
2007-03-29 20:09:18 +02:00
|
|
|
|
2009-09-25 16:42:33 +02:00
|
|
|
um = [SOGoUserManager sharedUserManager];
|
2009-05-03 19:50:57 +02:00
|
|
|
s = [uid hasPrefix: @"@"] ? [uid substringFromIndex: 1] : uid;
|
2007-03-29 20:09:18 +02:00
|
|
|
|
|
|
|
return [NSString stringWithFormat: @"%@ <%@>",
|
2009-05-03 19:50:57 +02:00
|
|
|
[um getCNForUID: s], [um getEmailForUID: s]];
|
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
|
|
|
{
|
2009-05-03 19:50:57 +02:00
|
|
|
if ([currentUID hasPrefix: @"@"])
|
|
|
|
// NOTE: don't remove the prefix if we want to identify the lists visually
|
|
|
|
currentUID = [currentUID substringFromIndex: 1];
|
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];
|
|
|
|
}
|
|
|
|
|
2007-04-17 15:56:19 +02:00
|
|
|
- (void) setUserUIDS: (NSString *) retainedUsers
|
|
|
|
{
|
|
|
|
if ([retainedUsers length] > 0)
|
2009-10-13 16:04:02 +02:00
|
|
|
{
|
|
|
|
savedUIDs = [retainedUsers componentsSeparatedByString: @","];
|
|
|
|
[savedUIDs retain];
|
|
|
|
}
|
2007-04-17 15:56:19 +02:00
|
|
|
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-12-07 00:09:58 +01:00
|
|
|
- (BOOL) canModifyAcls
|
2007-05-04 17:57:12 +02:00
|
|
|
{
|
2007-12-07 00:09:58 +01:00
|
|
|
SoSecurityManager *mgr;
|
|
|
|
|
|
|
|
mgr = [SoSecurityManager sharedSecurityManager];
|
|
|
|
|
2008-05-03 01:14:51 +02:00
|
|
|
return (![mgr validatePermission: SoPerm_ChangePermissions
|
2007-12-07 00:09:58 +01:00
|
|
|
onObject: [self clientObject]
|
|
|
|
inContext: context]);
|
2007-05-04 17:57:12 +02:00
|
|
|
}
|
|
|
|
|
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
|