1 /* UIxAclEditor.m - this file is part of SOGo
3 * Copyright (C) 2006, 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 <Foundation/NSArray.h>
24 #import <Foundation/NSDictionary.h>
25 #import <Foundation/NSKeyValueCoding.h>
26 #import <NGObjWeb/SoUser.h>
27 #import <NGObjWeb/WORequest.h>
28 #import <NGObjWeb/SoSecurityManager.h>
29 #import <NGCards/iCalPerson.h>
30 #import <SoObjects/SOGo/LDAPUserManager.h>
31 #import <SoObjects/SOGo/SOGoContentObject.h>
32 #import <SoObjects/SOGo/SOGoPermissions.h>
33 #import <SoObjects/SOGo/NSArray+Utilities.h>
34 #import <SoObjects/SOGo/SOGoUser.h>
36 #import "UIxAclEditor.h"
38 @implementation UIxAclEditor
42 if ((self = [super init]))
46 publishInFreeBusy = NO;
47 users = [NSMutableArray new];
60 [currentUser release];
61 [defaultUserID release];
65 - (NSArray *) aclsForObject
68 aclUsers = [[self clientObject] aclUsers];
73 - (NSString *) _displayNameForUID: (NSString *) uid
77 um = [LDAPUserManager sharedUserManager];
79 return [NSString stringWithFormat: @"%@ <%@>",
80 [um getCNForUID: uid], [um getEmailForUID: uid]];
83 - (NSString *) ownerName
87 ownerLogin = [[self clientObject] ownerInContext: context];
89 return [self _displayNameForUID: ownerLogin];
96 ownerLogin = [[self clientObject] ownerInContext: context];
98 return (![ownerLogin isEqualToString: @"nobody"]);
101 - (NSString *) defaultUserID
104 ASSIGN (defaultUserID, [[self clientObject] defaultUserID]);
106 return defaultUserID;
109 - (void) _prepareUsers
111 NSEnumerator *aclsEnum;
112 NSString *currentUID, *ownerLogin;
114 ownerLogin = [[self clientObject] ownerInContext: context];
116 ASSIGN (defaultUserID, [[self clientObject] defaultUserID]);
118 aclsEnum = [[self aclsForObject] objectEnumerator];
119 currentUID = [aclsEnum nextObject];
122 if (!([currentUID isEqualToString: ownerLogin]
123 || [currentUID isEqualToString: defaultUserID]))
124 [users addObjectUniquely: currentUID];
125 currentUID = [aclsEnum nextObject];
131 - (NSArray *) usersForObject
134 [self _prepareUsers];
139 - (void) setCurrentUser: (NSString *) newCurrentUser
141 ASSIGN (currentUser, newCurrentUser);
144 - (NSString *) currentUser
149 - (NSString *) currentUserDisplayName
151 return [self _displayNameForUID: currentUser];
154 - (void) setUserUIDS: (NSString *) retainedUsers
156 if ([retainedUsers length] > 0)
157 savedUIDs = [retainedUsers componentsSeparatedByString: @","];
159 savedUIDs = [NSArray new];
162 - (BOOL) shouldTakeValuesFromRequest: (WORequest *) request
163 inContext: (WOContext *) context
165 return ([[request method] isEqualToString: @"POST"]);
168 - (id <WOActionResults>) saveAclsAction
170 NSEnumerator *aclsEnum;
171 SOGoObject *clientObject;
172 NSString *currentUID, *ownerLogin;
174 clientObject = [self clientObject];
175 ownerLogin = [clientObject ownerInContext: context];
176 aclsEnum = [[self aclsForObject] objectEnumerator];
177 currentUID = [[aclsEnum nextObject] objectForKey: @"c_uid"];
180 if ([currentUID isEqualToString: ownerLogin]
181 || [savedUIDs containsObject: currentUID])
182 [users removeObject: currentUID];
183 currentUID = [[aclsEnum nextObject] objectForKey: @"c_uid"];
185 [clientObject removeAclsForUsers: users];
187 return [self jsCloseWithRefreshMethod: nil];
190 - (BOOL) canModifyAcls
192 SoSecurityManager *mgr;
194 mgr = [SoSecurityManager sharedSecurityManager];
196 return (![mgr validatePermission: SOGoPerm_SaveAcls
197 onObject: [self clientObject]
198 inContext: context]);
201 // - (id <WOActionResults>) addUserInAcls
203 // SOGoObject *clientObject;
206 // uid = [self queryParameterForKey: @"uid"];
208 // clientObject = [self clientObject];