From 566fe55d714124a1e1581c27ff4d5f33e1c65ca4 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Thu, 16 Jul 2020 17:30:10 -0400 Subject: [PATCH] fix(preferences(js)): set account id before importing certificate Fixes #5084 --- UI/MailerUI/UIxMailAccountActions.m | 16 ++++++++++++++-- .../js/Preferences/AccountDialogController.js | 2 +- .../js/Preferences/PreferencesController.js | 9 ++++++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/UI/MailerUI/UIxMailAccountActions.m b/UI/MailerUI/UIxMailAccountActions.m index b3337d9e0..c97944eb6 100644 --- a/UI/MailerUI/UIxMailAccountActions.m +++ b/UI/MailerUI/UIxMailAccountActions.m @@ -1,6 +1,6 @@ /* UIxMailAccountActions.m - this file is part of SOGo * - * Copyright (C) 2007-2017 Inverse inc. + * Copyright (C) 2007-2020 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 @@ -306,6 +306,7 @@ if (password && pkcs12) { NSData *certificate; + NSDictionary *description; certificate = [pkcs12 convertPKCS12ToPEMUsingPassword: password]; @@ -314,7 +315,18 @@ [[self clientObject] setCertificate: certificate]; - response = [self responseWith204]; + description = [certificate certificateDescription]; + if (description) + { + response = [self responseWithStatus: 200 andJSONRepresentation: description]; + } + else + { + description = [NSDictionary + dictionaryWithObject: [self labelForKey: @"Error reading the certificate. Please install a new certificate."] + forKey: @"message"]; + response = [self responseWithStatus: 500 andJSONRepresentation: description]; + } } return response; diff --git a/UI/WebServerResources/js/Preferences/AccountDialogController.js b/UI/WebServerResources/js/Preferences/AccountDialogController.js index df5a99967..a5df047c1 100644 --- a/UI/WebServerResources/js/Preferences/AccountDialogController.js +++ b/UI/WebServerResources/js/Preferences/AccountDialogController.js @@ -49,7 +49,7 @@ onSuccessItem: function(item, response, status, headers) { this.clearQueue(); $timeout(function() { - _.assign(vm.account, {security: {hasCertificate: true}}); + _.assign(vm.account, {security: {hasCertificate: true}, $$certificate: response}); }); _loadCertificate(); }, diff --git a/UI/WebServerResources/js/Preferences/PreferencesController.js b/UI/WebServerResources/js/Preferences/PreferencesController.js index d2183fa17..114556a3f 100644 --- a/UI/WebServerResources/js/Preferences/PreferencesController.js +++ b/UI/WebServerResources/js/Preferences/PreferencesController.js @@ -105,7 +105,9 @@ this.addMailAccount = function(ev, form) { var account, index; + index = this.preferences.defaults.AuxiliaryMailAccounts.length; account = new Account({ + id: index, isNew: true, name: "", identities: [ @@ -121,7 +123,6 @@ receiptAnyAction: "ignore" } }); - index = this.preferences.defaults.AuxiliaryMailAccounts.length; $mdDialog.show({ controller: 'AccountDialogController', @@ -147,8 +148,10 @@ }; this.editMailAccount = function(event, index, form) { - var data = _.cloneDeep(this.preferences.defaults.AuxiliaryMailAccounts[index]); - var account = new Account(data); + var data, account; + + data = _.assign({ id: index }, _.cloneDeep(this.preferences.defaults.AuxiliaryMailAccounts[index])); + account = new Account(data); $mdDialog.show({ controller: 'AccountDialogController', controllerAs: '$AccountDialogController',