Monotone-Parent: 5652b12a99be3b69adbf207347b951ec2e5f6c89

Monotone-Revision: 45f4738cc8fd2e71713e3625b32c19bd7ac54ce4

Monotone-Author: flachapelle@inverse.ca
Monotone-Date: 2008-07-09T17:11:18
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Francis Lachapelle
2008-07-09 17:11:18 +00:00
parent 812c7c535e
commit 4a29cda5b0
9 changed files with 299 additions and 73 deletions
@@ -133,3 +133,10 @@
= "The selected contact has no email address.";
"Please select a contact." = "Please select a contact.";
/* Error messages for move and copy */
"SoAccessDeniedException" = "You cannot write to this address book.";
"Forbidden" = "You cannot write to this address book.";
"Invalid Contact" = "The selected contact no longer exists.";
"Unknown Destination Folder" = "The chosen destination address book no longer exists.";
@@ -145,3 +145,10 @@
= "Cette personne n'a pas d'adresse courriel.";
"Please select a contact." = "Veuillez sélectionner un contact..";
/* Error messages for move and copy */
"SoAccessDeniedException" = "Vous ne pouvez pas ajouter de fiches à ce carnet.";
"Forbidden" = "Vous ne pouvez pas ajouter de fiches à ce carnet.";
"Invalid Contact" = "La fiche sélectionnée n'existe plus.";
"Unknown Destination Folder" = "Le carnet d'adresses choisi n'existe plus.";
+2 -2
View File
@@ -31,8 +31,8 @@
{
}
- (WOResponse *) copyAction;
- (WOResponse *) moveAction;
- (id <WOActionResults>) copyAction;
- (id <WOActionResults>) moveAction;
@end
+127 -50
View File
@@ -24,6 +24,9 @@
#import <Foundation/NSDictionary.h>
#import <Foundation/NSEnumerator.h>
#import <NGObjWeb/NSException+HTTP.h>
#import <NGObjWeb/SoPermissions.h>
#import <NGObjWeb/SoSecurityManager.h>
#import <NGObjWeb/WOContext+SoObjects.h>
#import <NGObjWeb/WORequest.h>
#import <NGObjWeb/WOResponse.h>
@@ -46,83 +49,157 @@
@implementation UIxContactFolderActions
- (id) init
- (NSException*) _moveContacts: (NSArray*) contactsId
toFolder: (NSString*) destinationFolderId
andKeepCopy: (BOOL) keepCopy
{
if ((self = [super init]))
{
}
return self;
}
- (void) dealloc
{
[super dealloc];
}
- (WOResponse *) copyAction
{
WORequest *request;
NSArray *contactsId;
NSEnumerator *uids;
NSString *folderId, *uid, *newUid;
SOGoContactFolders *folders;
SOGoParentFolder *folder, *destinationFolder;
id <SOGoContactObject> contact;
SOGoContentObject *newContact;
NGVCard *card;
NSEnumerator *uids;
NSException *ex;
NSString *uid, *newUid;
id <SOGoContactObject> contact;
SOGoContactFolders *folders;
SOGoParentFolder *sourceFolder, *destinationFolder;
SOGoContentObject *newContact;
SoSecurityManager *sm;
WORequest *request;
unsigned int errorCount;
sm = [SoSecurityManager sharedSecurityManager];
request = [context request];
ex = nil;
errorCount = 0;
if ((folderId = [request formValueForKey: @"folder"]) &&
(contactsId = [request formValuesForKey: @"uid"]))
// Search the specified destination folder
sourceFolder = [self clientObject];
folders = [(SOGoUserFolder*)[[sourceFolder container] container] privateContacts: @"Contacts"
inContext: nil];
destinationFolder = [folders lookupName: destinationFolderId
inContext: nil
acquire: NO];
if (destinationFolder)
{
// Search the specified destination folder
folder = [self clientObject];
folders = [(SOGoUserFolder*)[[folder container] container] privateContacts: @"Contacts"
inContext: nil];
destinationFolder = [folders lookupName: folderId
inContext: nil
acquire: NO];
if (destinationFolder)
// Verify write access to the folder
ex = [sm validatePermission: SoPerm_AddDocumentsImagesAndFiles
onObject: destinationFolder
inContext: context];
if (ex == nil)
{
uids = [contactsId objectEnumerator];
uids = [contactsId objectEnumerator];
uid = [uids nextObject];
while (uid)
{
contact = [folder lookupName: uid
inContext: [self context]
acquire: NO];
if (![(NSObject*)contact isKindOfClass: [NSException class]])
// Search the contact ID
contact = [sourceFolder lookupName: uid
inContext: [self context]
acquire: NO];
if ([(NSObject*)contact isKindOfClass: [NSException class]])
errorCount++;
else
{
newUid = [SOGoObject globallyUniqueObjectId];
card = [contact vCard];
[card setUid: newUid];
//[contact setContent: [card versitString]];
//[contact copyTo: destinationFolder]; // verify if exception
newContact = [SOGoContentObject objectWithName: newUid
inContainer: destinationFolder];
if (keepCopy)
{
// Change the contact UID
newUid = [SOGoObject globallyUniqueObjectId];
[card setUid: newUid];
newContact = [SOGoContentObject objectWithName: newUid
inContainer: destinationFolder];
}
else
// Don't change the contact UID
newContact = [SOGoContentObject objectWithName: [contact nameInContainer]
inContainer: (SOGoGCSFolder*)destinationFolder];
ex = [newContact saveContentString: [card versitString]];
if (ex == nil && !keepCopy)
// Delete the original contact if necessary
ex = [contact delete];
if (ex != nil)
errorCount++;
}
}
uid = [uids nextObject];
}
}
}
else
ex = [NSException exceptionWithName: @"UnkownDestinationFolder"
reason: @"Unknown Destination Folder"
userInfo: nil];
return [self responseWithStatus: 204];
if (errorCount > 0)
// At least one contact 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;
}
- (WOResponse *) moveAction
- (id <WOActionResults>) copyAction
{
return [self responseWithStatus: 204];
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;
}
@end
+3 -8
View File
@@ -97,12 +97,12 @@
actionName = "saveUserRights";
};
copy = {
protectedBy = "View";
protectedBy = "Access Contents Information";
actionClass = "UIxContactFolderActions";
actionName = "copy";
};
move = {
protectedBy = "View";
protectedBy = "Delete Objects";
actionClass = "UIxContactFolderActions";
actionName = "move";
};
@@ -137,15 +137,10 @@
actionName = "canAccessContent";
};
copy = {
protectedBy = "<public>";
protectedBy = "Access Contents Information";
actionClass = "UIxContactFolderActions";
actionName = "copy";
};
move = {
protectedBy = "<public>";
actionClass = "UIxContactFolderActions";
actionName = "move";
};
};
};