From 79fc9f4c2613dd018333183a40a4d2cde84e8b25 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Thu, 30 Sep 2010 18:05:14 +0000 Subject: [PATCH] Monotone-Parent: c494ba259363880f5d46e8931a1708d1ba1aed45 Monotone-Revision: 5f57280bc0c8371b942a310b60e1dfa1a790fb84 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-09-30T18:05:14 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 29 ++++ SoObjects/Mailer/GNUmakefile | 3 +- SoObjects/Mailer/SOGoMailAccount.h | 7 + SoObjects/Mailer/SOGoMailAccount.m | 128 +++++++++++++++++- SoObjects/Mailer/SOGoUser+Mailer.h | 36 +++++ SoObjects/Mailer/SOGoUser+Mailer.m | 77 +++++++++++ .../Localizable.strings | 2 + UI/MailerUI/Czech.lproj/Localizable.strings | 2 + UI/MailerUI/Dutch.lproj/Localizable.strings | 2 + UI/MailerUI/English.lproj/Localizable.strings | 2 + UI/MailerUI/French.lproj/Localizable.strings | 2 + UI/MailerUI/GNUmakefile | 1 + UI/MailerUI/German.lproj/Localizable.strings | 2 + .../Hungarian.lproj/Localizable.strings | 2 + UI/MailerUI/Italian.lproj/Localizable.strings | 2 + UI/MailerUI/Polish.lproj/Localizable.strings | 2 + UI/MailerUI/Russian.lproj/Localizable.strings | 2 + UI/MailerUI/Spanish.lproj/Localizable.strings | 2 + UI/MailerUI/Swedish.lproj/Localizable.strings | 2 + UI/MailerUI/UIxMailAccountActions.m | 37 +++++ UI/MailerUI/UIxMailUserDelegationEditor.m | 112 +++++++++++++++ .../Ukrainian.lproj/Localizable.strings | 2 + UI/MailerUI/Welsh.lproj/Localizable.strings | 2 + UI/MailerUI/product.plist | 14 ++ UI/Templates/MailerUI/UIxMailMainFrame.wox | 2 +- .../MailerUI/UIxMailUserDelegationEditor.wox | 35 +++++ UI/WebServerResources/MailerUI.js | 40 +++++- .../UIxContactsUserFolders.js | 4 +- .../UIxMailUserDelegationEditor.css | 58 ++++++++ .../UIxMailUserDelegationEditor.js | 111 +++++++++++++++ 30 files changed, 712 insertions(+), 10 deletions(-) create mode 100644 SoObjects/Mailer/SOGoUser+Mailer.h create mode 100644 SoObjects/Mailer/SOGoUser+Mailer.m create mode 100644 UI/MailerUI/UIxMailUserDelegationEditor.m create mode 100644 UI/Templates/MailerUI/UIxMailUserDelegationEditor.wox create mode 100644 UI/WebServerResources/UIxMailUserDelegationEditor.css create mode 100644 UI/WebServerResources/UIxMailUserDelegationEditor.js diff --git a/ChangeLog b/ChangeLog index d6dce8142..31930682a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,34 @@ 2010-09-30 Wolfgang Sourdeau + * UI/WebServerResources/UIxContactsUserFolders.js: + (onConfirmFolderSelection): fixed the regexp used when sanitizing + a username containing a user info field. + + * SoObjects/Mailer/SOGoMailAccount.m (-identities): the account + identities are now kept in an ivar until the account object is + released. Moreoever, we invoke the new + "_appendDelegatorIdentities" method when the account + nameInContainer is "0". + (-_appendDelegatorIdentities): new method that appends the mail + values of all delegators for the owner user. + + * UI/WebServerResources/MailerUI.js: (onMenuAccountDelegation): + new menu action for showing the new dialog below. + (onAccountIconMenuPrepareVisibility): new setup function. + + * UI/MailerUI/UIxMailAccountActions.m (-addDelegateAction) + (-removeDelegation): new action methods. + + * SoObjects/Mailer/SOGoUser+Mailer.m: new category module. + (mailDelegators, addMailDelegator, removeMailDelegator): new + accessors. + + * UI/MailerUI/UIxMailUserDelegationEditor.m: new window for + choosing account delegates + + * UI/WebServerResources/UIxMailUserDelegationEditor.js: new page + file, derived from UIxAclEditor.js. + * SoObjects/SOGo/NSDictionary+BSJSONAdditions.m (+[NSMutableDictionary dictionaryWithJSONString:]): return nil directly if the json string is empty. diff --git a/SoObjects/Mailer/GNUmakefile b/SoObjects/Mailer/GNUmakefile index acfe45445..e20b687b4 100644 --- a/SoObjects/Mailer/GNUmakefile +++ b/SoObjects/Mailer/GNUmakefile @@ -37,7 +37,8 @@ Mailer_OBJC_FILES += \ \ EOQualifier+MailDAV.m \ NSData+Mail.m \ - NSString+Mail.m + NSString+Mail.m \ + SOGoUser+Mailer.m Mailer_RESOURCE_FILES += \ Version \ diff --git a/SoObjects/Mailer/SOGoMailAccount.h b/SoObjects/Mailer/SOGoMailAccount.h index 472e0e037..db16fe53c 100644 --- a/SoObjects/Mailer/SOGoMailAccount.h +++ b/SoObjects/Mailer/SOGoMailAccount.h @@ -35,6 +35,7 @@ */ @class NSArray; +@class NSMutableArray; @class NSString; @class SOGoMailFolder; @@ -55,6 +56,7 @@ typedef enum { SOGoSentFolder *sentFolder; SOGoTrashFolder *trashFolder; SOGoIMAPAclStyle imapAclStyle; + NSMutableArray *identities; } - (SOGoIMAPAclStyle) imapAclStyle; @@ -89,6 +91,11 @@ typedef enum { - (NSArray *) otherUsersFolderNamespaces; - (NSArray *) sharedFolderNamespaces; +/* account delegation */ +- (NSArray *) delegates; +- (void) addDelegates: (NSArray *) newDelegates; +- (void) removeDelegates: (NSArray *) oldDelegates; + @end #endif /* __Mailer_SOGoMailAccount_H__ */ diff --git a/SoObjects/Mailer/SOGoMailAccount.m b/SoObjects/Mailer/SOGoMailAccount.m index b0ed7714f..42d432fed 100644 --- a/SoObjects/Mailer/SOGoMailAccount.m +++ b/SoObjects/Mailer/SOGoMailAccount.m @@ -44,7 +44,6 @@ #import #import #import -#import #import "SOGoDraftsFolder.h" #import "SOGoMailFolder.h" @@ -53,7 +52,7 @@ #import "SOGoSentFolder.h" #import "SOGoSieveConverter.h" #import "SOGoTrashFolder.h" - +#import "SOGoUser+Mailer.h" #import "SOGoMailAccount.h" @@ -71,6 +70,7 @@ static NSString *sieveScriptName = @"sogo"; sentFolder = nil; trashFolder = nil; imapAclStyle = undefined; + identities = nil; } return self; @@ -82,6 +82,7 @@ static NSString *sieveScriptName = @"sogo"; [draftsFolder release]; [sentFolder release]; [trashFolder release]; + [identities release]; [super dealloc]; } @@ -482,17 +483,47 @@ static NSString *sieveScriptName = @"sogo"; return mailAccount; } +- (void) _appendDelegatorIdentities +{ + NSArray *delegators; + SOGoUser *delegatorUser; + NSDictionary *delegatorAccount; + NSInteger count, max; + + delegators = [[SOGoUser userWithLogin: owner] mailDelegators]; + max = [delegators count]; + for (count = 0; count < max; count++) + { + delegatorUser = [SOGoUser + userWithLogin: [delegators objectAtIndex: count]]; + if (delegatorUser) + { + delegatorAccount = [[delegatorUser mailAccounts] + objectAtIndex: 0]; + [identities addObjectsFromArray: + [delegatorAccount objectForKey: @"identities"]]; + } + } +} + - (NSArray *) identities { - return [[self _mailAccount] objectForKey: @"identities"]; + if (!identities) + { + identities = [[[self _mailAccount] objectForKey: @"identities"] + mutableCopy]; + if ([nameInContainer isEqualToString: @"0"]) + [self _appendDelegatorIdentities]; + } + + return identities; } - (NSString *) signature { - NSArray *identities; NSString *signature; - identities = [self identities]; + [self identities]; if ([identities count] > 0) signature = [[identities objectAtIndex: 0] objectForKey: @"signature"]; else @@ -766,6 +797,93 @@ static NSString *sieveScriptName = @"sogo"; return trashFolder; } +/* account delegation */ +- (NSArray *) delegates +{ + NSDictionary *mailSettings; + SOGoUser *ownerUser; + NSArray *delegates; + + if ([nameInContainer isEqualToString: @"0"]) + { + ownerUser = [SOGoUser userWithLogin: [self ownerInContext: context]]; + mailSettings = [[ownerUser userSettings] objectForKey: @"Mail"]; + delegates = [mailSettings objectForKey: @"DelegateTo"]; + if (!delegates) + delegates = [NSArray array]; + } + else + delegates = nil; + + return delegates; +} + +- (void) _setDelegates: (NSArray *) newDelegates +{ + SOGoUser *ownerUser; + SOGoUserSettings *settings; + + ownerUser = [SOGoUser userWithLogin: [self ownerInContext: context]]; + settings = [ownerUser userSettings]; + [[settings objectForKey: @"Mail"] setObject: newDelegates + forKey: @"DelegateTo"]; + [settings synchronize]; +} + +- (void) addDelegates: (NSArray *) newDelegates +{ + NSMutableArray *delegates; + NSInteger count, max; + NSString *currentDelegate; + SOGoUser *delegateUser; + + if ([nameInContainer isEqualToString: @"0"]) + { + delegates = [[self delegates] mutableCopy]; + [delegates autorelease]; + max = [newDelegates count]; + for (count = 0; count < max; count++) + { + currentDelegate = [newDelegates objectAtIndex: 0]; + delegateUser = [SOGoUser userWithLogin: currentDelegate]; + if (delegateUser) + { + [delegates addObjectUniquely: currentDelegate]; + [delegateUser addMailDelegator: owner]; + } + } + + [self _setDelegates: delegates]; + } +} + +- (void) removeDelegates: (NSArray *) oldDelegates +{ + NSMutableArray *delegates; + NSInteger count, max; + NSString *currentDelegate; + SOGoUser *delegateUser; + + if ([nameInContainer isEqualToString: @"0"]) + { + delegates = [[self delegates] mutableCopy]; + [delegates autorelease]; + max = [oldDelegates count]; + for (count = 0; count < max; count++) + { + currentDelegate = [oldDelegates objectAtIndex: 0]; + delegateUser = [SOGoUser userWithLogin: currentDelegate]; + if (delegateUser) + { + [delegates removeObject: currentDelegate]; + [delegateUser removeMailDelegator: owner]; + } + } + + [self _setDelegates: delegates]; + } +} + /* WebDAV */ - (NSString *) davContentType diff --git a/SoObjects/Mailer/SOGoUser+Mailer.h b/SoObjects/Mailer/SOGoUser+Mailer.h new file mode 100644 index 000000000..e665291fb --- /dev/null +++ b/SoObjects/Mailer/SOGoUser+Mailer.h @@ -0,0 +1,36 @@ +/* SOGoUser+Mailer.h - this file is part of SOGo + * + * Copyright (C) 2010 Inverse inc. + * + * Author: Wolfgang Sourdeau + * + * 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. + */ + +#ifndef SOGOUSER_MAILER_H +#define SOGOUSER_MAILER_H + +#import + +@interface SOGoUser (SOGoMailExtensions) + +- (NSArray *) mailDelegators; +- (void) addMailDelegator: (NSString *) newDelegator; +- (void) removeMailDelegator: (NSString *) oldDelegator; + +@end + +#endif /* SOGOUSER_MAILER_H */ diff --git a/SoObjects/Mailer/SOGoUser+Mailer.m b/SoObjects/Mailer/SOGoUser+Mailer.m new file mode 100644 index 000000000..c96ce8abf --- /dev/null +++ b/SoObjects/Mailer/SOGoUser+Mailer.m @@ -0,0 +1,77 @@ +/* SOGoUser+Mailer.m - this file is part of SOGo + * + * Copyright (C) 2010 Inverse inc. + * + * Author: Wolfgang Sourdeau + * + * 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 + +#import +#import + +#import "SOGoUser+Mailer.h" + +@implementation SOGoUser (SOGoMailExtensions) + +- (NSArray *) mailDelegators +{ + NSDictionary *mailSettings; + NSArray *mailDelegators; + + mailSettings = [[self userSettings] objectForKey: @"Mail"]; + mailDelegators = [mailSettings objectForKey: @"DelegateFrom"]; + if (!mailDelegators) + mailDelegators = [NSArray array]; + + return mailDelegators; +} + +- (void) _setMailDelegators: (NSArray *) newDelegators +{ + SOGoUserSettings *settings; + + settings = [self userSettings]; + [[settings objectForKey: @"Mail"] setObject: newDelegators + forKey: @"DelegateFrom"]; + [settings synchronize]; +} + +- (void) addMailDelegator: (NSString *) newDelegator +{ + NSMutableArray *delegators; + + delegators = [[self mailDelegators] mutableCopy]; + [delegators autorelease]; + [delegators addObjectUniquely: newDelegator]; + + [self _setMailDelegators: delegators]; +} + +- (void) removeMailDelegator: (NSString *) oldDelegator +{ + NSMutableArray *delegators; + + delegators = [[self mailDelegators] mutableCopy]; + [delegators autorelease]; + [delegators removeObject: oldDelegator]; + + [self _setMailDelegators: delegators]; +} + +@end diff --git a/UI/MailerUI/BrazilianPortuguese.lproj/Localizable.strings b/UI/MailerUI/BrazilianPortuguese.lproj/Localizable.strings index 0460bf8bf..ad6f69e7b 100644 --- a/UI/MailerUI/BrazilianPortuguese.lproj/Localizable.strings +++ b/UI/MailerUI/BrazilianPortuguese.lproj/Localizable.strings @@ -194,6 +194,8 @@ "Delete Folder" = "Apagar Pasta"; "Use This Folder For" = "Usar Esta Pasta Para"; "Get Messages for Account" = "Receber Mensagens por Conta"; +"Properties..." = "Properties..."; +"Delegation..." = "Delegation..."; /* Use This Folder menu */ "Sent Messages" = "Enviar Mensagens"; diff --git a/UI/MailerUI/Czech.lproj/Localizable.strings b/UI/MailerUI/Czech.lproj/Localizable.strings index 74878405f..4834d6c4d 100644 --- a/UI/MailerUI/Czech.lproj/Localizable.strings +++ b/UI/MailerUI/Czech.lproj/Localizable.strings @@ -195,6 +195,8 @@ "Delete Folder" = "Smazat složku"; "Use This Folder For" = "Použít tuto složku pro"; "Get Messages for Account" = "Stáhnout zprávy pro účet"; +"Properties..." = "Properties..."; +"Delegation..." = "Delegation..."; /* Use This Folder menu */ "Sent Messages" = "Odeslané zprávy"; diff --git a/UI/MailerUI/Dutch.lproj/Localizable.strings b/UI/MailerUI/Dutch.lproj/Localizable.strings index 92fc80992..f851f82e2 100644 --- a/UI/MailerUI/Dutch.lproj/Localizable.strings +++ b/UI/MailerUI/Dutch.lproj/Localizable.strings @@ -194,6 +194,8 @@ "Delete Folder" = "Map verwijderen"; "Use This Folder For" = "De map gebruiken voor..."; "Get Messages for Account" = "Berichten ophalen voor account"; +"Properties..." = "Properties..."; +"Delegation..." = "Delegation..."; /* Use This Folder menu */ "Sent Messages" = "Berichten verzenden"; diff --git a/UI/MailerUI/English.lproj/Localizable.strings b/UI/MailerUI/English.lproj/Localizable.strings index 38b3c12c1..bb7412fd9 100644 --- a/UI/MailerUI/English.lproj/Localizable.strings +++ b/UI/MailerUI/English.lproj/Localizable.strings @@ -194,6 +194,8 @@ "Delete Folder" = "Delete Folder"; "Use This Folder For" = "Use This Folder For"; "Get Messages for Account" = "Get Messages for Account"; +"Properties..." = "Properties..."; +"Delegation..." = "Delegation..."; /* Use This Folder menu */ "Sent Messages" = "Sent Messages"; diff --git a/UI/MailerUI/French.lproj/Localizable.strings b/UI/MailerUI/French.lproj/Localizable.strings index 3128f127b..b78322ca5 100644 --- a/UI/MailerUI/French.lproj/Localizable.strings +++ b/UI/MailerUI/French.lproj/Localizable.strings @@ -194,6 +194,8 @@ "Delete Folder" = "Supprimer le dossier..."; "Use This Folder For" = "Utiliser ce dossier pour"; "Get Messages for Account" = "Relever les messages de ce compte"; +"Properties..." = "Propriétés..."; +"Delegation..." = "Délégation..."; /* Use This Folder menu */ "Sent Messages" = "les message envoyés"; diff --git a/UI/MailerUI/GNUmakefile b/UI/MailerUI/GNUmakefile index 6d0dbbd3d..b7c8be7a9 100644 --- a/UI/MailerUI/GNUmakefile +++ b/UI/MailerUI/GNUmakefile @@ -32,6 +32,7 @@ MailerUI_OBJC_FILES += \ UIxMailWindowCloser.m \ \ UIxMailUserRightsEditor.m \ + UIxMailUserDelegationEditor.m \ # UIxMailEditorAction.m \ # UIxMailReplyAction.m \ # UIxMailForwardAction.m \ diff --git a/UI/MailerUI/German.lproj/Localizable.strings b/UI/MailerUI/German.lproj/Localizable.strings index b24eeb05f..14e60b3e5 100644 --- a/UI/MailerUI/German.lproj/Localizable.strings +++ b/UI/MailerUI/German.lproj/Localizable.strings @@ -194,6 +194,8 @@ "Delete Folder" = "Löschen"; "Use This Folder For" = "Diesen Ordner verwenden für"; "Get Messages for Account" = "Neue Nachrichten empfangen"; +"Properties..." = "Properties..."; +"Delegation..." = "Delegation..."; /* Use This Folder menu */ "Sent Messages" = "Gesendete Nachrichten"; diff --git a/UI/MailerUI/Hungarian.lproj/Localizable.strings b/UI/MailerUI/Hungarian.lproj/Localizable.strings index ed138b9f0..9fb652f74 100644 --- a/UI/MailerUI/Hungarian.lproj/Localizable.strings +++ b/UI/MailerUI/Hungarian.lproj/Localizable.strings @@ -194,6 +194,8 @@ "Delete Folder" = "Mappa törlése"; "Use This Folder For" = "Mappa használata az alábbira:"; "Get Messages for Account" = "Fiók üzeneteinek letöltése"; +"Properties..." = "Properties..."; +"Delegation..." = "Delegation..."; /* Use This Folder menu */ "Sent Messages" = "Elküldött üzenetek"; diff --git a/UI/MailerUI/Italian.lproj/Localizable.strings b/UI/MailerUI/Italian.lproj/Localizable.strings index b4f2988a0..751dc0e54 100644 --- a/UI/MailerUI/Italian.lproj/Localizable.strings +++ b/UI/MailerUI/Italian.lproj/Localizable.strings @@ -189,6 +189,8 @@ "Delete Folder" = "Cancella cartella"; "Use This Folder For" = "Usa questa cartella per"; "Get Messages for Account" = "Scarica messaggi per l'account"; +"Properties..." = "Properties..."; +"Delegation..." = "Delegation..."; /* Use This Folder menu */ "Sent Messages" = "Messaggi inviati"; diff --git a/UI/MailerUI/Polish.lproj/Localizable.strings b/UI/MailerUI/Polish.lproj/Localizable.strings index a24a921e8..0a0b576fd 100644 --- a/UI/MailerUI/Polish.lproj/Localizable.strings +++ b/UI/MailerUI/Polish.lproj/Localizable.strings @@ -194,6 +194,8 @@ "Delete Folder" = "Usuń folder"; "Use This Folder For" = "Użyj tego foldera do"; "Get Messages for Account" = "Pobierz wiadomości z konta"; +"Properties..." = "Properties..."; +"Delegation..." = "Delegation..."; /* Use This Folder menu */ "Sent Messages" = "Wysłane"; diff --git a/UI/MailerUI/Russian.lproj/Localizable.strings b/UI/MailerUI/Russian.lproj/Localizable.strings index 2d2f5dd36..a34db5d47 100644 --- a/UI/MailerUI/Russian.lproj/Localizable.strings +++ b/UI/MailerUI/Russian.lproj/Localizable.strings @@ -194,6 +194,8 @@ "Delete Folder" = "Удалить папку"; "Use This Folder For" = "Использовать эту папку для"; "Get Messages for Account" = "Получить новые сообщения"; +"Properties..." = "Properties..."; +"Delegation..." = "Delegation..."; /* Use This Folder menu */ "Sent Messages" = "Отправленные сообщения"; diff --git a/UI/MailerUI/Spanish.lproj/Localizable.strings b/UI/MailerUI/Spanish.lproj/Localizable.strings index 71eb60144..402a38f11 100644 --- a/UI/MailerUI/Spanish.lproj/Localizable.strings +++ b/UI/MailerUI/Spanish.lproj/Localizable.strings @@ -194,6 +194,8 @@ "Delete Folder" = "Borrar carpeta"; "Use This Folder For" = "Usar esta carpeta para"; "Get Messages for Account" = "Recibir mensajes para cuenta"; +"Properties..." = "Properties..."; +"Delegation..." = "Delegation..."; /* Use This Folder menu */ "Sent Messages" = "Enviar mensajes"; diff --git a/UI/MailerUI/Swedish.lproj/Localizable.strings b/UI/MailerUI/Swedish.lproj/Localizable.strings index 959e6e01d..871317ae2 100644 --- a/UI/MailerUI/Swedish.lproj/Localizable.strings +++ b/UI/MailerUI/Swedish.lproj/Localizable.strings @@ -194,6 +194,8 @@ "Delete Folder" = "Ta bort mapp"; "Use This Folder For" = "Använd mapp till"; "Get Messages for Account" = "Hämta nya meddelanden för konto"; +"Properties..." = "Properties..."; +"Delegation..." = "Delegation..."; /* Use This Folder menu */ "Sent Messages" = "Skickade meddelanden"; diff --git a/UI/MailerUI/UIxMailAccountActions.m b/UI/MailerUI/UIxMailAccountActions.m index c62275bcc..50e7a9f75 100644 --- a/UI/MailerUI/UIxMailAccountActions.m +++ b/UI/MailerUI/UIxMailAccountActions.m @@ -231,4 +231,41 @@ return [self redirectToLocation: url]; } +- (WOResponse *) _performDelegationAction: (SEL) action +{ + SOGoMailAccount *co; + WOResponse *response; + NSString *uid; + + co = [self clientObject]; + if ([[co nameInContainer] isEqualToString: @"0"]) + { + uid = [[context request] formValueForKey: @"uid"]; + if ([uid length] > 0) + { + [co performSelector: action + withObject: [NSArray arrayWithObject: uid]]; + response = [self responseWith204]; + } + else + response = [self responseWithStatus: 500 + andString: @"Missing 'uid' parameter."]; + } + else + response = [self responseWithStatus: 403 + andString: @"This action cannot be performed on secondary accounts."]; + + return response; +} + +- (WOResponse *) addDelegateAction +{ + return [self _performDelegationAction: @selector (addDelegates:)]; +} + +- (WOResponse *) removeDelegateAction +{ + return [self _performDelegationAction: @selector (removeDelegates:)]; +} + @end diff --git a/UI/MailerUI/UIxMailUserDelegationEditor.m b/UI/MailerUI/UIxMailUserDelegationEditor.m new file mode 100644 index 000000000..b0e8a8cb7 --- /dev/null +++ b/UI/MailerUI/UIxMailUserDelegationEditor.m @@ -0,0 +1,112 @@ +/* UIxMailUserDelegationEditor.m - this file is part of SOGo + * + * Copyright (C) 2010 Inverse inc. + * + * Author: Wolfgang Sourdeau + * + * 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 +#import + +#import +#import + +#import + +@interface UIxMailUserDelegationEditor : UIxComponent +{ + NSArray *delegates; + NSString *currentDelegate; +} + +- (NSArray *) delegates; +- (void) setCurrentDelegate: (NSString *) newCurrentDelegate; +- (NSString *) currentDelegate; + +@end + +@implementation UIxMailUserDelegationEditor + +- (id) init +{ + if ((self = [super init])) + { + delegates = nil; + currentDelegate = nil; + } + + return self; +} + +- (void) dealloc +{ + [delegates release]; + [currentDelegate release]; + [super dealloc]; +} + +- (NSArray *) delegates +{ + if (!delegates) + { + delegates = [[self clientObject] delegates]; + [delegates retain]; + } + + return delegates; +} + +- (void) setCurrentDelegate: (NSString *) newCurrentDelegate +{ + ASSIGN (currentDelegate, newCurrentDelegate); +} + +- (NSString *) currentDelegate +{ + return currentDelegate; +} + +- (NSString *) currentDelegateDisplayName +{ + SOGoUserManager *um; + NSString *s; + + um = [SOGoUserManager sharedUserManager]; + s = ([currentDelegate hasPrefix: @"@"] + ? [currentDelegate substringFromIndex: 1] + : currentDelegate); + + return [um getFullEmailForUID: s]; +} + +- (id) defaultAction +{ + id response; + SOGoMailAccount *co; + + co = [self clientObject]; + if ([[co nameInContainer] isEqualToString: @"0"]) + response = self; + else + response = [self responseWithStatus: 403 + andString: @"The list of account delegates cannot be modified on secondary accounts."]; + + return response; +} + +@end diff --git a/UI/MailerUI/Ukrainian.lproj/Localizable.strings b/UI/MailerUI/Ukrainian.lproj/Localizable.strings index 692afefbb..ce55aca24 100644 --- a/UI/MailerUI/Ukrainian.lproj/Localizable.strings +++ b/UI/MailerUI/Ukrainian.lproj/Localizable.strings @@ -194,6 +194,8 @@ "Delete Folder" = "Вилучити"; "Use This Folder For" = "Використати цю теку як"; "Get Messages for Account" = "Отримати нові повідомлення"; +"Properties..." = "Properties..."; +"Delegation..." = "Delegation..."; /* Use This Folder menu */ "Sent Messages" = "Відіслані"; diff --git a/UI/MailerUI/Welsh.lproj/Localizable.strings b/UI/MailerUI/Welsh.lproj/Localizable.strings index 40bb6bca6..54f23a92f 100644 --- a/UI/MailerUI/Welsh.lproj/Localizable.strings +++ b/UI/MailerUI/Welsh.lproj/Localizable.strings @@ -194,6 +194,8 @@ "Delete Folder" = "Dileu Ffolder"; "Use This Folder For" = "Defyddio'r Ffolder yma am"; "Get Messages for Account" = "Cael negeseuon ar gyfer Cyfrif"; +"Properties..." = "Properties..."; +"Delegation..." = "Delegation..."; /* Use This Folder menu */ "Sent Messages" = "Negeseuon anfonwyd"; diff --git a/UI/MailerUI/product.plist b/UI/MailerUI/product.plist index 6d6cc0380..4c91aa418 100644 --- a/UI/MailerUI/product.plist +++ b/UI/MailerUI/product.plist @@ -393,6 +393,20 @@ actionClass = "UIxMailFolderActions"; actionName = "createFolder"; }; + delegation = { + protectedBy = "View"; + pageName = "UIxMailUserDelegationEditor"; + }; + addDelegate = { + protectedBy = "View"; + actionClass = "UIxMailAccountActions"; + actionName = "addDelegate"; + }; + removeDelegate = { + protectedBy = "View"; + actionClass = "UIxMailAccountActions"; + actionName = "removeDelegate"; + }; }; }; diff --git a/UI/Templates/MailerUI/UIxMailMainFrame.wox b/UI/Templates/MailerUI/UIxMailMainFrame.wox index 70c0900fd..1026cbe89 100644 --- a/UI/Templates/MailerUI/UIxMailMainFrame.wox +++ b/UI/Templates/MailerUI/UIxMailMainFrame.wox @@ -38,9 +38,9 @@
  • -
  • +
  • diff --git a/UI/Templates/MailerUI/UIxMailUserDelegationEditor.wox b/UI/Templates/MailerUI/UIxMailUserDelegationEditor.wox new file mode 100644 index 000000000..355acb26b --- /dev/null +++ b/UI/Templates/MailerUI/UIxMailUserDelegationEditor.wox @@ -0,0 +1,35 @@ + + + + +
    +
    +
    +
    + + + + +
    +
      +
    • +
    • +
      +
    +
    +
    +
    +
    diff --git a/UI/WebServerResources/MailerUI.js b/UI/WebServerResources/MailerUI.js index d4eb68616..a62f5eb3f 100644 --- a/UI/WebServerResources/MailerUI.js +++ b/UI/WebServerResources/MailerUI.js @@ -2370,6 +2370,28 @@ function onMessageListMenuPrepareVisibility() { return true; } +function onAccountIconMenuPrepareVisibility() { + /* This methods disables or enables the "Delegation..." menu option on + mail accounts. */ + if (document.menuTarget) { + var mbx = document.menuTarget.getAttribute("dataname"); + if (mbx) { + var lis = this.getElementsByTagName("li"); + var li = lis[lis.length - 1]; + var parts = mbx.split("/"); + var acctNbr = parseInt(parts[1]); + if (acctNbr > 0) { + li.addClassName("disabled"); + } + else { + li.removeClassName("disabled"); + } + } + } + + return true; +} + function onFolderMenuPrepareVisibility() { /* This methods disables or enables the "Sharing" menu option on mailboxes. */ @@ -2485,9 +2507,15 @@ function onMenuArchiveFolder(event) { event.stop(); } +function onMenuAccountDelegation(event) { + var folderID = document.menuTarget.getAttribute("dataname"); + var urlstr = ApplicationBaseURL + folderID + "/delegation"; + openAclWindow(urlstr); +} + function getMenus() { var menus = { - accountIconMenu: [ null, null, onMenuCreateFolder, null, null, null ], + accountIconMenu: [ null, null, onMenuCreateFolder, null, null, onMenuAccountDelegation ], inboxIconMenu: [ null, null, null, "-", null, onMenuCreateFolder, onMenuExpungeFolder, onMenuArchiveFolder, "-", null, @@ -2555,6 +2583,11 @@ function getMenus() { labelMenu.prepareVisibility = onLabelMenuPrepareVisibility; } + var labelMenu = $("label-menu"); + if (labelMenu) { + labelMenu.prepareVisibility = onLabelMenuPrepareVisibility; + } + var markMenu = $("mark-menu"); if (markMenu) { markMenu.prepareVisibility = onMarkMenuPrepareVisibility; @@ -2568,6 +2601,11 @@ function getMenus() { } } + var accountIconMenu = $("accountIconMenu"); + if (accountIconMenu) { + accountIconMenu.prepareVisibility = onAccountIconMenuPrepareVisibility; + } + var folderMenus = [ "inboxIconMenu", "trashIconMenu", "mailboxIconMenu" ]; for (var i = 0; i < folderMenus.length; i++) { var menu = $(folderMenus[i]); diff --git a/UI/WebServerResources/UIxContactsUserFolders.js b/UI/WebServerResources/UIxContactsUserFolders.js index d4f3dbb03..a59f2e7fe 100644 --- a/UI/WebServerResources/UIxContactsUserFolders.js +++ b/UI/WebServerResources/UIxContactsUserFolders.js @@ -205,7 +205,7 @@ function onConfirmFolderSelection(event) { var email = (span.innerHTML .replace("<", "<", "g") .replace(">", ">", "g")); - folderName = email; + folderName = email.replace(/>,.*$/, ">", "g"); } else { var resource = $(topNode.selectedEntry).down("SPAN.nodeName"); @@ -214,8 +214,8 @@ function onConfirmFolderSelection(event) { .replace("<", "<", "g") .replace(">", ">", "g")); folderName = resource.innerHTML + ' (' + email + ')'; + folderName = folderName.replace(/>,.*(\))?$/, ">)$1", "g"); } - folderName = folderName.replace(/>,.*(\))?$/, ">)$1", "g"); var data = { folderName: folderName, folder: folder, window: window }; if (parent$(accessToSubscribedFolder(folder))) diff --git a/UI/WebServerResources/UIxMailUserDelegationEditor.css b/UI/WebServerResources/UIxMailUserDelegationEditor.css new file mode 100644 index 000000000..030fe115b --- /dev/null +++ b/UI/WebServerResources/UIxMailUserDelegationEditor.css @@ -0,0 +1,58 @@ +DIV.delegation +{ position: absolute; + top: 0px; + left: 0px; + right: 0px; + bottom: 0px; + padding: 0px; + border: 0px; + margin: 0px; } + +DIV.delegation LABEL +{ white-space: nowrap; + width: 100%; } + +#delegateRoles +{ position: absolute; + top: 5px; + left: 0px; + right: 0px; + bottom: 0px; } + +#delegateSelectorButtons +{ margin-left: 5px; + padding-bottom: 2px; } + +UL#delegateList +{ position: absolute; + left: 0px; + right: 0px; + top: 40px; + bottom: 0px; + padding: 0px; + margin: 0px; + white-space: nowrap; + overflow: auto; + border-bottom: 1px solid #fff; + border-right: 1px solid #fff; + border-top: 1px solid #909090; + border-left: 1px solid #909090; + background-color: #CCDDEC; + list-style-type: none; + list-style-image: none; } + +UL#delegateList LI +{ clear: both; + cursor: pointer; + height: 20px; + margin-left: 0px; + padding-left: 24px; + background-repeat: no-repeat; + background-position: 4px center; + background-image: url("abcard.png"); } + +DIV#delegateSelectorButtons A.smallToolbarButton +{ float: left; } + +SPAN.userFullName +{ margin-top: 2px; } diff --git a/UI/WebServerResources/UIxMailUserDelegationEditor.js b/UI/WebServerResources/UIxMailUserDelegationEditor.js new file mode 100644 index 000000000..f47754684 --- /dev/null +++ b/UI/WebServerResources/UIxMailUserDelegationEditor.js @@ -0,0 +1,111 @@ +var contactSelectorAction = 'delegation-contacts'; + +function addDelegate(delegateName, delegateID) { + var result = false; + if (!$(delegateID)) { + var ul = $("delegateList"); + var newNode = nodeForDelegate(delegateName, delegateID); + ul.appendChild(newNode); + + var url = window.location.href; + var elements = url.split("/"); + elements[elements.length-1] = ("addDelegate?uid=" + + delegateID); + triggerAjaxRequest(elements.join("/"), addDelegateCallback, newNode); + result = true; + } + return result; +} + +function addDelegateCallback(http) { + if (http.readyState == 4) { + if (!isHttpStatus204(http.status)) { + var node = http.callbackData; + node.parentNode.removeChild(node); + } + } +} + +function setEventsOnDelegateNode(node) { + node.observe("mousedown", listRowMouseDownHandler); + node.observe("selectstart", listRowMouseDownHandler); + node.observe("click", onRowClick); +} + +function nodeForDelegate(delegateName, delegateId) { + var node = createElement("li"); + node.id = delegateId; + + var span = createElement("span"); + span.addClassName("userFullName"); + span.appendChild(document.createTextNode(" " + delegateName)); + node.appendChild(span); + + setEventsOnDelegateNode(node); + + return node; +} + +function onDelegateAdd(event) { + openUserFolderSelector(null, "user"); + + preventDefault(event); +} + +function removeDelegateCallback(http) { + var node = http.callbackData; + + if (http.readyState == 4 + && isHttpStatus204(http.status)) + node.parentNode.removeChild(node); + else + log("error deleting delegate: " + node.getAttribute("id")); +} + +function onDelegateRemove(event) { + var delegateList = $("delegateList"); + var nodes = delegateList.getSelectedRows(); + + var url = window.location.href; + var elements = url.split("/"); + elements[elements.length-1] = "removeDelegate?uid="; + var baseURL = elements.join("/"); + + for (var i = 0; i < nodes.length; i++) { + var delegateId = nodes[i].id; + triggerAjaxRequest(baseURL + delegateId, removeDelegateCallback, + nodes[i]); + } + preventDefault(event); +} + +function subscribeToFolder(refreshCallback, refreshCallbackData) { + var result = true; + if (UserLogin != refreshCallbackData["folder"]) { + result = addDelegate(refreshCallbackData["folderName"], + refreshCallbackData["folder"]); + } + else + refreshCallbackData["window"].alert(_("You cannot subscribe to a folder that you own!")); + return result; +} + +function onDelegationLoadHandler() { + var ul = $("delegateList"); + var lis = ul.childNodesWithTag("li"); + for (var i = 0; i < lis.length; i++) + setEventsOnDelegateNode(lis[i]); + + var buttonArea = $("delegateSelectorButtons"); + if (buttonArea) { + var buttons = buttonArea.childNodesWithTag("a"); + $("addDelegate").stopObserving ("click"); + $("deleteDelegate").stopObserving ("click"); + $("addDelegate").observe("mousedown", onDelegateAdd); + $("deleteDelegate").observe("mousedown", onDelegateRemove); + } + + Event.observe(window, "unload", onDelegationCloseHandler); +} + +document.observe("dom:loaded", onDelegationLoadHandler);