2010-11-01 20:32:19 +01:00
|
|
|
/* UIxContactActions.m - this file is part of SOGo
|
|
|
|
*
|
2018-01-23 19:30:56 +01:00
|
|
|
* Copyright (C) 2010-2018 Inverse inc.
|
2010-11-01 20:32:19 +01: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Foundation/NSArray.h>
|
2018-01-23 19:30:56 +01:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2010-11-01 20:32:19 +01:00
|
|
|
|
2016-06-08 22:25:54 +02:00
|
|
|
#import <NGExtensions/NSString+misc.h>
|
|
|
|
|
2012-10-22 16:09:13 +02:00
|
|
|
#import <NGObjWeb/WOContext.h>
|
2010-11-01 20:32:19 +01:00
|
|
|
#import <NGObjWeb/WORequest.h>
|
2012-10-22 16:09:13 +02:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
2010-11-01 20:32:19 +01:00
|
|
|
|
|
|
|
#import <NGCards/NGVCard.h>
|
|
|
|
|
|
|
|
#import <Contacts/SOGoContactGCSEntry.h>
|
|
|
|
|
2018-01-23 19:30:56 +01:00
|
|
|
#import <Mailer/NSData+SMIME.h>
|
|
|
|
|
2016-05-04 15:43:27 +02:00
|
|
|
#import <SOGoUI/SOGoDirectAction.h>
|
2010-11-01 20:32:19 +01:00
|
|
|
|
|
|
|
@interface NGVCard (SOGoActionCategory)
|
|
|
|
|
|
|
|
- (BOOL) addOrRemove: (BOOL) set
|
|
|
|
category: (NSString *) newCategory;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NGVCard (SOGoActionCategory)
|
|
|
|
|
|
|
|
- (BOOL) addOrRemove: (BOOL) set
|
|
|
|
category: (NSString *) category
|
|
|
|
{
|
|
|
|
NSMutableArray *categories;
|
|
|
|
BOOL modified;
|
|
|
|
NSUInteger idx;
|
|
|
|
|
|
|
|
modified = NO;
|
|
|
|
|
|
|
|
categories = [[self categories] mutableCopy];
|
|
|
|
[categories autorelease];
|
2011-12-30 21:39:07 +01:00
|
|
|
if (!categories)
|
|
|
|
categories = [NSMutableArray array];
|
2010-11-01 20:32:19 +01:00
|
|
|
if (set)
|
|
|
|
{
|
|
|
|
if (![categories containsObject: category])
|
|
|
|
{
|
|
|
|
[categories addObject: category];
|
|
|
|
modified = YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
idx = [categories indexOfObject: category];
|
|
|
|
if (idx != NSNotFound)
|
|
|
|
{
|
|
|
|
[categories removeObjectAtIndex: idx];
|
|
|
|
modified = YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (modified)
|
|
|
|
[self setCategories: categories];
|
|
|
|
|
|
|
|
return modified;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2016-04-26 17:06:44 +02:00
|
|
|
@interface UIxContactActions : SOGoDirectAction
|
2010-11-01 20:32:19 +01:00
|
|
|
|
|
|
|
- (WOResponse *) setCategoryAction;
|
|
|
|
- (WOResponse *) unsetCategoryAction;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation UIxContactActions
|
|
|
|
|
|
|
|
- (WOResponse *) _setOrUnsetCategoryAction: (BOOL) set
|
|
|
|
{
|
|
|
|
SOGoContactGCSEntry *contact;
|
|
|
|
NSString *category;
|
|
|
|
WORequest *rq;
|
|
|
|
WOResponse *response;
|
|
|
|
NGVCard *card;
|
|
|
|
|
|
|
|
rq = [context request];
|
|
|
|
category = [rq formValueForKey: @"category"];
|
|
|
|
if ([category length] > 0)
|
|
|
|
{
|
|
|
|
contact = [self clientObject];
|
|
|
|
if (![contact isNew])
|
|
|
|
{
|
|
|
|
card = [contact vCard];
|
|
|
|
if ([card addOrRemove: set category: category])
|
|
|
|
[contact save];
|
|
|
|
response = [self responseWith204];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
response = [self responseWithStatus: 404
|
|
|
|
andString: @"Contact does not exist"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
response = [self responseWithStatus: 403
|
|
|
|
andString: @"Missing 'category' parameter"];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) setCategoryAction
|
|
|
|
{
|
|
|
|
return [self _setOrUnsetCategoryAction: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) unsetCategoryAction
|
|
|
|
{
|
|
|
|
return [self _setOrUnsetCategoryAction: NO];
|
|
|
|
}
|
|
|
|
|
2012-07-09 16:17:07 +02:00
|
|
|
// returns the raw content of the object
|
|
|
|
- (WOResponse *) rawAction
|
|
|
|
{
|
|
|
|
NSMutableString *content;
|
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
content = [NSMutableString string];
|
|
|
|
response = [context response];
|
|
|
|
|
2015-10-31 07:10:03 +01:00
|
|
|
[content appendFormat: @"%@", [[self clientObject] contentAsString]];
|
2012-07-09 16:17:07 +02:00
|
|
|
[response setHeader: @"text/plain; charset=utf-8"
|
|
|
|
forKey: @"content-type"];
|
2016-06-08 22:25:54 +02:00
|
|
|
[response appendContentString: [content stringByEscapingHTMLString]];
|
2012-07-09 16:17:07 +02:00
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2018-01-23 19:30:56 +01:00
|
|
|
- (WOResponse *) certificateAction
|
|
|
|
{
|
|
|
|
NSData *pkcs7;
|
|
|
|
NSDictionary *data;
|
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
pkcs7 = [[[self clientObject] vCard] certificate];
|
|
|
|
|
|
|
|
if (pkcs7)
|
|
|
|
{
|
2019-05-08 14:09:14 +02:00
|
|
|
data = [[pkcs7 signersFromPKCS7] certificateDescription];
|
2018-01-23 19:30:56 +01:00
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
response = [self responseWithStatus: 200 andJSONRepresentation: data];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data = [NSDictionary
|
|
|
|
dictionaryWithObject: [self labelForKey: @"Error reading the card certificate."]
|
|
|
|
forKey: @"message"];
|
|
|
|
response = [self responseWithStatus: 500 andJSONRepresentation: data];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data = [NSDictionary
|
|
|
|
dictionaryWithObject: [self labelForKey: @"No certificate associated to card."]
|
|
|
|
forKey: @"message"];
|
|
|
|
response = [self responseWithStatus: 404 andJSONRepresentation: data];
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) removeCertificateAction
|
|
|
|
{
|
|
|
|
[[[self clientObject] vCard] setCertificate: nil];
|
|
|
|
|
|
|
|
return [self responseWith204];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-01 20:32:19 +01:00
|
|
|
@end
|