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 <NGCards/iCalPerson.h>
29 #import <SoObjects/SOGo/LDAPUserManager.h>
30 #import <SoObjects/SOGo/SOGoContentObject.h>
31 #import <SoObjects/SOGo/SOGoPermissions.h>
32 #import <SoObjects/SOGo/NSArray+Utilities.h>
34 #import "UIxAclEditor.h"
36 @implementation UIxAclEditor
40 if ((self = [super init]))
44 publishInFreeBusy = NO;
45 users = [NSMutableArray new];
58 [currentUser release];
59 [defaultUserID release];
63 - (NSArray *) aclsForObject
66 aclUsers = [[self clientObject] aclUsers];
71 - (NSString *) _displayNameForUID: (NSString *) uid
75 um = [LDAPUserManager sharedUserManager];
77 return [NSString stringWithFormat: @"%@ <%@>",
78 [um getCNForUID: uid], [um getEmailForUID: uid]];
81 - (NSString *) ownerName
85 ownerLogin = [[self clientObject] ownerInContext: context];
87 return [self _displayNameForUID: ownerLogin];
90 - (NSString *) defaultUserID
93 ASSIGN (defaultUserID, [[self clientObject] defaultUserID]);
98 - (void) _prepareUsers
100 NSEnumerator *aclsEnum;
101 NSString *currentUID, *ownerLogin;
103 ownerLogin = [[self clientObject] ownerInContext: context];
105 ASSIGN (defaultUserID, [[self clientObject] defaultUserID]);
107 aclsEnum = [[self aclsForObject] objectEnumerator];
108 currentUID = [aclsEnum nextObject];
111 if (!([currentUID isEqualToString: ownerLogin]
112 || [currentUID isEqualToString: defaultUserID]))
113 [users addObjectUniquely: currentUID];
114 currentUID = [aclsEnum nextObject];
120 - (NSArray *) usersForObject
123 [self _prepareUsers];
128 - (void) setCurrentUser: (NSString *) newCurrentUser
130 ASSIGN (currentUser, newCurrentUser);
133 - (NSString *) currentUser
138 - (NSString *) currentUserDisplayName
140 return [self _displayNameForUID: currentUser];
143 - (NSString *) toolbar
145 NSString *currentLogin, *ownerLogin;
147 currentLogin = [[context activeUser] login];
148 ownerLogin = [[self clientObject] ownerInContext: context];
150 return (([ownerLogin isEqualToString: currentLogin])
151 ? @"SOGoAclOwner.toolbar" : @"SOGoAclAssistant.toolbar");
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) currentUserIsOwner
192 SOGoObject *clientObject;
193 NSString *currentUserLogin, *ownerLogin;
195 clientObject = [self clientObject];
196 ownerLogin = [clientObject ownerInContext: context];
197 currentUserLogin = [[context activeUser] login];
199 return [ownerLogin isEqualToString: currentUserLogin];
202 // - (id <WOActionResults>) addUserInAcls
204 // SOGoObject *clientObject;
207 // uid = [self queryParameterForKey: @"uid"];
209 // clientObject = [self clientObject];