1 /* UIxUserRightsEditor.m - this file is part of SOGo
3 * Copyright (C) 2007 Inverse groupe conseil
5 * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
7 * This file is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This file is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #import <NGObjWeb/NSException+HTTP.h>
24 #import <NGObjWeb/WOResponse.h>
25 #import <NGObjWeb/WORequest.h>
26 #import <SoObjects/SOGo/LDAPUserManager.h>
27 #import <SoObjects/SOGo/SOGoPermissions.h>
28 #import <SoObjects/SOGo/SOGoObject.h>
30 #import "UIxUserRightsEditor.h"
32 @implementation UIxUserRightsEditor
36 if ((self = [super init]))
39 userRights = [NSMutableArray new];
50 [defaultUserID release];
59 - (BOOL) userIsDefaultUser
62 ASSIGN (defaultUserID, [[self clientObject] defaultUserID]);
64 return [uid isEqualToString: defaultUserID];
67 - (NSString *) userDisplayName
71 um = [LDAPUserManager sharedUserManager];
73 return [NSString stringWithFormat: @"%@ <%@>",
74 [um getCNForUID: uid],
75 [um getEmailForUID: uid]];
83 SOGoObject *clientObject;
87 newUID = [[context request] formValueForKey: @"uid"];
88 if ([newUID length] > 0)
91 ASSIGN (defaultUserID, [[self clientObject] defaultUserID]);
93 um = [LDAPUserManager sharedUserManager];
94 if ([newUID isEqualToString: defaultUserID]
95 || [[um getEmailForUID: newUID] length] > 0)
98 clientObject = [self clientObject];
99 [userRights addObjectsFromArray: [clientObject aclsForUser: uid]];
108 - (id <WOActionResults>) defaultAction
110 id <WOActionResults> response;
112 if (![self _initRights])
113 response = [NSException exceptionWithHTTPStatus: 403
114 reason: @"No such user."];
117 [self prepareRightsForm];
124 - (id <WOActionResults>) saveUserRightsAction
126 id <WOActionResults> response;
128 if (![self _initRights])
129 response = [NSException exceptionWithHTTPStatus: 403
130 reason: @"No such user."];
134 [[self clientObject] setRoles: userRights forUser: uid];
135 response = [self jsCloseWithRefreshMethod: nil];
141 - (void) appendRight: (NSString *) newRight
143 if (![userRights containsObject: newRight])
144 [userRights addObject: newRight];
147 - (void) removeRight: (NSString *) right
149 if ([userRights containsObject: right])
150 [userRights removeObject: right];
153 - (void) appendExclusiveRight: (NSString *) newRight
154 fromList: (NSArray *) list
156 [userRights removeObjectsInArray: list];
157 [self appendRight: newRight];
160 - (void) removeAllRightsFromList: (NSArray *) list
162 [userRights removeObjectsInArray: list];
165 - (void) prepareRightsForm
169 - (void) updateRights
171 [self subclassResponsibility: _cmd];