2007-03-27 20:10:01 +02:00
|
|
|
/* UIxFolderActions.m - this file is part of SOGo
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Inverse groupe conseil
|
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
#import <Foundation/NSUserDefaults.h>
|
2007-05-30 22:21:54 +02:00
|
|
|
#import <Foundation/NSURL.h>
|
2007-03-27 20:10:01 +02:00
|
|
|
#import <Foundation/NSValue.h>
|
|
|
|
|
|
|
|
#import <NGObjWeb/WOContext.h>
|
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
2007-04-17 16:03:02 +02:00
|
|
|
#import <NGObjWeb/WORequest.h>
|
2007-03-27 20:10:01 +02:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
2007-03-29 19:20:37 +02:00
|
|
|
#import <NGObjWeb/SoSecurityManager.h>
|
2007-10-09 19:57:27 +02:00
|
|
|
#import <NGObjWeb/SoClassSecurityInfo.h>
|
2007-03-27 20:10:01 +02:00
|
|
|
|
2007-05-09 20:25:51 +02:00
|
|
|
#import <SoObjects/SOGo/LDAPUserManager.h>
|
2007-09-15 00:01:02 +02:00
|
|
|
#import <SoObjects/SOGo/NSArray+Utilities.h>
|
2007-11-07 16:58:43 +01:00
|
|
|
#import <SoObjects/SOGo/SOGoGCSFolder.h>
|
2007-05-09 20:25:51 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoPermissions.h>
|
2007-11-07 16:58:43 +01:00
|
|
|
#import <SoObjects/SOGo/SOGoUser.h>
|
2007-03-27 20:10:01 +02:00
|
|
|
|
2007-09-11 21:36:40 +02:00
|
|
|
#import "WODirectAction+SOGo.h"
|
|
|
|
|
2007-03-27 20:10:01 +02:00
|
|
|
#import "UIxFolderActions.h"
|
|
|
|
|
|
|
|
@implementation UIxFolderActions
|
|
|
|
|
|
|
|
- (void) _setupContext
|
|
|
|
{
|
2008-04-22 01:03:48 +02:00
|
|
|
NSString *mailInvitationParam;
|
2007-05-09 20:25:51 +02:00
|
|
|
SOGoUser *activeUser;
|
2007-03-27 20:10:01 +02:00
|
|
|
|
2007-05-09 20:25:51 +02:00
|
|
|
activeUser = [context activeUser];
|
|
|
|
login = [activeUser login];
|
2007-03-27 20:10:01 +02:00
|
|
|
clientObject = [self clientObject];
|
|
|
|
owner = [clientObject ownerInContext: nil];
|
|
|
|
|
2007-09-15 03:54:34 +02:00
|
|
|
baseFolder = [[clientObject container] nameInContainer];
|
2007-03-27 20:10:01 +02:00
|
|
|
|
2007-05-09 20:25:51 +02:00
|
|
|
um = [LDAPUserManager sharedUserManager];
|
|
|
|
ud = [activeUser userSettings];
|
2007-03-27 20:10:01 +02:00
|
|
|
moduleSettings = [ud objectForKey: baseFolder];
|
|
|
|
if (!moduleSettings)
|
|
|
|
{
|
|
|
|
moduleSettings = [NSMutableDictionary new];
|
|
|
|
[moduleSettings autorelease];
|
|
|
|
}
|
|
|
|
[ud setObject: moduleSettings forKey: baseFolder];
|
|
|
|
|
2007-05-30 22:21:54 +02:00
|
|
|
mailInvitationParam
|
|
|
|
= [[context request] formValueForKey: @"mail-invitation"];
|
|
|
|
isMailInvitation = [mailInvitationParam boolValue];
|
2007-03-27 20:10:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) subscribeAction
|
|
|
|
{
|
|
|
|
[self _setupContext];
|
|
|
|
|
2008-05-16 22:30:00 +02:00
|
|
|
return [clientObject subscribe: YES
|
|
|
|
inTheNameOf: nil
|
|
|
|
fromMailInvitation: isMailInvitation
|
|
|
|
inContext: context];
|
2007-03-27 20:10:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) unsubscribeAction
|
|
|
|
{
|
|
|
|
[self _setupContext];
|
|
|
|
|
2008-05-16 22:30:00 +02:00
|
|
|
return [clientObject subscribe: NO
|
|
|
|
inTheNameOf: nil
|
|
|
|
fromMailInvitation: isMailInvitation
|
|
|
|
inContext: context];
|
2007-03-27 20:10:01 +02:00
|
|
|
}
|
|
|
|
|
2007-03-29 19:20:37 +02:00
|
|
|
- (WOResponse *) canAccessContentAction
|
|
|
|
{
|
2007-11-27 22:06:11 +01:00
|
|
|
/* We want this action to be authorized managed by the SOPE's internal acl
|
|
|
|
handling. */
|
|
|
|
return [self responseWith204];
|
|
|
|
// #warning IMPROVEMENTS REQUIRED!
|
|
|
|
// NSArray *acls;
|
|
|
|
// // NSEnumerator *userAcls;
|
|
|
|
// // NSString *currentAcl;
|
|
|
|
|
|
|
|
// [self _setupContext];
|
2007-10-09 19:57:27 +02:00
|
|
|
|
2007-11-27 22:06:11 +01:00
|
|
|
// // NSLog(@"canAccessContentAction %@, owner %@", subscriptionPointer, owner);
|
|
|
|
|
|
|
|
// if ([login isEqualToString: owner] || [owner isEqualToString: @"nobody"]) {
|
|
|
|
// return [self responseWith204];
|
|
|
|
// }
|
|
|
|
// else {
|
|
|
|
// acls = [clientObject aclsForUser: login];
|
|
|
|
// // userAcls = [acls objectEnumerator];
|
|
|
|
// // currentAcl = [userAcls nextObject];
|
|
|
|
// // while (currentAcl) {
|
|
|
|
// // NSLog(@"ACL login %@, owner %@, folder %@: %@",
|
|
|
|
// // login, owner, baseFolder, currentAcl);
|
|
|
|
// // currentAcl = [userAcls nextObject];
|
|
|
|
// // }
|
|
|
|
// if (([[clientObject folderType] isEqualToString: @"Contact"]
|
|
|
|
// && [acls containsObject: SOGoRole_ObjectViewer]) ||
|
|
|
|
// ([[clientObject folderType] isEqualToString: @"Appointment"]
|
|
|
|
// && [acls containsObject: SOGoRole_AuthorizedSubscriber])) {
|
|
|
|
// return [self responseWith204];
|
|
|
|
// }
|
|
|
|
// }
|
2007-10-09 19:57:27 +02:00
|
|
|
|
2007-11-27 22:06:11 +01:00
|
|
|
// return [self responseWithStatus: 403];
|
2007-03-29 19:20:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) _realFolderActivation: (BOOL) makeActive
|
|
|
|
{
|
2007-09-15 00:01:02 +02:00
|
|
|
NSMutableArray *folderSubscription;
|
|
|
|
NSString *folderName;
|
|
|
|
|
2007-03-29 19:20:37 +02:00
|
|
|
[self _setupContext];
|
2007-09-15 00:01:02 +02:00
|
|
|
folderSubscription
|
2008-05-06 01:39:07 +02:00
|
|
|
= [moduleSettings objectForKey: @"InactiveFolders"];
|
2007-09-15 00:01:02 +02:00
|
|
|
if (!folderSubscription)
|
2007-03-29 19:20:37 +02:00
|
|
|
{
|
2007-09-15 00:01:02 +02:00
|
|
|
folderSubscription = [NSMutableArray array];
|
2008-05-06 01:39:07 +02:00
|
|
|
[moduleSettings setObject: folderSubscription forKey: @"InactiveFolders"];
|
2007-03-29 19:20:37 +02:00
|
|
|
}
|
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
folderName = [clientObject nameInContainer];
|
|
|
|
if (makeActive)
|
|
|
|
[folderSubscription removeObject: folderName];
|
2008-05-06 01:39:07 +02:00
|
|
|
else
|
|
|
|
[folderSubscription addObjectUniquely: folderName];
|
2007-09-15 00:01:02 +02:00
|
|
|
|
2007-03-29 19:20:37 +02:00
|
|
|
[ud synchronize];
|
|
|
|
|
2007-09-11 21:36:40 +02:00
|
|
|
return [self responseWith204];
|
2007-03-29 19:20:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) activateFolderAction
|
|
|
|
{
|
|
|
|
return [self _realFolderActivation: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) deactivateFolderAction
|
|
|
|
{
|
|
|
|
return [self _realFolderActivation: NO];
|
|
|
|
}
|
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
- (WOResponse *) deleteFolderAction
|
|
|
|
{
|
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
response = (WOResponse *) [[self clientObject] delete];
|
|
|
|
if (!response)
|
|
|
|
response = [self responseWith204];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) renameFolderAction
|
|
|
|
{
|
|
|
|
WOResponse *response;
|
|
|
|
NSString *folderName;
|
|
|
|
|
|
|
|
folderName = [[context request] formValueForKey: @"name"];
|
|
|
|
if ([folderName length] > 0)
|
|
|
|
{
|
|
|
|
clientObject = [self clientObject];
|
|
|
|
[clientObject renameTo: folderName];
|
|
|
|
response = [self responseWith204];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response = [self responseWithStatus: 500];
|
|
|
|
[response appendContentString: @"Missing 'name' parameter."];
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2007-09-15 01:16:16 +02:00
|
|
|
- (id) batchDeleteAction
|
|
|
|
{
|
|
|
|
WOResponse *response;
|
|
|
|
NSString *idsParam;
|
|
|
|
NSArray *ids;
|
|
|
|
|
|
|
|
idsParam = [[context request] formValueForKey: @"ids"];
|
|
|
|
ids = [idsParam componentsSeparatedByString: @"/"];
|
|
|
|
if ([ids count])
|
|
|
|
{
|
|
|
|
clientObject = [self clientObject];
|
|
|
|
[clientObject deleteEntriesWithIds: ids];
|
|
|
|
response = [self responseWith204];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response = [self responseWithStatus: 500];
|
|
|
|
[response appendContentString: @"At least 1 id required."];
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2007-03-27 20:10:01 +02:00
|
|
|
@end
|