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/WOApplication.h>
25 #import <NGObjWeb/WOResponse.h>
26 #import <NGObjWeb/WORequest.h>
27 #import <SoObjects/SOGo/LDAPUserManager.h>
28 #import <SoObjects/SOGo/SOGoPermissions.h>
29 #import <SoObjects/SOGo/SOGoObject.h>
30 #import <SoObjects/SOGo/SOGoUser.h>
31 #import <UI/SOGoUI/SOGoACLAdvisory.h>
32 #import <Foundation/NSUserDefaults.h>
34 #import "UIxUserRightsEditor.h"
36 static BOOL sendACLAdvisories = NO;
38 @implementation UIxUserRightsEditor
44 ud = [NSUserDefaults standardUserDefaults];
45 sendACLAdvisories = [ud boolForKey: @"SOGoACLsSendEMailNotifications"];
50 if ((self = [super init]))
53 userRights = [NSMutableArray new];
64 [defaultUserID release];
73 - (BOOL) userIsDefaultUser
76 ASSIGN (defaultUserID, [[self clientObject] defaultUserID]);
78 return [uid isEqualToString: defaultUserID];
81 - (NSString *) userDisplayName
85 um = [LDAPUserManager sharedUserManager];
87 return [NSString stringWithFormat: @"%@ <%@>",
88 [um getCNForUID: uid],
89 [um getEmailForUID: uid]];
97 SOGoObject *clientObject;
101 newUID = [[context request] formValueForKey: @"uid"];
102 if ([newUID length] > 0)
105 ASSIGN (defaultUserID, [[self clientObject] defaultUserID]);
107 um = [LDAPUserManager sharedUserManager];
108 if ([newUID isEqualToString: defaultUserID]
109 || [[um getEmailForUID: newUID] length] > 0)
111 ASSIGN (uid, newUID);
112 clientObject = [self clientObject];
113 [userRights addObjectsFromArray: [clientObject aclsForUser: uid]];
122 - (id <WOActionResults>) defaultAction
124 id <WOActionResults> response;
126 if (![self _initRights])
127 response = [NSException exceptionWithHTTPStatus: 403
128 reason: @"No such user."];
131 [self prepareRightsForm];
138 - (void) sendACLAdvisoryTemplateForObject: (id) theObject
140 NSString *language, *pageName;
142 SOGoACLAdvisory *page;
145 user = [SOGoUser userWithLogin: uid roles: nil];
146 language = [user language];
147 pageName = [NSString stringWithFormat: @"SOGoACL%@ModificationAdvisory",
150 app = [WOApplication application];
151 page = [app pageWithName: pageName inContext: context];
152 [page setACLObject: theObject];
153 [page setRecipientUID: uid];
157 - (id <WOActionResults>) saveUserRightsAction
159 id <WOActionResults> response;
161 if (![self _initRights])
162 response = [NSException exceptionWithHTTPStatus: 403
163 reason: @"No such user."];
168 o = [NSArray arrayWithArray: userRights];
171 [[self clientObject] setRoles: userRights forUser: uid];
173 if (![o isEqualToArray: userRights] && sendACLAdvisories)
175 [self sendACLAdvisoryTemplateForObject: [self clientObject]];
178 response = [self jsCloseWithRefreshMethod: nil];
184 - (void) appendRight: (NSString *) newRight
186 if (![userRights containsObject: newRight])
187 [userRights addObject: newRight];
190 - (void) removeRight: (NSString *) right
192 if ([userRights containsObject: right])
193 [userRights removeObject: right];
196 - (void) appendExclusiveRight: (NSString *) newRight
197 fromList: (NSArray *) list
199 [userRights removeObjectsInArray: list];
200 [self appendRight: newRight];
203 - (void) removeAllRightsFromList: (NSArray *) list
205 [userRights removeObjectsInArray: list];
208 - (void) prepareRightsForm
212 - (void) updateRights
214 [self subclassResponsibility: _cmd];