From 05d59df68bb163193320a75a3a629c7f64188fe7 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Fri, 3 Jul 2015 20:40:06 -0400 Subject: [PATCH] (feat) added mailbox delegation support --- SoObjects/SOGo/SOGoUser.m | 27 +++- UI/MailerUI/UIxMailUserDelegationEditor.m | 126 +++++++++--------- UI/Templates/MailerUI/UIxMailMainFrame.wox | 6 + .../MailerUI/UIxMailUserDelegationEditor.wox | 86 +++++++----- .../js/Mailer/Account.service.js | 44 ++++++ .../js/Mailer/MailboxesController.js | 70 ++++++++++ 6 files changed, 261 insertions(+), 98 deletions(-) diff --git a/SoObjects/SOGo/SOGoUser.m b/SoObjects/SOGo/SOGoUser.m index 263c6e7e5..35883ddcf 100644 --- a/SoObjects/SOGo/SOGoUser.m +++ b/SoObjects/SOGo/SOGoUser.m @@ -627,10 +627,10 @@ { NSString *fullName, *replyTo, *imapLogin, *imapServer, *cImapServer, *signature, *encryption, *scheme, *action, *query, *customEmail, *defaultEmail, *sieveServer; - NSMutableDictionary *mailAccount, *identity, *mailboxes, *receipts; + NSMutableDictionary *mailAccount, *identity, *mailboxes, *receipts, *mailSettings; NSNumber *port; NSMutableArray *identities; - NSArray *mails; + NSArray *mails, *delegates; NSURL *url, *cUrl; unsigned int count, max, default_identity; NSInteger defaultPort; @@ -824,6 +824,29 @@ [mailAccounts addObject: mailAccount]; [mailAccount release]; + + /* delegates */ + mailSettings = [[self userSettings] objectForKey: @"Mail"]; + delegates = [mailSettings objectForKey: @"DelegateTo"]; + if (!delegates) + delegates = [NSArray array]; + else + { + NSMutableArray *allDelegates; + SOGoUser *delegate; + + allDelegates = [NSMutableArray array]; + for (count = 0; count < [delegates count]; count++) + { + delegate = [SOGoUser userWithLogin: [delegates objectAtIndex: count]]; + [allDelegates addObject: [NSDictionary dictionaryWithObjectsAndKeys: [delegates objectAtIndex: count], @"uid", + [delegate cn], @"cn", + [delegate systemEmail], @"c_email", nil]]; + } + + delegates = allDelegates; + } + [mailAccount setObject: delegates forKey: @"delegates"]; } - (NSArray *) mailAccounts diff --git a/UI/MailerUI/UIxMailUserDelegationEditor.m b/UI/MailerUI/UIxMailUserDelegationEditor.m index b0e8a8cb7..d79e6293c 100644 --- a/UI/MailerUI/UIxMailUserDelegationEditor.m +++ b/UI/MailerUI/UIxMailUserDelegationEditor.m @@ -1,8 +1,6 @@ /* UIxMailUserDelegationEditor.m - this file is part of SOGo * - * Copyright (C) 2010 Inverse inc. - * - * Author: Wolfgang Sourdeau + * Copyright (C) 2010-2015 Inverse inc. * * 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 @@ -29,84 +27,84 @@ #import @interface UIxMailUserDelegationEditor : UIxComponent -{ - NSArray *delegates; - NSString *currentDelegate; -} +// { +// NSArray *delegates; +// NSString *currentDelegate; +// } -- (NSArray *) delegates; -- (void) setCurrentDelegate: (NSString *) newCurrentDelegate; -- (NSString *) currentDelegate; +// - (NSArray *) delegates; +// - (void) setCurrentDelegate: (NSString *) newCurrentDelegate; +// - (NSString *) currentDelegate; @end @implementation UIxMailUserDelegationEditor -- (id) init -{ - if ((self = [super init])) - { - delegates = nil; - currentDelegate = nil; - } +// - (id) init +// { +// if ((self = [super init])) +// { +// delegates = nil; +// currentDelegate = nil; +// } - return self; -} +// return self; +// } -- (void) dealloc -{ - [delegates release]; - [currentDelegate release]; - [super dealloc]; -} +// - (void) dealloc +// { +// [delegates release]; +// [currentDelegate release]; +// [super dealloc]; +// } -- (NSArray *) delegates -{ - if (!delegates) - { - delegates = [[self clientObject] delegates]; - [delegates retain]; - } +// - (NSArray *) delegates +// { +// if (!delegates) +// { +// delegates = [[self clientObject] delegates]; +// [delegates retain]; +// } - return delegates; -} +// return delegates; +// } -- (void) setCurrentDelegate: (NSString *) newCurrentDelegate -{ - ASSIGN (currentDelegate, newCurrentDelegate); -} +// - (void) setCurrentDelegate: (NSString *) newCurrentDelegate +// { +// ASSIGN (currentDelegate, newCurrentDelegate); +// } -- (NSString *) currentDelegate -{ - return currentDelegate; -} +// - (NSString *) currentDelegate +// { +// return currentDelegate; +// } -- (NSString *) currentDelegateDisplayName -{ - SOGoUserManager *um; - NSString *s; +// - (NSString *) currentDelegateDisplayName +// { +// SOGoUserManager *um; +// NSString *s; - um = [SOGoUserManager sharedUserManager]; - s = ([currentDelegate hasPrefix: @"@"] - ? [currentDelegate substringFromIndex: 1] - : currentDelegate); +// um = [SOGoUserManager sharedUserManager]; +// s = ([currentDelegate hasPrefix: @"@"] +// ? [currentDelegate substringFromIndex: 1] +// : currentDelegate); - return [um getFullEmailForUID: s]; -} +// return [um getFullEmailForUID: s]; +// } -- (id) defaultAction -{ - id response; - SOGoMailAccount *co; +// - (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."]; +// 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; -} +// return response; +// } @end diff --git a/UI/Templates/MailerUI/UIxMailMainFrame.wox b/UI/Templates/MailerUI/UIxMailMainFrame.wox index 4477c21a4..9d76016a8 100644 --- a/UI/Templates/MailerUI/UIxMailMainFrame.wox +++ b/UI/Templates/MailerUI/UIxMailMainFrame.wox @@ -245,6 +245,12 @@ ng-click="newFolder(account)"> + + + diff --git a/UI/Templates/MailerUI/UIxMailUserDelegationEditor.wox b/UI/Templates/MailerUI/UIxMailUserDelegationEditor.wox index 355acb26b..d9e12af20 100644 --- a/UI/Templates/MailerUI/UIxMailUserDelegationEditor.wox +++ b/UI/Templates/MailerUI/UIxMailUserDelegationEditor.wox @@ -1,35 +1,57 @@ - - + + + + +

- {{delegate.account.name}}

+ + +
+ +
+
+
+
{{user.cn}}
+
{{user.c_email}}
+
+ + + +
+
+
+
-
-
-
-
- - - - -
-
    -
  • -
  • -
    -
-
+
+ + + {{user.cn}} {{user.c_email}} + + +
- - + + + diff --git a/UI/WebServerResources/js/Mailer/Account.service.js b/UI/WebServerResources/js/Mailer/Account.service.js index a3d412a43..514129290 100644 --- a/UI/WebServerResources/js/Mailer/Account.service.js +++ b/UI/WebServerResources/js/Mailer/Account.service.js @@ -220,4 +220,48 @@ return deferred.promise; }; + /** + * @function $addDelegate + * @memberof Account.prototype + * @param {Object} user - a User object with minimal set of attributes (uid, isGroup, cn, c_email) + * @desc Remove a user from the account's delegates + * @see {@link User.$filter} + */ + Account.prototype.$addDelegate = function(user) { + var _this = this, + deferred = Account.$q.defer(), + param = {uid: user.uid}; + if (!user.uid || _.indexOf(_.pluck(this.delegates, 'uid'), user.uid) > -1) { + // No UID specified or user already in delegates + deferred.resolve(); + } + else { + Account.$$resource.fetch(this.id.toString(), 'addDelegate', param).then(function() { + _this.delegates.push(user); + deferred.resolve(_this.users); + }, function(data, status) { + deferred.reject(l('An error occured please try again.')); + }); + } + return deferred.promise; + }; + + /** + * @function $removeDelegate + * @memberof Account.prototype + * @param {Object} user - a User object with minimal set of attributes (uid, isGroup, cn, c_email) + * @desc Remove a user from the account's delegates + * @return a promise of the server call to remove the user from the account's delegates + */ + Account.prototype.$removeDelegate = function(uid) { + var _this = this, + param = {uid: uid}; + return Account.$$resource.fetch(this.id.toString(), 'removeDelegate', param).then(function() { + var i = _.indexOf(_.pluck(_this.delegates, 'uid'), uid); + if (i >= 0) { + _this.delegates.splice(i, 1); + } + }); + }; + })(); diff --git a/UI/WebServerResources/js/Mailer/MailboxesController.js b/UI/WebServerResources/js/Mailer/MailboxesController.js index d15dbf2dd..a3e77eaeb 100644 --- a/UI/WebServerResources/js/Mailer/MailboxesController.js +++ b/UI/WebServerResources/js/Mailer/MailboxesController.js @@ -24,6 +24,76 @@ }); }); }; + $scope.delegate = function(account) { + $mdDialog.show({ + templateUrl: account.id + '/delegation', // UI/Templates/MailerUI/UIxMailUserDelegation.wox + controller: MailboxDelegationController, + controllerAs: 'delegate', + clickOutsideToClose: true, + escapeToClose: true, + locals: { + User: User, + account: account, + $q: $q + } + }); + + /** + * @ngInject + */ + MailboxDelegationController.$inject = ['$scope', '$mdDialog', 'User', 'account', '$q']; + function MailboxDelegationController($scope, $mdDialog, User, account, $q) { + var vm = this; + + vm.users = account.delegates; + vm.account = account; + vm.selectedUser = null; + vm.userToAdd = ''; + vm.searchText = ''; + vm.userFilter = userFilter; + vm.closeModal = closeModal; + vm.removeUser = removeUser; + vm.addUser = addUser; + vm.selectUser = selectUser; + + function userFilter($query) { + //return User.$filter($query, folder.$acl.users); + return User.$filter($query, account.delegates); + } + + function closeModal() { + $mdDialog.hide(); + } + + function removeUser(user) { + account.$removeDelegate(user.uid).then(function() { + if (user.uid == vm.selectedUser.uid) { + vm.selectedUser = null; + } + }, function(data, status) { + Dialog.alert(l('Warning'), l('An error occured please try again.')) + }); + } + + function addUser(data) { + if (data) { + account.$addDelegate(data).then(function() { + vm.userToAdd = ''; + vm.searchText = ''; + }, function(error) { + Dialog.alert(l('Warning'), error); + }); + } + } + + function selectUser(user) { + // Check if it is a different user + if (vm.selectedUser != user) { + vm.selectedUser = user; + } + } + } + }; $scope.editFolder = function(folder) { $scope.editMode = folder.path; focus('mailboxName_' + folder.path);