From 9f917d62b50c5d66f77cf0b2ce146502a6506f1e Mon Sep 17 00:00:00 2001 From: Nabil Adouani Date: Fri, 6 Nov 2020 16:43:24 +0100 Subject: [PATCH] #1623 Add the API key section in the user's settings page --- .../app/scripts/controllers/SettingsCtrl.js | 40 +++++++++++++++++++ .../app/views/partials/personal-settings.html | 30 ++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/frontend/app/scripts/controllers/SettingsCtrl.js b/frontend/app/scripts/controllers/SettingsCtrl.js index c84b6ef61d..470670ef98 100644 --- a/frontend/app/scripts/controllers/SettingsCtrl.js +++ b/frontend/app/scripts/controllers/SettingsCtrl.js @@ -24,6 +24,8 @@ passwordConfirm: '' }; + $scope.keyData = {}; + $scope.mfaData = { enabled: $scope.currentUser.hasMFA, secret: null, @@ -32,6 +34,7 @@ }; $scope.canChangePass = appConfig.config.capabilities.indexOf('changePassword') !== -1; + $scope.canChangeKey = appConfig.config.capabilities.indexOf('authByKey') !== -1; $scope.canChangeMfa = appConfig.config.capabilities.indexOf('mfa') !== -1; @@ -95,6 +98,43 @@ } }; + $scope.createKey = function(){ + var modalInstance = ModalSrv.confirm( + 'Renew API Key', + 'Are you sure you want to renew your API Key?', { + flavor: 'danger', + okText: 'Yes, renew it' + } + ); + + modalInstance.result + .then(function() { + UserSrv.setKey($scope.currentUser.login); + }) + .then(function() { + delete $scope.keyData.key; + NotificationSrv.success('API key has been successfully renewed.'); + }) + .catch(function(err) { + if (!_.isString(err)) { + NotificationSrv.error('SettingsCtrl', err.data, err.status); + } + }); + }; + + $scope.getKey = function() { + UserSrv.getKey($scope.currentUser.login) + .then(function(key) { + $scope.keyData.key = key; + }); + }; + + $scope.copyKey = function() { + clipboard.copyText($scope.keyData.key); + delete $scope.keyData.key; + NotificationSrv.success('API key has been successfully copied to clipboard.'); + }; + $scope.copySecret = function(secret) { clipboard.copyText(secret); NotificationSrv.success('MFA Secret has been successfully copied to clipboard.'); diff --git a/frontend/app/views/partials/personal-settings.html b/frontend/app/views/partials/personal-settings.html index 8adb4364c6..525cdf7c94 100644 --- a/frontend/app/views/partials/personal-settings.html +++ b/frontend/app/views/partials/personal-settings.html @@ -136,6 +136,36 @@

+ +
+
+
+

API Key

+
+
+
+

You don't have any API key.

+

Please contact your organization's administrator.

+
+
+

You have an API key defined. You can renew it if needed.

+
+ + Renew + Reveal + + + + + +
+
+
+
+
+