From 214b72bb8dd8c30c3033a8853731cf44cc407485 Mon Sep 17 00:00:00 2001 From: gconsidine Date: Tue, 1 Aug 2017 13:36:05 -0400 Subject: [PATCH] Use existing config service for license_type checks --- awx/ui/client/lib/models/Config.js | 5 +++++ awx/ui/client/src/license/license.route.js | 7 +++++++ awx/ui/client/src/setup-menu/setup-menu.partial.html | 2 +- awx/ui/client/src/setup-menu/setup.route.js | 5 ++++- awx/ui/client/src/shared/stateExtender.provider.js | 1 + 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/awx/ui/client/lib/models/Config.js b/awx/ui/client/lib/models/Config.js index 777a9f2bd4..17dd1f8901 100644 --- a/awx/ui/client/lib/models/Config.js +++ b/awx/ui/client/lib/models/Config.js @@ -11,12 +11,17 @@ function getTruncatedVersion () { return version; } + +function isOpen () { + return this.get('license_info.license_type') === 'open'; +} function ConfigModel (method, resource, graft) { BaseModel.call(this, 'config', { cache: true }); this.Constructor = ConfigModel; this.getTruncatedVersion = getTruncatedVersion; + this.isOpen = isOpen; return this.create(method, resource, graft); } diff --git a/awx/ui/client/src/license/license.route.js b/awx/ui/client/src/license/license.route.js index cd09b28ad5..629bab4093 100644 --- a/awx/ui/client/src/license/license.route.js +++ b/awx/ui/client/src/license/license.route.js @@ -6,6 +6,7 @@ import {templateUrl} from '../shared/template-url/template-url.factory'; import { N_ } from '../i18n'; +import _ from 'lodash'; export default { name: 'license', @@ -17,6 +18,12 @@ export default { parent: 'setup', label: N_('LICENSE') }, + onEnter: ['$state', 'ConfigService', (state, configService) => { + return configService.getConfig() + .then(config => { + return _.get(config, 'license_info.license_type') === 'open' && state.go('setup'); + }); + }], resolve: { features: ['CheckLicense', '$rootScope', function(CheckLicense, $rootScope) { diff --git a/awx/ui/client/src/setup-menu/setup-menu.partial.html b/awx/ui/client/src/setup-menu/setup-menu.partial.html index 85118a9c9e..d5179afa6f 100644 --- a/awx/ui/client/src/setup-menu/setup-menu.partial.html +++ b/awx/ui/client/src/setup-menu/setup-menu.partial.html @@ -68,7 +68,7 @@ View information about this version of Ansible {{BRAND_NAME}}.

- +

View Your License

View and edit your license information. diff --git a/awx/ui/client/src/setup-menu/setup.route.js b/awx/ui/client/src/setup-menu/setup.route.js index 1483ac4436..51b613e32e 100644 --- a/awx/ui/client/src/setup-menu/setup.route.js +++ b/awx/ui/client/src/setup-menu/setup.route.js @@ -1,5 +1,6 @@ import {templateUrl} from '../shared/template-url/template-url.factory'; import { N_ } from '../i18n'; +import _ from 'lodash'; export default { name: 'setup', @@ -8,10 +9,12 @@ export default { label: N_("SETTINGS") }, templateUrl: templateUrl('setup-menu/setup-menu'), - controller: function(orgAdmin, $scope){ + controller: function(config, orgAdmin, $scope){ + $scope.isOpen = _.get(config, 'license_info.license_type') === 'open'; $scope.orgAdmin = orgAdmin; }, resolve: { + config: ['ConfigService', config => config.getConfig()], orgAdmin: ['$rootScope', 'ProcessErrors', 'Rest', 'GetBasePath', function($rootScope, ProcessErrors, Rest, GetBasePath){ diff --git a/awx/ui/client/src/shared/stateExtender.provider.js b/awx/ui/client/src/shared/stateExtender.provider.js index f9534c2665..60edc3f083 100644 --- a/awx/ui/client/src/shared/stateExtender.provider.js +++ b/awx/ui/client/src/shared/stateExtender.provider.js @@ -58,6 +58,7 @@ export default function($stateProvider) { controllerAs: state.controllerAs, views: state.views, parent: state.parent, + redirectTo: state.redirectTo, // new in uiRouter 1.0 lazyLoad: state.lazyLoad, };