2007-03-27 20:10:01 +02:00
|
|
|
/* UIxFolderActions.m - this file is part of SOGo
|
|
|
|
*
|
2008-09-27 03:13:41 +02:00
|
|
|
* Copyright (C) 2007 Inverse inc.
|
2007-03-27 20:10:01 +02:00
|
|
|
*
|
|
|
|
* 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>
|
2008-08-10 23:44:25 +02:00
|
|
|
#import <Foundation/NSEnumerator.h>
|
2007-03-27 20:10:01 +02:00
|
|
|
#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>
|
2008-08-10 23:44:25 +02:00
|
|
|
#import <NGObjWeb/NSException+HTTP.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>
|
2008-08-10 23:44:25 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoContentObject.h>
|
2007-11-07 16:58:43 +01:00
|
|
|
#import <SoObjects/SOGo/SOGoGCSFolder.h>
|
2008-08-10 23:44:25 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoParentFolder.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
|
2008-11-18 01:06:37 +01:00
|
|
|
inTheNamesOf: nil
|
2008-05-16 22:30:00 +02:00
|
|
|
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
|
2008-11-18 01:06:37 +01:00
|
|
|
inTheNamesOf: nil
|
2008-05-16 22:30:00 +02:00
|
|
|
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 *) 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;
|
|
|
|
}
|
|
|
|
|
2008-08-10 23:44:25 +02:00
|
|
|
- (NSException*) _moveContacts: (NSArray*) contactsId
|
|
|
|
toFolder: (NSString*) destinationFolderId
|
|
|
|
andKeepCopy: (BOOL) keepCopy
|
|
|
|
{
|
|
|
|
NSEnumerator *uids;
|
|
|
|
NSException *ex;
|
|
|
|
NSString *uid;
|
|
|
|
SOGoContentObject *currentChild;
|
|
|
|
SOGoGCSFolder *sourceFolder, *destinationFolder;
|
|
|
|
SOGoParentFolder *folders;
|
|
|
|
SoSecurityManager *sm;
|
|
|
|
WORequest *request;
|
|
|
|
unsigned int errorCount;
|
|
|
|
|
|
|
|
sm = [SoSecurityManager sharedSecurityManager];
|
|
|
|
request = [context request];
|
|
|
|
ex = nil;
|
|
|
|
errorCount = 0;
|
|
|
|
|
|
|
|
// Search the specified destination folder
|
|
|
|
sourceFolder = [self clientObject];
|
|
|
|
folders = [sourceFolder container];
|
|
|
|
destinationFolder = [folders lookupName: destinationFolderId
|
|
|
|
inContext: nil
|
|
|
|
acquire: NO];
|
|
|
|
if (destinationFolder)
|
|
|
|
{
|
|
|
|
// Verify write access to the folder
|
|
|
|
ex = [sm validatePermission: SoPerm_AddDocumentsImagesAndFiles
|
|
|
|
onObject: destinationFolder
|
|
|
|
inContext: context];
|
|
|
|
if (!ex)
|
|
|
|
{
|
|
|
|
uids = [contactsId objectEnumerator];
|
|
|
|
while ((uid = [uids nextObject]))
|
|
|
|
{
|
|
|
|
// Search the currentChild ID
|
|
|
|
currentChild = [sourceFolder lookupName: uid
|
|
|
|
inContext: [self context]
|
|
|
|
acquire: NO];
|
|
|
|
if ([currentChild isKindOfClass: [NSException class]])
|
|
|
|
errorCount++;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (keepCopy)
|
|
|
|
ex = [currentChild copyToFolder: destinationFolder];
|
|
|
|
else
|
|
|
|
ex = [currentChild moveToFolder: destinationFolder];
|
|
|
|
if (ex)
|
|
|
|
errorCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ex = [NSException exceptionWithName: @"UnknownDestinationFolder"
|
|
|
|
reason: @"Unknown Destination Folder"
|
|
|
|
userInfo: nil];
|
|
|
|
|
|
|
|
if (errorCount > 0)
|
|
|
|
// At least one currentChild was not copied
|
|
|
|
ex = [NSException exceptionWithHTTPStatus: 400
|
|
|
|
reason: @"Invalid Contact"];
|
|
|
|
else if (ex != nil)
|
|
|
|
// Destination address book doesn't exist or is not writable
|
|
|
|
ex = [NSException exceptionWithHTTPStatus: 403
|
|
|
|
reason: [ex name]];
|
|
|
|
|
|
|
|
return ex;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id <WOActionResults>) copyAction
|
|
|
|
{
|
|
|
|
WORequest *request;
|
|
|
|
id <WOActionResults> response;
|
|
|
|
NSString *destinationFolderId;
|
|
|
|
NSArray *contactsId;
|
|
|
|
NSException *ex;
|
|
|
|
|
|
|
|
request = [context request];
|
|
|
|
ex = nil;
|
|
|
|
|
|
|
|
if ((destinationFolderId = [request formValueForKey: @"folder"]) &&
|
|
|
|
(contactsId = [request formValuesForKey: @"uid"]))
|
|
|
|
{
|
|
|
|
ex = [self _moveContacts: contactsId
|
|
|
|
toFolder: destinationFolderId
|
|
|
|
andKeepCopy: YES];
|
|
|
|
if (ex != nil)
|
|
|
|
response = (id)ex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
response = [NSException exceptionWithHTTPStatus: 400
|
|
|
|
reason: @"missing 'folder' and/or 'uid' parameter"];
|
|
|
|
|
|
|
|
if (ex == nil)
|
|
|
|
response = [self responseWith204];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id <WOActionResults>) moveAction
|
|
|
|
{
|
|
|
|
WORequest *request;
|
|
|
|
id <WOActionResults> response;
|
|
|
|
NSString *destinationFolderId;
|
|
|
|
NSArray *contactsId;
|
|
|
|
NSException *ex;
|
|
|
|
|
|
|
|
request = [context request];
|
|
|
|
ex = nil;
|
|
|
|
|
|
|
|
if ((destinationFolderId = [request formValueForKey: @"folder"]) &&
|
|
|
|
(contactsId = [request formValuesForKey: @"uid"]))
|
|
|
|
{
|
|
|
|
ex = [self _moveContacts: contactsId
|
|
|
|
toFolder: destinationFolderId
|
|
|
|
andKeepCopy: NO];
|
|
|
|
if (ex != nil)
|
|
|
|
response = (id)ex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
response = [NSException exceptionWithHTTPStatus: 400
|
|
|
|
reason: @"missing 'folder' and/or 'uid' parameter"];
|
|
|
|
|
|
|
|
if (ex == nil)
|
|
|
|
response = [self responseWith204];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2007-03-27 20:10:01 +02:00
|
|
|
@end
|