1 /* UIxFolderActions.m - this file is part of SOGo
3 * Copyright (C) 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/NSDictionary.h>
24 #import <Foundation/NSString.h>
25 #import <Foundation/NSUserDefaults.h>
26 #import <Foundation/NSURL.h>
27 #import <Foundation/NSValue.h>
29 #import <NGObjWeb/WOContext.h>
30 #import <NGObjWeb/WOContext+SoObjects.h>
31 #import <NGObjWeb/WORequest.h>
32 #import <NGObjWeb/WOResponse.h>
33 #import <NGObjWeb/SoSecurityManager.h>
34 #import <NGObjWeb/SoClassSecurityInfo.h>
36 #import <SoObjects/SOGo/LDAPUserManager.h>
37 #import <SoObjects/SOGo/NSArray+Utilities.h>
38 #import <SoObjects/SOGo/SOGoGCSFolder.h>
39 #import <SoObjects/SOGo/SOGoPermissions.h>
40 #import <SoObjects/SOGo/SOGoUser.h>
42 #import "WODirectAction+SOGo.h"
44 #import "UIxFolderActions.h"
46 @implementation UIxFolderActions
48 #warning some of this code could probably be moved in one of the \
49 clientObject classes...
51 - (void) _setupContext
53 NSString *folder, *mailInvitationParam;
54 NSArray *realFolderPath;
57 activeUser = [context activeUser];
58 login = [activeUser login];
59 clientObject = [self clientObject];
60 owner = [clientObject ownerInContext: nil];
62 baseFolder = [[clientObject container] nameInContainer];
64 um = [LDAPUserManager sharedUserManager];
65 ud = [activeUser userSettings];
66 moduleSettings = [ud objectForKey: baseFolder];
69 moduleSettings = [NSMutableDictionary new];
70 [moduleSettings autorelease];
72 [ud setObject: moduleSettings forKey: baseFolder];
74 realFolderPath = [[clientObject nameInContainer]
75 componentsSeparatedByString: @"_"];
76 if ([realFolderPath count] > 1)
77 folder = [realFolderPath objectAtIndex: 1];
79 folder = [realFolderPath objectAtIndex: 0];
80 subscriptionPointer = [NSString stringWithFormat: @"%@:%@/%@",
81 owner, baseFolder, folder];
84 = [[context request] formValueForKey: @"mail-invitation"];
85 isMailInvitation = [mailInvitationParam boolValue];
88 - (WOResponse *) _realSubscribe: (BOOL) reallyDo
91 NSMutableArray *folderSubscription;
92 NSString *mailInvitationURL;
94 if ([owner isEqualToString: login])
96 response = [self responseWithStatus: 403];
97 [response appendContentString:
98 @"You cannot (un)subscribe to a folder that you own!"];
103 = [moduleSettings objectForKey: @"SubscribedFolders"];
104 if (!(folderSubscription
105 && [folderSubscription isKindOfClass: [NSMutableArray class]]))
107 folderSubscription = [NSMutableArray array];
108 [moduleSettings setObject: folderSubscription
109 forKey: @"SubscribedFolders"];
112 [folderSubscription addObjectUniquely: subscriptionPointer];
114 [folderSubscription removeObject: subscriptionPointer];
118 if (isMailInvitation)
121 = [[clientObject soURLToBaseContainerForCurrentUser]
123 response = [self responseWithStatus: 302];
124 [response setHeader: mailInvitationURL
125 forKey: @"location"];
128 response = [self responseWith204];
134 - (WOResponse *) subscribeAction
136 [self _setupContext];
138 return [self _realSubscribe: YES];
141 - (WOResponse *) unsubscribeAction
143 [self _setupContext];
145 return [self _realSubscribe: NO];
148 - (WOResponse *) canAccessContentAction
150 /* We want this action to be authorized managed by the SOPE's internal acl
152 return [self responseWith204];
153 // #warning IMPROVEMENTS REQUIRED!
155 // // NSEnumerator *userAcls;
156 // // NSString *currentAcl;
158 // [self _setupContext];
160 // // NSLog(@"canAccessContentAction %@, owner %@", subscriptionPointer, owner);
162 // if ([login isEqualToString: owner] || [owner isEqualToString: @"nobody"]) {
163 // return [self responseWith204];
166 // acls = [clientObject aclsForUser: login];
167 // // userAcls = [acls objectEnumerator];
168 // // currentAcl = [userAcls nextObject];
169 // // while (currentAcl) {
170 // // NSLog(@"ACL login %@, owner %@, folder %@: %@",
171 // // login, owner, baseFolder, currentAcl);
172 // // currentAcl = [userAcls nextObject];
174 // if (([[clientObject folderType] isEqualToString: @"Contact"]
175 // && [acls containsObject: SOGoRole_ObjectViewer]) ||
176 // ([[clientObject folderType] isEqualToString: @"Appointment"]
177 // && [acls containsObject: SOGoRole_AuthorizedSubscriber])) {
178 // return [self responseWith204];
182 // return [self responseWithStatus: 403];
185 - (WOResponse *) _realFolderActivation: (BOOL) makeActive
187 NSMutableArray *folderSubscription;
188 NSString *folderName;
190 [self _setupContext];
192 = [moduleSettings objectForKey: @"ActiveFolders"];
193 if (!folderSubscription)
195 folderSubscription = [NSMutableArray array];
196 [moduleSettings setObject: folderSubscription forKey: @"ActiveFolders"];
199 folderName = [clientObject nameInContainer];
201 [folderSubscription addObjectUniquely: folderName];
203 [folderSubscription removeObject: folderName];
207 return [self responseWith204];
210 - (WOResponse *) activateFolderAction
212 return [self _realFolderActivation: YES];
215 - (WOResponse *) deactivateFolderAction
217 return [self _realFolderActivation: NO];
220 - (WOResponse *) deleteFolderAction
222 WOResponse *response;
224 response = (WOResponse *) [[self clientObject] delete];
226 response = [self responseWith204];
231 - (WOResponse *) renameFolderAction
233 WOResponse *response;
234 NSString *folderName;
236 folderName = [[context request] formValueForKey: @"name"];
237 if ([folderName length] > 0)
239 clientObject = [self clientObject];
240 [clientObject renameTo: folderName];
241 response = [self responseWith204];
245 response = [self responseWithStatus: 500];
246 [response appendContentString: @"Missing 'name' parameter."];
252 - (id) batchDeleteAction
254 WOResponse *response;
258 idsParam = [[context request] formValueForKey: @"ids"];
259 ids = [idsParam componentsSeparatedByString: @"/"];
262 clientObject = [self clientObject];
263 [clientObject deleteEntriesWithIds: ids];
264 response = [self responseWith204];
268 response = [self responseWithStatus: 500];
269 [response appendContentString: @"At least 1 id required."];