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/AgenorUserManager.h>
28 #import "UIxUserRightsEditor.h"
30 @implementation UIxUserRightsEditor
34 if ((self = [super init]))
37 userRights = [NSMutableArray new];
55 - (NSString *) userDisplayName
57 AgenorUserManager *um;
59 um = [AgenorUserManager sharedUserManager];
61 return [NSString stringWithFormat: @"%@ <%@>",
62 [um getCNForUID: uid],
63 [um getEmailForUID: uid]];
69 NSString *newUID, *email;
70 AgenorUserManager *um;
71 SOGoObject *clientObject;
75 newUID = [[context request] formValueForKey: @"uid"];
76 if ([newUID length] > 0)
78 um = [AgenorUserManager sharedUserManager];
79 email = [um getEmailForUID: newUID];
80 if ([email length] > 0)
83 clientObject = [self clientObject];
84 [userRights addObjectsFromArray: [clientObject aclsForUser: uid]];
85 if (![userRights count])
86 [userRights addObjectsFromArray: [clientObject defaultAclRoles]];
95 - (id <WOActionResults>) defaultAction
97 id <WOActionResults> response;
99 if (![self _initRights])
100 response = [NSException exceptionWithHTTPStatus: 403
101 reason: @"No such user."];
104 [self prepareRightsForm];
111 - (id <WOActionResults>) saveUserRightsAction
113 id <WOActionResults> response;
115 if (![self _initRights])
116 response = [NSException exceptionWithHTTPStatus: 403
117 reason: @"No such user."];
121 [[self clientObject] setRoles: userRights
123 response = [self jsCloseWithRefreshMethod: nil];
129 - (void) appendRight: (NSString *) newRight
131 if (![userRights containsObject: newRight])
132 [userRights addObject: newRight];
135 - (void) removeRight: (NSString *) right
137 if ([userRights containsObject: right])
138 [userRights removeObject: right];
141 - (void) appendExclusiveRight: (NSString *) newRight
142 fromList: (NSArray *) list
144 [userRights removeObjectsInArray: list];
145 [self appendRight: newRight];
148 - (void) removeAllRightsFromList: (NSArray *) list
150 [userRights removeObjectsInArray: list];
153 - (void) prepareRightsForm
157 - (void) updateRights
159 [self subclassResponsibility: _cmd];