]> err.no Git - scalable-opengroupware.org/blob - UI/Common/UIxAclEditor.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1006 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / Common / UIxAclEditor.m
1 /* UIxAclEditor.m - this file is part of SOGo
2  *
3  * Copyright (C) 2006 Inverse groupe conseil
4  *
5  * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
6  *
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)
10  * any later version.
11  *
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.
16  *
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.
21  */
22
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>
31
32 #import "UIxAclEditor.h"
33
34 @implementation UIxAclEditor
35
36 - (id) init
37 {
38   if ((self = [super init]))
39     {
40       acls = nil;
41       prepared = NO;
42       publishInFreeBusy = NO;
43       users = [NSMutableArray new];
44       delegates = [NSMutableArray new];
45       assistants = [NSMutableArray new];
46       ownerCN = nil;
47     }
48
49   return self;
50 }
51
52 - (void) dealloc
53 {
54   [users release];
55   [delegates release];
56   [assistants release];
57   if (ownerCN)
58     [ownerCN release];
59   [super dealloc];
60 }
61
62 - (NSArray *) aclsForFolder
63 {
64   SOGoAclsFolder *folder;
65
66   if (!acls)
67     {
68       folder = [SOGoAclsFolder aclsFolder];
69       acls = [folder aclsForObject: [self clientObject]];
70     }
71
72   return acls;
73 }
74
75 - (NSString *) ownerCN
76 {
77   if (!ownerCN)
78     {
79       ownerCN = [[self clientObject] ownerInContext: context];
80       [ownerCN retain];
81     }
82
83   return ownerCN;
84 }
85
86 - (void) _prepareUsers
87 {
88   NSEnumerator *aclsEnum;
89   AgenorUserManager *um;
90   NSDictionary *currentAcl;
91   iCalPerson *currentUser;
92   NSString *currentUID;
93
94   aclsEnum = [[self aclsForFolder] objectEnumerator];
95   um = [AgenorUserManager sharedUserManager];
96   currentAcl = [aclsEnum nextObject];
97   while (currentAcl)
98     {
99       currentUID = [currentAcl objectForKey: @"c_uid"];
100       if ([currentUID isEqualToString: @"freebusy"])
101         publishInFreeBusy = YES;
102       else
103         {
104           currentUser = [um iCalPersonWithUid: currentUID];
105           if (![[currentUser cn] isEqualToString: [self ownerCN]])
106             {
107               if ([[currentAcl objectForKey: @"c_role"]
108                     isEqualToString: SOGoRole_Delegate])
109                 [delegates addObject: [currentUser cn]];
110               else
111                 [assistants addObject: [currentUser cn]];
112               [users addObject: currentUser];
113             }
114         }
115       currentAcl = [aclsEnum nextObject];
116
117       prepared = YES;
118     }
119 }
120
121 - (NSArray *) usersForFolder
122 {
123   if (!prepared)
124     [self _prepareUsers];
125
126   return users;
127 }
128
129 - (NSArray *) delegates
130 {
131   if (!prepared)
132     [self _prepareUsers];
133
134   return delegates;
135 }
136
137 - (NSString *) assistantsValue
138 {
139   if (!prepared)
140     [self _prepareUsers];
141
142   return [assistants componentsJoinedByString: @","];
143 }
144
145 - (NSString *) delegatesValue
146 {
147   if (!prepared)
148     [self _prepareUsers];
149
150   return [delegates componentsJoinedByString: @","];
151 }
152
153 - (BOOL) publishInFreeBusy
154 {
155   if (!prepared)
156     [self _prepareUsers];
157
158   return publishInFreeBusy;
159 }
160
161 - (NSString *) toolbar
162 {
163   return (([[self ownerCN] isEqualToString: [[context activeUser] login]])
164           ? @"SOGoAclOwner.toolbar" : @"SOGoAclAssistant.toolbar");
165 }
166
167 - (BOOL) clientIsCalendar
168 {
169   return [NSStringFromClass ([[self clientObject] class])
170                             isEqualToString: @"SOGoAppointmentFolder"];
171 }
172
173 - (id) saveAclsAction
174 {
175   NSString *uids;
176   NSArray *fbUsers;
177   WORequest *request;
178   SOGoAclsFolder *folder;
179   SOGoObject *clientObject;
180
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"];
195     else
196       fbUsers = nil;
197     [folder setRoleForObject: clientObject
198             forUsers: fbUsers
199             to: SOGoRole_FreeBusy];
200   }
201
202   return [self jsCloseWithRefreshMethod: nil];
203 }
204
205 @end