diff --git a/awx/ui/static/js/app.js b/awx/ui/static/js/app.js index 0444a68a4b..e2d2c30702 100644 --- a/awx/ui/static/js/app.js +++ b/awx/ui/static/js/app.js @@ -511,7 +511,7 @@ angular.module('Tower', [ if ($rootScope.current_user === undefined || $rootScope.current_user === null) { Authorization.restoreUserInfo(); //user must have hit browser refresh } - CheckLicense(); + CheckLicense.test(); } activateTab(); diff --git a/awx/ui/static/js/forms/LicenseUpdate.js b/awx/ui/static/js/forms/LicenseUpdate.js new file mode 100644 index 0000000000..064eb1cdb6 --- /dev/null +++ b/awx/ui/static/js/forms/LicenseUpdate.js @@ -0,0 +1,37 @@ +/********************************************* + * Copyright (c) 2014 AnsibleWorks, Inc. + * + * License.js + * Form definition for Organization model + * + * + */ +angular.module('LicenseUpdateFormDefinition', []) + .value('LicenseUpdateForm', { + + name: 'license', + well: false, + + fields: { + license_json: { + label: 'License Key:', + type: 'textarea', + addRequired: true, + editRequird: true, + rows: 10, + 'default': '---' + } + }, + + buttons: { + form_submit: { + label: "Submit", + "class": "pull-right btn-primary", + ngClick: "submitLicenseKey()", + ngDisabled: true + } + }, + + related: { } + + }); //LicenseUpdateForm diff --git a/awx/ui/static/js/helpers/Access.js b/awx/ui/static/js/helpers/Access.js index 878f636eb7..a6f20107dc 100644 --- a/awx/ui/static/js/helpers/Access.js +++ b/awx/ui/static/js/helpers/Access.js @@ -9,7 +9,8 @@ 'use strict'; -angular.module('AccessHelper', ['RestServices', 'Utilities', 'ngCookies']) +angular.module('AccessHelper', ['RestServices', 'Utilities', 'ngCookies', 'LicenseUpdateFormDefinition', 'FormGenerator', 'ParseHelper', 'ModalDialog', 'VariablesHelper']) + .factory('CheckAccess', ['$rootScope', 'Alert', 'Rest', 'GetBasePath', 'ProcessErrors', function ($rootScope, Alert, Rest, GetBasePath, ProcessErrors) { return function (params) { @@ -48,6 +49,199 @@ angular.module('AccessHelper', ['RestServices', 'Utilities', 'ngCookies']) } ]) +.factory('CheckLicense', ['$rootScope', '$compile', 'CreateDialog', 'Store', 'LicenseUpdateForm', 'GenerateForm', 'TextareaResize', 'ToJSON', 'GetBasePath', 'Rest', 'ProcessErrors', 'Alert', +function($rootScope, $compile, CreateDialog, Store, LicenseUpdateForm, GenerateForm, TextareaResize, ToJSON, GetBasePath, Rest, ProcessErrors, Alert) { + 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; + } + }, + + getHTML: function(license) { + var title, html, result = {}; + if (license && typeof license === 'object' && Object.keys(license).length > 0 && license.valid_key !== undefined) { + // we have a license + if (!license.valid_key) { + title = "Invalid License"; + html = "
The Ansible Tower license is invalid. Please visit " + + "http://ansible.com/license to obtain a valid license key. " + + "Copy and paste the key in the field below and click the Submit button.
Thank you for using Ansible Tower. The Ansible Tower license " + + "has expired. You will no longer be able to run playbooks after " + this.getRemainingDays(license.grace_period_remaining) + " days
" + + "Please visit ansible.com/license to purchse a valid license. " + + "Copy and paste the new license key in the field below and click the Submit button.
Thank you for using Ansible Tower. The Ansible Tower license " + + "has expired, and the 30 day grace period has been exceeded. To continue using Tower to run playbooks and adding managed hosts a " + + "valid license key is required.
Please visit http://ansible.com/license to " + + "purchse a license. Copy and paste the new license key in the field below and click the Submit button.
"; + } + } + else if (this.getRemainingDays(license.time_remaining) < 15) { + html = "Thank you for using Ansible Tower. The Ansible Tower license " + + "has " + this.getRemainingDays(license.time_remaining) + " remaining.
" + + "Extend your Ansible Tower license by visiting http://ansible.com/license. " + + "Copy and paste the new license key in the field below and click the Submit button.
The Ansible Tower license has reached capacity for the number of " + + "managed hosts allowed. No additional hosts can be added.
To extend the Ansible Tower license please visit " + + "ansible.com/license. " + + "Copy and paste the new license key in the field below and click the Submit button.
"; + } + } else { + // No license + title = "License Required"; + html = "Thank you for trying Ansible Tower. A FREE trial license is available for various infrastructure sizes, as well as free unlimited use for up to ten nodes.
" + + "
Visit ansible.com/license to obtain a free license key. Copy and paste the key in the field below and " + + "click the Submit button.