2007-03-27 20:10:01 +02:00
|
|
|
/* UIxFolderActions.m - this file is part of SOGo
|
|
|
|
*
|
2015-01-22 12:50:31 +01:00
|
|
|
* Copyright (C) 2007-2015 Inverse inc.
|
2007-03-27 20:10:01 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
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+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>
|
2008-08-10 23:44:25 +02:00
|
|
|
#import <NGObjWeb/NSException+HTTP.h>
|
2007-03-27 20:10:01 +02:00
|
|
|
|
2014-11-10 21:08:23 +01:00
|
|
|
#import <SOGo/SOGoUserManager.h>
|
|
|
|
#import <SOGo/NSArray+Utilities.h>
|
|
|
|
#import <SOGo/NSDictionary+Utilities.h>
|
|
|
|
#import <SOGo/NSString+Utilities.h>
|
|
|
|
#import <SOGo/SOGoContentObject.h>
|
|
|
|
#import <SOGo/SOGoParentFolder.h>
|
|
|
|
#import <SOGo/SOGoPermissions.h>
|
|
|
|
#import <SOGo/SOGoUser.h>
|
|
|
|
#import <SOGo/SOGoUserSettings.h>
|
2015-01-22 12:50:31 +01:00
|
|
|
|
|
|
|
#import <Contacts/SOGoContactGCSFolder.h>
|
2014-11-10 21:08:23 +01:00
|
|
|
#import <Contacts/SOGoContactSourceFolder.h>
|
2007-03-27 20:10:01 +02:00
|
|
|
|
2015-01-22 12:50:31 +01:00
|
|
|
#import <Appointments/SOGoAppointmentFolder.h>
|
|
|
|
|
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
|
|
|
|
2009-09-25 16:42:33 +02:00
|
|
|
um = [SOGoUserManager sharedUserManager];
|
2009-11-29 05:19:32 +01:00
|
|
|
us = [activeUser userSettings];
|
|
|
|
moduleSettings = [us objectForKey: baseFolder];
|
2007-03-27 20:10:01 +02:00
|
|
|
if (!moduleSettings)
|
2009-10-13 16:10:17 +02:00
|
|
|
moduleSettings = [NSMutableDictionary dictionary];
|
2009-11-29 05:19:32 +01:00
|
|
|
[us setObject: moduleSettings forKey: baseFolder];
|
2007-03-27 20:10:01 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-08-27 23:14:54 +02:00
|
|
|
- (WOResponse *) _subscribeAction: (BOOL) reallyDo
|
2007-03-27 20:10:01 +02:00
|
|
|
{
|
2009-08-27 23:14:54 +02:00
|
|
|
WOResponse *response;
|
2014-11-10 21:08:23 +01:00
|
|
|
NSDictionary *jsonResponse;
|
2009-08-27 23:14:54 +02:00
|
|
|
NSURL *mailInvitationURL;
|
|
|
|
|
2014-11-10 21:08:23 +01:00
|
|
|
response = nil;
|
2007-03-27 20:10:01 +02:00
|
|
|
[self _setupContext];
|
2009-08-27 23:14:54 +02:00
|
|
|
if ([owner isEqualToString: login])
|
|
|
|
{
|
2014-11-10 21:08:23 +01:00
|
|
|
jsonResponse = [NSDictionary dictionaryWithObject: [self labelForKey: @"You cannot (un)subscribe to a folder that you own!"]
|
|
|
|
forKey: @"error"];
|
|
|
|
response = [self responseWithStatus: 403
|
|
|
|
andJSONRepresentation: jsonResponse];
|
2009-08-27 23:14:54 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-24 18:48:03 +02:00
|
|
|
[clientObject subscribeUserOrGroup: login
|
|
|
|
reallyDo: reallyDo
|
|
|
|
response: response];
|
|
|
|
|
2009-08-27 23:14:54 +02:00
|
|
|
if (isMailInvitation)
|
|
|
|
{
|
2014-11-10 21:08:23 +01:00
|
|
|
mailInvitationURL = [clientObject soURLToBaseContainerForCurrentUser];
|
|
|
|
response = [self responseWithStatus: 302];
|
2009-08-27 23:14:54 +02:00
|
|
|
[response setHeader: [mailInvitationURL absoluteString]
|
|
|
|
forKey: @"location"];
|
|
|
|
}
|
|
|
|
else
|
2014-11-10 21:08:23 +01:00
|
|
|
{
|
|
|
|
// @see [SOGoGCSFolder folderWithSubscriptionReference:inContainer:]
|
|
|
|
jsonResponse
|
|
|
|
= [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[NSString stringWithFormat: @"%@_%@", [owner asCSSIdentifier], [clientObject nameInContainer]], @"id",
|
|
|
|
owner, @"owner",
|
|
|
|
[clientObject displayName], @"name",
|
|
|
|
[NSNumber numberWithBool: [clientObject isKindOfClass: [SOGoGCSFolder class]]], @"isEditable",
|
|
|
|
[NSNumber numberWithBool:
|
|
|
|
[clientObject isKindOfClass: [SOGoContactSourceFolder class]]
|
|
|
|
&& ![(SOGoContactSourceFolder *) clientObject isPersonalSource]], @"isRemote",
|
|
|
|
nil];
|
|
|
|
response = [self responseWithStatus: 200
|
|
|
|
andJSONRepresentation: jsonResponse];
|
|
|
|
}
|
2009-08-27 23:14:54 +02:00
|
|
|
}
|
2007-03-27 20:10:01 +02:00
|
|
|
|
2009-08-27 23:14:54 +02:00
|
|
|
return response;
|
2007-03-27 20:10:01 +02:00
|
|
|
}
|
|
|
|
|
2009-08-27 23:14:54 +02:00
|
|
|
- (WOResponse *) subscribeAction
|
2007-03-27 20:10:01 +02:00
|
|
|
{
|
2009-08-27 23:14:54 +02:00
|
|
|
return [self _subscribeAction: YES];
|
|
|
|
}
|
2007-03-27 20:10:01 +02:00
|
|
|
|
2009-08-27 23:14:54 +02:00
|
|
|
- (WOResponse *) unsubscribeAction
|
|
|
|
{
|
|
|
|
return [self _subscribeAction: NO];
|
2007-03-27 20:10:01 +02:00
|
|
|
}
|
|
|
|
|
2015-01-22 15:15:44 +01:00
|
|
|
/**
|
|
|
|
* @api {get} /so/:username/:folderPath/canAccessContent Test access rights
|
|
|
|
* @apiVersion 1.0.0
|
|
|
|
* @apiName GetCanAccessContent
|
|
|
|
* @apiGroup Common
|
|
|
|
* @apiExample {curl} Example usage:
|
|
|
|
* curl -i http://localhost/SOGo/so/sogo1/Calendar/personal/canAccessContent
|
|
|
|
*/
|
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
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
[us synchronize];
|
2007-03-29 19:20:37 +02:00
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2015-01-13 17:30:23 +01:00
|
|
|
/**
|
|
|
|
* @api {get} /so/:username/:folderPath/newguid Generate new ID
|
|
|
|
* @apiVersion 1.0.0
|
|
|
|
* @apiName GetNewGUID
|
|
|
|
* @apiGroup Common
|
|
|
|
* @apiExample {curl} Example usage:
|
|
|
|
* curl -i http://localhost/SOGo/so/sogo1/Calendar/personal/newguid
|
|
|
|
*
|
|
|
|
* @apiSuccess (Success 200) {String} pid Folder ID (element's parent)
|
|
|
|
* @apiSuccess (Success 200) {String} id New element ID
|
|
|
|
* @apiError (Error 500) {Object} error The error message
|
|
|
|
*/
|
2014-08-20 21:18:35 +02:00
|
|
|
- (WOResponse *) newguidAction
|
|
|
|
{
|
|
|
|
NSString *objectId, *folderId;
|
|
|
|
NSDictionary *data;
|
|
|
|
WOResponse *response;
|
|
|
|
SOGoFolder *co;
|
|
|
|
SoSecurityManager *sm;
|
|
|
|
|
|
|
|
co = [self clientObject];
|
|
|
|
objectId = [co globallyUniqueObjectId];
|
|
|
|
if ([objectId length] > 0)
|
|
|
|
{
|
|
|
|
sm = [SoSecurityManager sharedSecurityManager];
|
|
|
|
if (![sm validatePermission: SoPerm_AddDocumentsImagesAndFiles
|
|
|
|
onObject: co
|
|
|
|
inContext: context])
|
|
|
|
{
|
|
|
|
folderId = [co nameInContainer];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
folderId = @"personal";
|
|
|
|
}
|
2015-01-22 12:50:31 +01:00
|
|
|
// Append meaningful extension to objects of calendars and addressbooks
|
|
|
|
if ([co isKindOfClass: [SOGoContactGCSFolder class]])
|
|
|
|
{
|
|
|
|
objectId = [NSString stringWithFormat: @"%@.vcf", objectId];
|
|
|
|
}
|
|
|
|
else if ([co isKindOfClass: [SOGoAppointmentFolder class]])
|
|
|
|
{
|
|
|
|
objectId = [NSString stringWithFormat: @"%@.ics", objectId];
|
|
|
|
}
|
2014-08-20 21:18:35 +02:00
|
|
|
data = [NSDictionary dictionaryWithObjectsAndKeys: objectId, @"id", folderId, @"pid", nil];
|
|
|
|
response = [self responseWithStatus: 200
|
|
|
|
andString: [data jsonRepresentation]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
response = [NSException exceptionWithHTTPStatus: 500 /* Internal Error */
|
|
|
|
reason: @"could not create a unique ID"];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
- (WOResponse *) renameFolderAction
|
|
|
|
{
|
|
|
|
WOResponse *response;
|
2014-08-06 22:03:30 +02:00
|
|
|
WORequest *request;
|
|
|
|
NSDictionary *params, *message;
|
2007-09-15 00:01:02 +02:00
|
|
|
NSString *folderName;
|
|
|
|
|
2014-08-06 22:03:30 +02:00
|
|
|
request = [context request];
|
|
|
|
params = [[request contentAsString] objectFromJSONString];
|
|
|
|
folderName = [params objectForKey: @"name"];
|
2007-09-15 00:01:02 +02:00
|
|
|
if ([folderName length] > 0)
|
|
|
|
{
|
|
|
|
clientObject = [self clientObject];
|
|
|
|
[clientObject renameTo: folderName];
|
|
|
|
response = [self responseWith204];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-06 22:03:30 +02:00
|
|
|
message = [NSDictionary dictionaryWithObject: @"Missing name parameter" forKey: @"error"];
|
|
|
|
response = [self responseWithStatus: 500
|
|
|
|
andString: [message jsonRepresentation]];
|
2007-09-15 00:01:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2015-05-08 22:32:26 +02:00
|
|
|
/**
|
|
|
|
* @api {post} /so/:username/:folderPath/batchDelete?uids=:uids Delete multiple resources
|
|
|
|
* @apiVersion 1.0.0
|
|
|
|
* @apiName GetBatchDelete
|
|
|
|
* @apiGroup Common
|
|
|
|
* @apiExample {curl} Example usage:
|
|
|
|
* curl -i http://localhost/SOGo/so/sogo1/Contacts/personal/batchDelete \
|
|
|
|
* -H 'Content-Type: application/json' \
|
|
|
|
* -d '{ "uids": ["1BC8-52F53F80-1-38C52041.vcf", "4095-52B0C180-31-9225E71.vlf"] }'
|
|
|
|
*
|
|
|
|
* @apiParam {String[]} uids List of resources IDs
|
|
|
|
*
|
|
|
|
* @apiError (Error 400) {Object} error The error message
|
|
|
|
*/
|
2007-09-15 01:16:16 +02:00
|
|
|
- (id) batchDeleteAction
|
|
|
|
{
|
|
|
|
WOResponse *response;
|
2015-05-08 21:47:09 +02:00
|
|
|
NSDictionary *data;
|
2007-09-15 01:16:16 +02:00
|
|
|
NSArray *ids;
|
|
|
|
|
2015-05-08 21:47:09 +02:00
|
|
|
data = [[[context request] contentAsString] objectFromJSONString];
|
|
|
|
ids = [data objectForKey: @"uids"];
|
|
|
|
|
|
|
|
if ([ids isKindOfClass: [NSArray class]] && [ids count])
|
2007-09-15 01:16:16 +02:00
|
|
|
{
|
|
|
|
clientObject = [self clientObject];
|
|
|
|
[clientObject deleteEntriesWithIds: ids];
|
|
|
|
response = [self responseWith204];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-08 22:32:26 +02:00
|
|
|
response = [self responseWithStatus: 400
|
|
|
|
andJSONRepresentation: [NSDictionary dictionaryWithObject: @"At least 1 id required."
|
|
|
|
forKey: @"error"]];
|
2007-09-15 01:16:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
unsigned int errorCount;
|
|
|
|
|
|
|
|
sm = [SoSecurityManager sharedSecurityManager];
|
|
|
|
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
|
|
|
|
{
|
|
|
|
id <WOActionResults> response;
|
|
|
|
NSString *destinationFolderId;
|
|
|
|
NSArray *contactsId;
|
2015-08-10 15:48:47 +02:00
|
|
|
NSDictionary *data;
|
2008-08-10 23:44:25 +02:00
|
|
|
NSException *ex;
|
|
|
|
|
2015-08-10 15:48:47 +02:00
|
|
|
data = [[[context request] contentAsString] objectFromJSONString];
|
|
|
|
contactsId = [data objectForKey: @"uids"];
|
|
|
|
destinationFolderId = [data objectForKey: @"folder"];
|
2008-08-10 23:44:25 +02:00
|
|
|
|
2015-08-10 15:48:47 +02:00
|
|
|
if (destinationFolderId && [contactsId count])
|
2010-01-19 13:28:10 +01:00
|
|
|
ex = [self _moveContacts: contactsId
|
|
|
|
toFolder: destinationFolderId
|
2008-08-10 23:44:25 +02:00
|
|
|
andKeepCopy: YES];
|
|
|
|
else
|
2010-01-19 13:28:10 +01:00
|
|
|
ex = [NSException exceptionWithHTTPStatus: 400
|
|
|
|
reason: (@"missing 'folder' and/or"
|
|
|
|
@" 'uid' parameter")];
|
2008-08-10 23:44:25 +02:00
|
|
|
|
2010-01-19 13:28:10 +01:00
|
|
|
if (ex)
|
|
|
|
response = (id) ex;
|
|
|
|
else
|
|
|
|
response = [self responseWith204];
|
2008-08-10 23:44:25 +02:00
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id <WOActionResults>) moveAction
|
|
|
|
{
|
|
|
|
id <WOActionResults> response;
|
|
|
|
NSString *destinationFolderId;
|
2015-08-10 15:48:47 +02:00
|
|
|
NSDictionary *data;
|
2008-08-10 23:44:25 +02:00
|
|
|
NSArray *contactsId;
|
|
|
|
NSException *ex;
|
|
|
|
|
2015-08-10 15:48:47 +02:00
|
|
|
data = [[[context request] contentAsString] objectFromJSONString];
|
|
|
|
contactsId = [data objectForKey: @"uids"];
|
|
|
|
destinationFolderId = [data objectForKey: @"folder"];
|
2008-08-10 23:44:25 +02:00
|
|
|
|
2015-08-10 15:48:47 +02:00
|
|
|
if (destinationFolderId && [contactsId count])
|
2010-01-19 13:28:10 +01:00
|
|
|
ex = [self _moveContacts: contactsId
|
|
|
|
toFolder: destinationFolderId
|
2008-08-10 23:44:25 +02:00
|
|
|
andKeepCopy: NO];
|
|
|
|
else
|
2010-01-19 13:28:10 +01:00
|
|
|
ex = [NSException exceptionWithHTTPStatus: 400
|
|
|
|
reason: (@"missing 'folder' and/or"
|
|
|
|
@"'uid' parameter")];
|
2008-08-10 23:44:25 +02:00
|
|
|
|
2010-01-19 13:28:10 +01:00
|
|
|
if (ex)
|
|
|
|
response = (id <WOActionResults>) ex;
|
|
|
|
else
|
|
|
|
response = [self responseWith204];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
2008-08-10 23:44:25 +02:00
|
|
|
|
2015-01-13 17:30:23 +01:00
|
|
|
/**
|
|
|
|
* @api {get} /so/:username/:folderPath/subscribeUsers?uids=:uids Subscribe user(s)
|
|
|
|
* @apiVersion 1.0.0
|
|
|
|
* @apiName GetSubscribeUsers
|
|
|
|
* @apiGroup Common
|
|
|
|
* @apiExample {curl} Example usage:
|
|
|
|
* curl -i http://localhost/SOGo/so/sogo1/Calendar/personal/subscribeUsers?uids=sogo2,sogo3
|
|
|
|
*
|
|
|
|
* @apiParam {String} uids Comma-separated list of user IDs
|
|
|
|
*
|
|
|
|
* @apiError (Error 400) {Object} error The error message
|
|
|
|
*/
|
2010-01-19 13:28:10 +01:00
|
|
|
- (id <WOActionResults>) subscribeUsersAction
|
|
|
|
{
|
|
|
|
id <WOActionResults> response;
|
|
|
|
NSString *uids;
|
|
|
|
NSArray *userIDs;
|
|
|
|
SOGoGCSFolder *folder;
|
|
|
|
int count, max;
|
|
|
|
|
|
|
|
uids = [[context request] formValueForKey: @"uids"];
|
|
|
|
if ([uids length])
|
|
|
|
{
|
|
|
|
userIDs = [uids componentsSeparatedByString: @","];
|
|
|
|
folder = [self clientObject];
|
|
|
|
max = [userIDs count];
|
|
|
|
for (count = 0; count < max; count++)
|
2012-04-18 19:39:11 +02:00
|
|
|
[folder subscribeUserOrGroup: [userIDs objectAtIndex: count]
|
2014-07-24 18:48:03 +02:00
|
|
|
reallyDo: YES
|
2014-08-15 15:57:19 +02:00
|
|
|
response: nil];
|
2015-01-13 17:30:23 +01:00
|
|
|
response = [self responseWith204];
|
2010-01-19 13:28:10 +01:00
|
|
|
}
|
|
|
|
else
|
2015-01-13 17:30:23 +01:00
|
|
|
response = [self responseWithStatus: 400
|
|
|
|
andJSONRepresentation: [NSDictionary dictionaryWithObject: @"missing 'uids' parameter"
|
2015-12-10 19:40:31 +01:00
|
|
|
forKey: @"message"]];
|
2010-01-19 13:28:10 +01:00
|
|
|
|
|
|
|
return response;
|
2008-08-10 23:44:25 +02:00
|
|
|
}
|
|
|
|
|
2007-03-27 20:10:01 +02:00
|
|
|
@end
|