From 5388585ef113d146abf92cec75226c770261d123 Mon Sep 17 00:00:00 2001 From: baron_l Date: Wed, 29 May 2019 02:39:30 +0200 Subject: [PATCH] fix(app): extensions status retrieval (#2910) * fix(rbac): extensions status retrieval not interrupted anymore * refactor(extensions): change endpoint used to retrieve extension activation status --- app/portainer/services/api/extensionService.js | 5 +++-- app/portainer/views/auth/authController.js | 16 +++++++++++----- .../views/extensions/extensionsController.js | 3 ++- .../views/init/admin/initAdminController.js | 8 +++++--- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/app/portainer/services/api/extensionService.js b/app/portainer/services/api/extensionService.js index f21ac3141..b53a1375b 100644 --- a/app/portainer/services/api/extensionService.js +++ b/app/portainer/services/api/extensionService.js @@ -60,8 +60,9 @@ angular.module('portainer.app') if (extensionId === service.EXTENSIONS.RBAC) { return StateManager.getExtension(extensionId) ? true : false; } else { - const extension = await Extension.get({id: extensionId}).$promise; - return extension.Enabled; + const extensions = await service.extensions(false); + const extension = _.find(extensions, (ext) => ext.Id === extensionId); + return extension ? extension.Enabled : false; } }; diff --git a/app/portainer/views/auth/authController.js b/app/portainer/views/auth/authController.js index b8e39375b..517cc03fd 100644 --- a/app/portainer/views/auth/authController.js +++ b/app/portainer/views/auth/authController.js @@ -14,9 +14,9 @@ function($q, $scope, $state, $stateParams, $sanitize, Authentication, UserServic OAuthProvider: '' }; - function retrieveAndSaveEnabledExtensions() { + async function retrieveAndSaveEnabledExtensions() { try { - ExtensionService.retrieveAndSaveEnabledExtensions(); + await ExtensionService.retrieveAndSaveEnabledExtensions(); } catch (err) { Notifications.error('Failure', err, 'Unable to retrieve enabled extensions'); } @@ -28,7 +28,9 @@ function($q, $scope, $state, $stateParams, $sanitize, Authentication, UserServic Authentication.login(username, password) .then(function success() { - retrieveAndSaveEnabledExtensions(); + return retrieveAndSaveEnabledExtensions(); + }) + .then(function () { checkForEndpoints(); }) .catch(function error() { @@ -40,7 +42,9 @@ function($q, $scope, $state, $stateParams, $sanitize, Authentication, UserServic return $q.reject(); }) .then(function success() { - retrieveAndSaveEnabledExtensions(); + return retrieveAndSaveEnabledExtensions(); + }) + .then(function() { $state.go('portainer.updatePassword'); }) .catch(function error() { @@ -141,7 +145,9 @@ function($q, $scope, $state, $stateParams, $sanitize, Authentication, UserServic function oAuthLogin(code) { return Authentication.OAuthLogin(code) .then(function success() { - retrieveAndSaveEnabledExtensions(); + return retrieveAndSaveEnabledExtensions(); + }) + .then(function() { URLHelper.cleanParameters(); }) .catch(function error() { diff --git a/app/portainer/views/extensions/extensionsController.js b/app/portainer/views/extensions/extensionsController.js index 1bddc01b2..b25fc3b57 100644 --- a/app/portainer/views/extensions/extensionsController.js +++ b/app/portainer/views/extensions/extensionsController.js @@ -30,7 +30,8 @@ angular.module('portainer.app') $scope.state.actionInProgress = true; ExtensionService.enable(license) .then(function onSuccess() { - ExtensionService.retrieveAndSaveEnabledExtensions(); + return ExtensionService.retrieveAndSaveEnabledExtensions(); + }).then(function () { Notifications.success('Extension successfully enabled'); $state.reload(); }) diff --git a/app/portainer/views/init/admin/initAdminController.js b/app/portainer/views/init/admin/initAdminController.js index c12563847..8384b3cd6 100644 --- a/app/portainer/views/init/admin/initAdminController.js +++ b/app/portainer/views/init/admin/initAdminController.js @@ -14,9 +14,9 @@ function ($scope, $state, Notifications, Authentication, StateManager, UserServi actionInProgress: false }; - function retrieveAndSaveEnabledExtensions() { + async function retrieveAndSaveEnabledExtensions() { try { - ExtensionService.retrieveAndSaveEnabledExtensions(); + await ExtensionService.retrieveAndSaveEnabledExtensions(); } catch (err) { Notifications.error('Failure', err, 'Unable to retrieve enabled extensions'); } @@ -32,7 +32,9 @@ function ($scope, $state, Notifications, Authentication, StateManager, UserServi return Authentication.login(username, password); }) .then(function success() { - retrieveAndSaveEnabledExtensions(); + return retrieveAndSaveEnabledExtensions(); + }) + .then(function () { return EndpointService.endpoints(); }) .then(function success(data) {