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];
94 ownerLogin = [[self clientObject] ownerInContext: context];
96 return (![ownerLogin isEqualToString: @"nobody"]);
99 - (NSString *) defaultUserID
102 ASSIGN (defaultUserID, [[self clientObject] defaultUserID]);
104 return defaultUserID;
107 - (void) _prepareUsers
109 NSEnumerator *aclsEnum;
110 NSString *currentUID, *ownerLogin;
112 ownerLogin = [[self clientObject] ownerInContext: context];
114 ASSIGN (defaultUserID, [[self clientObject] defaultUserID]);
116 aclsEnum = [[self aclsForObject] objectEnumerator];
117 currentUID = [aclsEnum nextObject];
120 if (!([currentUID isEqualToString: ownerLogin]
121 || [currentUID isEqualToString: defaultUserID]))
122 [users addObjectUniquely: currentUID];
123 currentUID = [aclsEnum nextObject];
129 - (NSArray *) usersForObject
132 [self _prepareUsers];
137 - (void) setCurrentUser: (NSString *) newCurrentUser
139 ASSIGN (currentUser, newCurrentUser);
142 - (NSString *) currentUser
147 - (NSString *) currentUserDisplayName
149 return [self _displayNameForUID: currentUser];
152 - (NSString *) toolbar
154 NSString *currentLogin, *ownerLogin;
156 currentLogin = [[context activeUser] login];
157 ownerLogin = [[self clientObject] ownerInContext: context];
159 return (([ownerLogin isEqualToString: currentLogin])
160 ? @"SOGoAclOwner.toolbar" : @"SOGoAclAssistant.toolbar");
163 - (void) setUserUIDS: (NSString *) retainedUsers
165 if ([retainedUsers length] > 0)
166 savedUIDs = [retainedUsers componentsSeparatedByString: @","];
168 savedUIDs = [NSArray new];
171 - (BOOL) shouldTakeValuesFromRequest: (WORequest *) request
172 inContext: (WOContext *) context
174 return ([[request method] isEqualToString: @"POST"]);
177 - (id <WOActionResults>) saveAclsAction
179 NSEnumerator *aclsEnum;
180 SOGoObject *clientObject;
181 NSString *currentUID, *ownerLogin;
183 clientObject = [self clientObject];
184 ownerLogin = [clientObject ownerInContext: context];
185 aclsEnum = [[self aclsForObject] objectEnumerator];
186 currentUID = [[aclsEnum nextObject] objectForKey: @"c_uid"];
189 if ([currentUID isEqualToString: ownerLogin]
190 || [savedUIDs containsObject: currentUID])
191 [users removeObject: currentUID];
192 currentUID = [[aclsEnum nextObject] objectForKey: @"c_uid"];
194 [clientObject removeAclsForUsers: users];
196 return [self jsCloseWithRefreshMethod: nil];
199 - (BOOL) currentUserIsOwner
201 SOGoObject *clientObject;
202 NSString *currentUserLogin, *ownerLogin;
204 clientObject = [self clientObject];
205 ownerLogin = [clientObject ownerInContext: context];
206 currentUserLogin = [[context activeUser] login];
208 return [ownerLogin isEqualToString: currentUserLogin];
211 // - (id <WOActionResults>) addUserInAcls
213 // SOGoObject *clientObject;
216 // uid = [self queryParameterForKey: @"uid"];
218 // clientObject = [self clientObject];