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/NSValue.h>
28 #import <NGObjWeb/WOContext.h>
29 #import <NGObjWeb/WOContext+SoObjects.h>
30 #import <NGObjWeb/WOResponse.h>
31 #import <NGObjWeb/SoSecurityManager.h>
33 #import <SOGo/AgenorUserManager.h>
34 #import <SOGo/SOGoUser.h>
35 #import <SOGo/SOGoObject.h>
36 #import <SOGo/SOGoPermissions.h>
38 #import "UIxFolderActions.h"
40 @implementation UIxFolderActions
42 #warning some of this code could probably be moved in one of the \
43 clientObject classes...
45 - (void) _setupContext
47 NSString *clientClass;
49 login = [[context activeUser] login];
50 clientObject = [self clientObject];
51 owner = [clientObject ownerInContext: nil];
53 clientClass = NSStringFromClass([clientObject class]);
54 if ([clientClass isEqualToString: @"SOGoContactGCSFolder"])
55 baseFolder = @"Contacts";
56 else if ([clientClass isEqualToString: @"SOGoAppointmentFolder"])
57 baseFolder = @"Calendar";
61 um = [AgenorUserManager sharedUserManager];
62 ud = [um getUserSettingsForUID: login];
63 moduleSettings = [ud objectForKey: baseFolder];
66 moduleSettings = [NSMutableDictionary new];
67 [moduleSettings autorelease];
69 [ud setObject: moduleSettings forKey: baseFolder];
71 subscriptionPointer = [NSMutableString stringWithFormat: @"%@:%@",
73 if ([baseFolder isEqualToString: @"Contacts"])
74 [subscriptionPointer appendFormat: @"/%@",
75 [clientObject nameInContainer]];
78 - (WOResponse *) _realActionWithFolderName: (NSDictionary *) folderDict
81 NSMutableDictionary *folderSubscription;
83 response = [context response];
84 if ([owner isEqualToString: login])
86 [response setStatus: 403];
87 [response appendContentString:
88 @"You cannot (un)subscribe to a folder that you own!"];
93 = [moduleSettings objectForKey: @"SubscribedFolders"];
94 if (!folderSubscription)
96 folderSubscription = [NSMutableDictionary dictionary];
97 [moduleSettings setObject: folderSubscription
98 forKey: @"SubscribedFolders"];
101 [folderSubscription setObject: folderDict
102 forKey: subscriptionPointer];
104 [folderSubscription removeObjectForKey: subscriptionPointer];
107 [response setStatus: 204];
113 - (WOResponse *) subscribeAction
116 NSMutableDictionary *folderDict;
117 NSString *folderName;
119 [self _setupContext];
120 email = [NSString stringWithFormat: @"%@ <%@>",
121 [um getCNForUID: owner], [um getEmailForUID: owner]];
122 if ([baseFolder isEqualToString: @"Contacts"])
123 folderName = [NSString stringWithFormat: @"%@ (%@)",
124 [clientObject nameInContainer], email];
128 folderDict = [NSMutableDictionary new];
129 [folderDict setObject: folderName forKey: @"displayName"];
130 [folderDict setObject: [NSNumber numberWithBool: NO] forKey: @"active"];
132 return [self _realActionWithFolderName: folderDict];
135 - (WOResponse *) unsubscribeAction
137 [self _setupContext];
139 return [self _realActionWithFolderName: nil];
142 - (WOResponse *) canAccessContentAction
144 WOResponse *response;
145 SoSecurityManager *securityManager;
148 securityManager = [SoSecurityManager sharedSecurityManager];
149 result = (![securityManager validatePermission: SoPerm_AccessContentsInformation
150 onObject: [self clientObject]
151 inContext: context]);
153 response = [context response];
154 [response setStatus: 200];
155 [response setHeader: @"text/plain; charset=\"ascii\""
156 forKey: @"content-type"];
157 [response appendContentString: (result) ? @"1" : @"0"];
162 - (WOResponse *) _realFolderActivation: (BOOL) makeActive
164 WOResponse *response;
165 NSMutableDictionary *folderSubscription, *folderDict;
168 response = [context response];
170 [self _setupContext];
171 active = [NSNumber numberWithBool: makeActive];
172 if ([owner isEqualToString: login])
173 [moduleSettings setObject: active forKey: @"activateUserFolder"];
177 = [moduleSettings objectForKey: @"SubscribedFolders"];
178 if (folderSubscription)
180 folderDict = [folderSubscription objectForKey: subscriptionPointer];
182 [folderDict setObject: active
188 [response setStatus: 204];
193 - (WOResponse *) activateFolderAction
195 return [self _realFolderActivation: YES];
198 - (WOResponse *) deactivateFolderAction
200 return [self _realFolderActivation: NO];