2007-04-23 17:09:43 +02:00
|
|
|
/* UIxUserRightsEditor.m - this file is part of SOGo
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 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.
|
|
|
|
*/
|
|
|
|
|
2007-04-25 00:49:38 +02:00
|
|
|
#import <NGObjWeb/NSException+HTTP.h>
|
|
|
|
#import <NGObjWeb/WOResponse.h>
|
|
|
|
#import <NGObjWeb/WORequest.h>
|
2007-05-09 20:25:51 +02:00
|
|
|
#import <SoObjects/SOGo/LDAPUserManager.h>
|
2007-05-18 01:05:47 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoPermissions.h>
|
2007-05-22 20:40:05 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoObject.h>
|
2007-04-25 00:49:38 +02:00
|
|
|
|
2007-04-23 17:09:43 +02:00
|
|
|
#import "UIxUserRightsEditor.h"
|
|
|
|
|
|
|
|
@implementation UIxUserRightsEditor
|
|
|
|
|
2007-04-25 00:49:38 +02:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
uid = nil;
|
|
|
|
userRights = [NSMutableArray new];
|
2007-05-22 20:40:05 +02:00
|
|
|
defaultUserID = nil;
|
2007-04-25 00:49:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[uid release];
|
|
|
|
[userRights release];
|
2007-05-22 21:30:36 +02:00
|
|
|
[defaultUserID release];
|
2007-04-25 00:49:38 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) uid
|
|
|
|
{
|
|
|
|
return uid;
|
|
|
|
}
|
|
|
|
|
2007-05-18 01:05:47 +02:00
|
|
|
- (BOOL) userIsDefaultUser
|
|
|
|
{
|
2007-05-22 20:40:05 +02:00
|
|
|
if (!defaultUserID)
|
|
|
|
ASSIGN (defaultUserID, [[self clientObject] defaultUserID]);
|
|
|
|
|
|
|
|
return [uid isEqualToString: defaultUserID];
|
2007-05-18 01:05:47 +02:00
|
|
|
}
|
|
|
|
|
2007-04-25 00:49:38 +02:00
|
|
|
- (NSString *) userDisplayName
|
|
|
|
{
|
2007-05-09 20:25:51 +02:00
|
|
|
LDAPUserManager *um;
|
2007-05-18 01:05:47 +02:00
|
|
|
|
2007-05-09 20:25:51 +02:00
|
|
|
um = [LDAPUserManager sharedUserManager];
|
2007-04-25 00:49:38 +02:00
|
|
|
|
|
|
|
return [NSString stringWithFormat: @"%@ <%@>",
|
|
|
|
[um getCNForUID: uid],
|
|
|
|
[um getEmailForUID: uid]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) _initRights
|
|
|
|
{
|
|
|
|
BOOL response;
|
2007-05-18 01:05:47 +02:00
|
|
|
NSString *newUID;
|
2007-05-09 20:25:51 +02:00
|
|
|
LDAPUserManager *um;
|
2007-04-25 00:49:38 +02:00
|
|
|
SOGoObject *clientObject;
|
|
|
|
|
|
|
|
response = NO;
|
|
|
|
|
|
|
|
newUID = [[context request] formValueForKey: @"uid"];
|
|
|
|
if ([newUID length] > 0)
|
|
|
|
{
|
2007-05-22 20:40:05 +02:00
|
|
|
if (!defaultUserID)
|
|
|
|
ASSIGN (defaultUserID, [[self clientObject] defaultUserID]);
|
|
|
|
|
2007-05-09 20:25:51 +02:00
|
|
|
um = [LDAPUserManager sharedUserManager];
|
2007-05-22 20:40:05 +02:00
|
|
|
if ([newUID isEqualToString: defaultUserID]
|
2007-05-18 01:05:47 +02:00
|
|
|
|| [[um getEmailForUID: newUID] length] > 0)
|
2007-04-25 00:49:38 +02:00
|
|
|
{
|
|
|
|
ASSIGN (uid, newUID);
|
|
|
|
clientObject = [self clientObject];
|
|
|
|
[userRights addObjectsFromArray: [clientObject aclsForUser: uid]];
|
2007-05-18 01:05:47 +02:00
|
|
|
|
2007-04-25 00:49:38 +02:00
|
|
|
response = YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id <WOActionResults>) defaultAction
|
|
|
|
{
|
|
|
|
id <WOActionResults> response;
|
|
|
|
|
|
|
|
if (![self _initRights])
|
|
|
|
response = [NSException exceptionWithHTTPStatus: 403
|
|
|
|
reason: @"No such user."];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self prepareRightsForm];
|
|
|
|
response = self;
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id <WOActionResults>) saveUserRightsAction
|
|
|
|
{
|
|
|
|
id <WOActionResults> response;
|
|
|
|
|
|
|
|
if (![self _initRights])
|
|
|
|
response = [NSException exceptionWithHTTPStatus: 403
|
|
|
|
reason: @"No such user."];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self updateRights];
|
2007-05-18 01:05:47 +02:00
|
|
|
[[self clientObject] setRoles: userRights forUser: uid];
|
2007-04-25 00:49:38 +02:00
|
|
|
response = [self jsCloseWithRefreshMethod: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) appendRight: (NSString *) newRight
|
|
|
|
{
|
|
|
|
if (![userRights containsObject: newRight])
|
|
|
|
[userRights addObject: newRight];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) removeRight: (NSString *) right
|
|
|
|
{
|
|
|
|
if ([userRights containsObject: right])
|
|
|
|
[userRights removeObject: right];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) appendExclusiveRight: (NSString *) newRight
|
|
|
|
fromList: (NSArray *) list
|
|
|
|
{
|
|
|
|
[userRights removeObjectsInArray: list];
|
|
|
|
[self appendRight: newRight];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) removeAllRightsFromList: (NSArray *) list
|
|
|
|
{
|
|
|
|
[userRights removeObjectsInArray: list];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) prepareRightsForm
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) updateRights
|
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
}
|
|
|
|
|
2007-04-23 17:09:43 +02:00
|
|
|
@end
|