1 /* UIxAclEditor.m - this file is part of SOGo
3 * Copyright (C) 2006 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/AgenorUserManager.h>
30 #import <SoObjects/SOGo/SOGoAclsFolder.h>
31 #import <SoObjects/SOGo/SOGoPermissions.h>
33 #import "UIxAclEditor.h"
35 @implementation UIxAclEditor
39 if ((self = [super init]))
43 publishInFreeBusy = NO;
44 users = [NSMutableArray new];
45 delegates = [NSMutableArray new];
46 assistants = [NSMutableArray new];
60 [currentUser release];
64 - (NSArray *) aclsForFolder
66 SOGoAclsFolder *folder;
70 folder = [SOGoAclsFolder aclsFolder];
71 acls = [folder aclsForObject: [self clientObject]];
77 - (NSString *) ownerLogin
81 ownerLogin = [[self clientObject] ownerInContext: context];
88 - (NSString *) _displayNameForUID: (NSString *) uid
90 AgenorUserManager *um;
92 um = [AgenorUserManager sharedUserManager];
94 return [NSString stringWithFormat: @"%@ <%@>",
95 [um getCNForUID: uid],
96 [um getEmailForUID: uid]];
99 - (NSString *) ownerName
101 return [self _displayNameForUID: [self ownerLogin]];
104 - (void) _prepareUsers
106 NSEnumerator *aclsEnum;
107 AgenorUserManager *um;
108 NSDictionary *currentAcl;
109 NSString *currentUID;
111 aclsEnum = [[self aclsForFolder] objectEnumerator];
112 um = [AgenorUserManager sharedUserManager];
113 currentAcl = [aclsEnum nextObject];
116 currentUID = [currentAcl objectForKey: @"c_uid"];
117 if ([currentUID isEqualToString: @"freebusy"])
118 publishInFreeBusy = YES;
121 if (![[um getCNForUID: currentUID]
122 isEqualToString: [self ownerLogin]])
124 if ([[currentAcl objectForKey: @"c_role"]
125 isEqualToString: SOGoRole_Delegate])
126 [delegates addObject: currentUID];
128 [assistants addObject: currentUID];
129 [users addObject: currentUID];
132 currentAcl = [aclsEnum nextObject];
138 - (NSArray *) usersForFolder
141 [self _prepareUsers];
146 - (void) setCurrentUser: (NSString *) newCurrentUser
148 ASSIGN (currentUser, newCurrentUser);
151 - (NSString *) currentUser
156 - (NSString *) currentUserDisplayName
158 return [self _displayNameForUID: currentUser];
161 - (NSArray *) delegates
164 [self _prepareUsers];
169 - (NSString *) assistantsValue
172 [self _prepareUsers];
174 return [assistants componentsJoinedByString: @","];
177 - (NSString *) delegatesValue
180 [self _prepareUsers];
182 return [delegates componentsJoinedByString: @","];
185 - (BOOL) publishInFreeBusy
188 [self _prepareUsers];
190 return publishInFreeBusy;
193 - (NSString *) toolbar
195 NSString *currentLogin;
197 currentLogin = [[context activeUser] login];
199 return (([[self ownerLogin] isEqualToString: currentLogin])
200 ? @"SOGoAclOwner.toolbar" : @"SOGoAclAssistant.toolbar");
203 - (BOOL) clientIsCalendar
205 return [NSStringFromClass ([[self clientObject] class])
206 isEqualToString: @"SOGoAppointmentFolder"];
209 - (id) saveAclsAction
214 SOGoAclsFolder *folder;
215 SOGoObject *clientObject;
217 folder = [SOGoAclsFolder aclsFolder];
218 request = [context request];
219 clientObject = [self clientObject];
220 uids = [request formValueForKey: @"delegates"];
221 [folder setRoleForObject: clientObject
222 forUsers: [uids componentsSeparatedByString: @","]
223 to: SOGoRole_Delegate];
224 uids = [request formValueForKey: @"assistants"];
225 [folder setRoleForObject: clientObject
226 forUsers: [uids componentsSeparatedByString: @","]
227 to: SOGoRole_Assistant];
228 if ([self clientIsCalendar]) {
229 if ([[request formValueForKey: @"freebusy"] intValue])
230 fbUsers = [NSArray arrayWithObject: @"freebusy"];
233 [folder setRoleForObject: clientObject
235 to: SOGoRole_FreeBusy];
238 return [self jsCloseWithRefreshMethod: nil];