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/NSKeyValueCoding.h>
25 #import <NGObjWeb/SoUser.h>
26 #import <NGObjWeb/WORequest.h>
27 #import <NGCards/iCalPerson.h>
28 #import <SoObjects/SOGo/AgenorUserManager.h>
29 #import <SoObjects/SOGo/SOGoAclsFolder.h>
30 #import <SoObjects/SOGo/SOGoPermissions.h>
32 #import "UIxAclEditor.h"
34 @implementation UIxAclEditor
38 if ((self = [super init]))
42 publishInFreeBusy = NO;
43 users = [NSMutableArray new];
44 delegates = [NSMutableArray new];
45 assistants = [NSMutableArray new];
62 - (NSArray *) aclsForFolder
64 SOGoAclsFolder *folder;
68 folder = [SOGoAclsFolder aclsFolder];
69 acls = [folder aclsForObject: [self clientObject]];
75 - (NSString *) ownerCN
79 ownerCN = [[self clientObject] ownerInContext: context];
86 - (void) _prepareUsers
88 NSEnumerator *aclsEnum;
89 AgenorUserManager *um;
90 NSDictionary *currentAcl;
91 iCalPerson *currentUser;
94 aclsEnum = [[self aclsForFolder] objectEnumerator];
95 um = [AgenorUserManager sharedUserManager];
96 currentAcl = [aclsEnum nextObject];
99 currentUID = [currentAcl objectForKey: @"c_uid"];
100 if ([currentUID isEqualToString: @"freebusy"])
101 publishInFreeBusy = YES;
104 currentUser = [um iCalPersonWithUid: currentUID];
105 if (![[currentUser cn] isEqualToString: [self ownerCN]])
107 if ([[currentAcl objectForKey: @"c_role"]
108 isEqualToString: SOGoRole_Delegate])
109 [delegates addObject: [currentUser cn]];
111 [assistants addObject: [currentUser cn]];
112 [users addObject: currentUser];
115 currentAcl = [aclsEnum nextObject];
121 - (NSArray *) usersForFolder
124 [self _prepareUsers];
129 - (NSArray *) delegates
132 [self _prepareUsers];
137 - (NSString *) assistantsValue
140 [self _prepareUsers];
142 return [assistants componentsJoinedByString: @","];
145 - (NSString *) delegatesValue
148 [self _prepareUsers];
150 return [delegates componentsJoinedByString: @","];
153 - (BOOL) publishInFreeBusy
156 [self _prepareUsers];
158 return publishInFreeBusy;
161 - (NSString *) toolbar
163 return (([[self ownerCN] isEqualToString: [[context activeUser] login]])
164 ? @"SOGoAclOwner.toolbar" : @"SOGoAclAssistant.toolbar");
167 - (BOOL) clientIsCalendar
169 return [NSStringFromClass ([[self clientObject] class])
170 isEqualToString: @"SOGoAppointmentFolder"];
173 - (id) saveAclsAction
178 SOGoAclsFolder *folder;
179 SOGoObject *clientObject;
181 folder = [SOGoAclsFolder aclsFolder];
182 request = [context request];
183 clientObject = [self clientObject];
184 uids = [request formValueForKey: @"delegates"];
185 [folder setRoleForObject: clientObject
186 forUsers: [uids componentsSeparatedByString: @","]
187 to: SOGoRole_Delegate];
188 uids = [request formValueForKey: @"assistants"];
189 [folder setRoleForObject: clientObject
190 forUsers: [uids componentsSeparatedByString: @","]
191 to: SOGoRole_Assistant];
192 if ([self clientIsCalendar]) {
193 if ([[request formValueForKey: @"freebusy"] intValue])
194 fbUsers = [NSArray arrayWithObject: @"freebusy"];
197 [folder setRoleForObject: clientObject
199 to: SOGoRole_FreeBusy];
202 return [self jsCloseWithRefreshMethod: nil];