From c516a17ef931489d20d5837ec2ece755a634a6c9 Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Thu, 2 Jun 2016 16:12:15 -0700 Subject: [PATCH] Removing old code and cleaning up for PR --- .../src/license/checkLicense2.factory.js | 201 ------------------ .../authentication.service.js | 21 -- .../login/loginModal/loginModal.controller.js | 3 - .../client/src/main-menu/main-menu.block.less | 3 +- 4 files changed, 2 insertions(+), 226 deletions(-) delete mode 100644 awx/ui/client/src/license/checkLicense2.factory.js diff --git a/awx/ui/client/src/license/checkLicense2.factory.js b/awx/ui/client/src/license/checkLicense2.factory.js deleted file mode 100644 index 03de29441c..0000000000 --- a/awx/ui/client/src/license/checkLicense2.factory.js +++ /dev/null @@ -1,201 +0,0 @@ -/************************************************* - * Copyright (c) 2015 Ansible, Inc. - * - * All Rights Reserved - *************************************************/ - - /** - * @ngdoc function - * @name helpers.function:License - * @description Routines for checking and reporting license status - * CheckLicense.test() is called in app.js, in line 532, which is when the license is checked. The license information is - * stored in local storage using 'Store()'. - * - * - * - * -*/ - -// import '../forms'; - -export default - ['$q', '$rootScope', '$compile', 'CreateDialog', 'Store', - 'GenerateForm', 'TextareaResize', 'ToJSON', 'GetBasePath', - 'Rest', 'ProcessErrors', 'Alert', 'IsAdmin', '$state', 'pendoService', - 'Authorization', 'Wait', - function($q, $rootScope, $compile, CreateDialog, Store, GenerateForm, - TextareaResize, ToJSON, GetBasePath, Rest, ProcessErrors, Alert, IsAdmin, $state, - pendoService, Authorization, Wait) { - return { - getRemainingDays: function(time_remaining) { - // assumes time_remaining will be in seconds - var tr = parseInt(time_remaining, 10); - return Math.floor(tr / 86400); - }, - - shouldNotify: function(license) { - if (license && typeof license === 'object' && Object.keys(license).length > 0) { - // we have a license object - if (!license.valid_key) { - // missing valid key - return true; - } - else if (license.free_instances <= 0) { - // host count exceeded - return true; - } - else if (this.getRemainingDays(license.time_remaining) < 15) { - // below 15 days remaining on license - return true; - } - return false; - } else { - // missing license object - return true; - } - }, - - isAdmin: function() { - return IsAdmin(); - }, - post: function(license, eula){ - var defaultUrl = GetBasePath('config'); - Rest.setUrl(defaultUrl); - var data = license; - data.eula_accepted = eula; - return Rest.post(JSON.stringify(data)) - .success(function(res){ - return res; - }) - .error(function(res, status){ - ProcessErrors($rootScope, res, status, null, {hdr: 'Error!', - msg: 'Call to '+ defaultUrl + ' failed. Return status: '+ status}); - }); - }, - postLicense: function(license_key, in_scope) { - var url = GetBasePath('config'), - self = this, - json_data, scope; - - scope = (in_scope) ? in_scope : self.scope; - - json_data = ToJSON('json', license_key); - json_data.eula_accepted = scope.eula_agreement; - if (typeof json_data === 'object' && Object.keys(json_data).length > 0) { - Rest.setUrl(url); - Rest.post(json_data) - .success(function (response) { - response.license_info = response; - Alert('License Accepted', 'The Ansible Tower license was updated. To review or update the license, choose View License from the Setup menu.','alert-info'); - $rootScope.features = undefined; - - Authorization.getLicense() - .success(function (data) { - Authorization.setLicense(data); - pendoService.issuePendoIdentity(); - Wait("stop"); - $state.go('home'); - }) - .error(function () { - Wait('stop'); - Alert('Error', 'Failed to access license information. GET returned status: ' + status, 'alert-danger', - $state.go('signOut')); - }); - - - - - }) - .catch(function (response) { - scope.license_json_api_error = "A valid license key in JSON format is required"; - ProcessErrors(scope, response.data, response.status, null, { hdr: 'Error!', - msg: 'Failed to update license. POST returned: ' + response.status - }); - }); - } else { - scope.license_json_api_error = "A valid license key in JSON format is required"; - } - }, - - test: function() { - var license = Store('license'), - self = this; - // scope; - - var getLicense = function() { - var deferred = $q.defer(); - - if (license === null) { - Rest.setUrl(GetBasePath('config')); - return Rest.get() - .then(function (data) { - license = data.data.license_info; - deferred.resolve(); - return deferred.promise; - }, function () { - deferred.resolve(); - return deferred.promise; - }); - } else { - deferred.resolve(license); - return deferred.promise; - } - }; - - var promise = getLicense(); - promise.then(function() { - // self.scope = $rootScope.$new(); - // scope = self.scope; - - if (license && typeof license === 'object' && Object.keys(license).length > 0) { - // if (license.tested) { - // return true; - // } - license.tested = true; - Store('license',license); //update with tested flag - } - - // Don't do anything when the license is valid - if (!self.shouldNotify(license)) { - $rootScope.licenseMissing = false; - return true; // if the license is valid it would exit 'test' here, otherwise it moves on to making the modal for the license - } - $rootScope.licenseMissing = true; - $state.go('license'); - }); - }, - // Checks current license validity - // Intended to for runtime or pre-state checks - // Returns false if invalid - valid: function(license) { - if (!license.valid_key){ - return false; - } - else if (license.free_instances <= 0){ - return false; - } - // notify if less than 15 days remaining - else if (license.time_remaining / 1000 / 60 / 60 / 24 > 15){ - return false; - } - return true; - }, - GetLicense: function() { - // Retrieve license detail - var //self = this, - // scope = (inScope) ? inScope : self.scope, - url = GetBasePath('config'); - Rest.setUrl(url); - return Rest.get() - .success(function(res){ - $rootScope.license_tested = true; - return res; - }) - .error(function (data, status) { - ProcessErrors($rootScope, data, status, null, { hdr: 'Error!', - msg: 'Failed to retrieve license. GET status: ' + status - }); - }); - } - }; - }]; diff --git a/awx/ui/client/src/login/authenticationServices/authentication.service.js b/awx/ui/client/src/login/authenticationServices/authentication.service.js index f85a36efe3..f39830c691 100644 --- a/awx/ui/client/src/login/authenticationServices/authentication.service.js +++ b/awx/ui/client/src/login/authenticationServices/authentication.service.js @@ -112,27 +112,6 @@ export default } }, - getLicense: function () { - //check in here first to see if license is already obtained, if we do have it, then rootScope.license - return $http({ - method: 'GET', - url: GetBasePath('config'), - headers: { - 'Authorization': 'Token ' + this.getToken() - } - }); - }, - - setLicense: function (data) { - var license = data.license_info; - license.analytics_status = data.analytics_status; - license.version = data.version; - license.ansible_version = data.ansible_version; - license.tested = false; - - $rootScope.features = license.features; - }, - licenseTested: function () { var license, result; if ($rootScope.license_tested !== undefined) { diff --git a/awx/ui/client/src/login/loginModal/loginModal.controller.js b/awx/ui/client/src/login/loginModal/loginModal.controller.js index 3122e5fcb6..f853da8516 100644 --- a/awx/ui/client/src/login/loginModal/loginModal.controller.js +++ b/awx/ui/client/src/login/loginModal/loginModal.controller.js @@ -113,9 +113,6 @@ export default ['$log', '$cookieStore', '$compile', '$window', '$rootScope', scope.removeAuthorizationGetLicense(); } scope.removeAuthorizationGetLicense = scope.$on('AuthorizationGetLicense', function() { - // Authorization.getLicense() - // .success(function (data) { - // Authorization.setLicense(data); ConfigService.getConfig().then(function(){ CheckLicense.test(); pendoService.issuePendoIdentity(); diff --git a/awx/ui/client/src/main-menu/main-menu.block.less b/awx/ui/client/src/main-menu/main-menu.block.less index 5b362626f7..94c2647127 100644 --- a/awx/ui/client/src/main-menu/main-menu.block.less +++ b/awx/ui/client/src/main-menu/main-menu.block.less @@ -204,7 +204,8 @@ flex: initial!important; padding-top:0px; } - + // gonna come back to this for hte hover when license is missing and + // screen size is less than 900px -- JT 6/2 // .MainMenu-item--licenseMissing:hover{ // padding-top:5px; // border-bottom: 5px solid @menu-link-btm-hov;