From 113622c05ece11478eb28647b37fc1a667dc4882 Mon Sep 17 00:00:00 2001 From: mabashian Date: Thu, 5 Sep 2019 09:10:59 -0400 Subject: [PATCH] Moves initial system settings rest call out to resolve --- awx/api/views/root.py | 2 +- .../client/src/license/license.controller.js | 23 +++++++++++++------ awx/ui/client/src/license/license.route.js | 20 +++++++++++++++- .../spec/license/license.controller-test.js | 15 +++++++++--- 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/awx/api/views/root.py b/awx/api/views/root.py index b45ccc0071..91f6b62149 100644 --- a/awx/api/views/root.py +++ b/awx/api/views/root.py @@ -201,7 +201,7 @@ class ApiV2SubscriptionView(APIView): getattr(getattr(exc, 'response', None), 'status_code', None) == 401 ): msg = _("The provided credentials are invalid (HTTP 401).") - if isinstance(exc, ValueError) and exc.args: + if isinstance(exc, (ValueError, OSError)) and exc.args: msg = exc.args[0] logger.exception(smart_text(u"Invalid license submitted."), extra=dict(actor=request.user.username)) diff --git a/awx/ui/client/src/license/license.controller.js b/awx/ui/client/src/license/license.controller.js index 3b1f3496ce..c0f9012edf 100644 --- a/awx/ui/client/src/license/license.controller.js +++ b/awx/ui/client/src/license/license.controller.js @@ -7,10 +7,10 @@ import {N_} from "../i18n"; export default - ['Wait', '$state', '$scope', '$rootScope', 'ProcessErrors', 'CheckLicense', 'moment', 'Rest', '$timeout', - '$window', 'ConfigService', 'pendoService', 'insightsEnablementService', 'i18n', 'config', 'GetBasePath', - function(Wait, $state, $scope, $rootScope, ProcessErrors, CheckLicense, moment, Rest, $timeout, - $window, ConfigService, pendoService, insightsEnablementService, i18n, config, GetBasePath) { + ['Wait', '$state', '$scope', '$rootScope', 'ProcessErrors', 'CheckLicense', 'moment', '$timeout', 'Rest', + '$window', 'ConfigService', 'pendoService', 'insightsEnablementService', 'i18n', 'config', 'rhCreds', 'GetBasePath', + function(Wait, $state, $scope, $rootScope, ProcessErrors, CheckLicense, moment, $timeout, Rest, + $window, ConfigService, pendoService, insightsEnablementService, i18n, config, rhCreds, GetBasePath) { const calcDaysRemaining = function(seconds) { // calculate the number of days remaining on the license @@ -61,9 +61,18 @@ export default }; $scope.rhCreds = {}; + + if (rhCreds.REDHAT_USERNAME && rhCreds.REDHAT_USERNAME !== "") { + $scope.rhCreds.username = rhCreds.REDHAT_USERNAME; + } + + if (rhCreds.REDHAT_PASSWORD && rhCreds.REDHAT_PASSWORD !== "") { + $scope.rhCreds.password = rhCreds.REDHAT_PASSWORD; + $scope.showPlaceholderPassword = true; + } }; - const init = (config) => { + const updateRHCreds = (config) => { Rest.setUrl(`${GetBasePath('settings')}system/`); Rest.get() .then(({data}) => { @@ -82,7 +91,7 @@ export default }); }; - init(config); + initVars(config); $scope.getKey = function(event) { // Mimic HTML5 spec, show filename @@ -210,7 +219,7 @@ export default licenseMissing: false }); } else { - init(config); + updateRHCreds(config); $scope.success = true; $rootScope.licenseMissing = false; // for animation purposes diff --git a/awx/ui/client/src/license/license.route.js b/awx/ui/client/src/license/license.route.js index 430da0174e..4c1251ca6a 100644 --- a/awx/ui/client/src/license/license.route.js +++ b/awx/ui/client/src/license/license.route.js @@ -42,6 +42,24 @@ export default { return config; }); } - ] + ], + rhCreds: ['Rest', 'GetBasePath', function(Rest, GetBasePath) { + Rest.setUrl(`${GetBasePath('settings')}system/`); + return Rest.get() + .then(({data}) => { + const rhCreds = {}; + if (data.REDHAT_USERNAME && data.REDHAT_USERNAME !== "") { + rhCreds.REDHAT_USERNAME = data.REDHAT_USERNAME; + } + + if (data.REDHAT_PASSWORD && data.REDHAT_PASSWORD !== "") { + rhCreds.REDHAT_PASSWORD = data.REDHAT_PASSWORD; + } + + return rhCreds; + }).catch(() => { + return {}; + }); + }] }, }; diff --git a/awx/ui/test/spec/license/license.controller-test.js b/awx/ui/test/spec/license/license.controller-test.js index eb013776b4..660e918e79 100644 --- a/awx/ui/test/spec/license/license.controller-test.js +++ b/awx/ui/test/spec/license/license.controller-test.js @@ -6,7 +6,8 @@ describe('Controller: LicenseController', () => { LicenseController, ConfigService, ProcessErrors, - config; + config, + rhCreds; beforeEach(angular.mock.module('awApp')); beforeEach(angular.mock.module('license', ($provide) => { @@ -22,23 +23,31 @@ describe('Controller: LicenseController', () => { version: '3.1.0-devel' }; + rhCreds = { + password: '$encrypted$', + username: 'foo', + } + ProcessErrors = jasmine.createSpy('ProcessErrors'); $provide.value('ConfigService', ConfigService); $provide.value('ProcessErrors', ProcessErrors); $provide.value('config', config); + $provide.value('rhCreds', rhCreds); })); - beforeEach(angular.mock.inject( ($rootScope, $controller, _ConfigService_, _ProcessErrors_, _config_) => { + beforeEach(angular.mock.inject( ($rootScope, $controller, _ConfigService_, _ProcessErrors_, _config_, _rhCreds_) => { scope = $rootScope.$new(); ConfigService = _ConfigService_; ProcessErrors = _ProcessErrors_; config = _config_; + rhCreds = _rhCreds_; LicenseController = $controller('licenseController', { $scope: scope, ConfigService: ConfigService, ProcessErrors: ProcessErrors, - config: config + config: config, + rhCreds: rhCreds }); }));