diff --git a/awx/ui/static/js/controllers/Authentication.js b/awx/ui/static/js/controllers/Authentication.js index bc37741cd5..b4383dc4c1 100644 --- a/awx/ui/static/js/controllers/Authentication.js +++ b/awx/ui/static/js/controllers/Authentication.js @@ -10,7 +10,7 @@ 'use strict'; -function Authenticate($scope, $rootScope, $location, Authorization, ToggleClass, Alert) +function Authenticate($window, $scope, $rootScope, $location, Authorization, ToggleClass, Alert) { // Authorization is injected from AuthService found in services.js @@ -52,6 +52,14 @@ function Authenticate($scope, $rootScope, $location, Authorization, ToggleClass, Authorization.setToken(data.token); $scope.reset(); + // Force request to /organizations to query with the correct token -in the event a new user + // has logged in. + var today = new Date(); + today.setTime(today.getTime() + ($AnsibleConfig.session_timeout * 1000)); + $rootScope.token = token; + $rootScope.userLoggedIn = true; + $rootScope.token_expire = today.getTime(); + // Get all the profile/access info regarding the logged in user Authorization.getUser() .success(function(data, status, headers, config) { @@ -94,5 +102,5 @@ function Authenticate($scope, $rootScope, $location, Authorization, ToggleClass, } } -Authenticate.$inject = ['$scope', '$rootScope', '$location', 'Authorization', 'ToggleClass', 'Alert']; +Authenticate.$inject = ['$window', '$scope', '$rootScope', '$location', 'Authorization', 'ToggleClass', 'Alert']; diff --git a/awx/ui/static/js/controllers/Teams.js b/awx/ui/static/js/controllers/Teams.js index f3879a6206..e66b579680 100644 --- a/awx/ui/static/js/controllers/Teams.js +++ b/awx/ui/static/js/controllers/Teams.js @@ -142,8 +142,7 @@ function TeamsAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, TeamsAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'TeamForm', 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'GenerateList', - 'OrganizationList', 'SearchInit', 'PaginateInit', 'TeamLookUpOrganizationInit', 'GetBasePath', - 'LookUpInit' ]; + 'OrganizationList', 'SearchInit', 'PaginateInit', 'GetBasePath', 'LookUpInit' ]; function TeamsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, TeamForm, diff --git a/awx/ui/static/js/helpers/Groups.js b/awx/ui/static/js/helpers/Groups.js index c1de31f250..547c2ec5c6 100644 --- a/awx/ui/static/js/helpers/Groups.js +++ b/awx/ui/static/js/helpers/Groups.js @@ -285,9 +285,12 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', ' data[fld] = scope[fld]; } data['inventory'] = inventory_id; - - if (master['description'] != data['description']) { - refreshHosts = true; + + // Update hosts with new group name/description + if (master['description'] != data['description'] || + master['name'] != data['name']) { + scope.groupTitle = '

' + data['name'] + '

'; + scope.groupTitle += '

' + data['description'] + '

'; } Rest.setUrl(defaultUrl); diff --git a/awx/ui/static/js/helpers/refresh.js b/awx/ui/static/js/helpers/refresh.js index 3f832c5011..8c6fc0e4ff 100644 --- a/awx/ui/static/js/helpers/refresh.js +++ b/awx/ui/static/js/helpers/refresh.js @@ -22,7 +22,7 @@ angular.module('RefreshHelper', ['RestServices', 'Utilities']) var set = params.set; var iterator = params.iterator; var url = params.url; - + Rest.setUrl(url); Rest.get() .success( function(data, status, headers, config) { diff --git a/awx/ui/static/lib/ansible/authenticate.js b/awx/ui/static/lib/ansible/authenticate.js index 6723e2083d..d49046b30f 100644 --- a/awx/ui/static/lib/ansible/authenticate.js +++ b/awx/ui/static/lib/ansible/authenticate.js @@ -16,15 +16,18 @@ angular.module('AuthService', ['ngCookies']) $cookieStore.remove('token_expire'); $cookieStore.put('token', token); $cookieStore.put('token_expire', today.getTime()); + $rootScope.token = token; $rootScope.userLoggedIn = true; + $rootScope.token_expire = today.getTime(); }, isTokenValid: function() { // check if token exists and is not expired var response = false; - if ( $cookieStore.get('token') && $cookieStore.get('token_expire') ) { - var token = $cookieStore.get('token'); - var exp = new Date($cookieStore.get('token_expire')); + var token = ($rootScope.token) ? $rootScope.token : $cookieStore.get('token'); + var token_expire = ($rootScope.token_expire) ? $rootScope.token_expire : $cookieStore.get('token_expire'); + if (token && token_expire) { + var exp = new Date(token_expire); var today = new Date(); if (today < exp) { this.setToken(token); //push expiration into the future while user is active @@ -37,8 +40,9 @@ angular.module('AuthService', ['ngCookies']) didSessionExpire: function() { // use only to test why user was sent to login page. var response = false; - if ($cookieStore.get('token_expire')) { - var exp = new Date($cookieStore.get('token_expire')); + var token_expire = ($rootScope.token_expire) ? $rootScope.token_expire : $cookieStore.get('token_expire'); + if (token_expire) { + var exp = new Date(token_expire); var today = new Date(); if (exp < today) { response = true; @@ -49,7 +53,7 @@ angular.module('AuthService', ['ngCookies']) getToken: function() { if ( this.isTokenValid() ) { - return $cookieStore.get('token'); + return ($rootScope.token) ? $rootScope.token : $cookieStore.get('token'); } else { return null; @@ -68,6 +72,8 @@ angular.module('AuthService', ['ngCookies']) $cookieStore.remove('token_expire'); $cookieStore.remove('current_user'); $rootScope.userLoggedIn = false; + $rootScope.token = null; + $rootScope.token_expire = new Date(1970, 0, 1, 0, 0, 0, 0); }, getLicense: function() { diff --git a/awx/ui/static/lib/ansible/rest-services.js b/awx/ui/static/lib/ansible/rest-services.js index 3fa0bb91cd..03676c0b30 100644 --- a/awx/ui/static/lib/ansible/rest-services.js +++ b/awx/ui/static/lib/ansible/rest-services.js @@ -12,7 +12,11 @@ angular.module('RestServices',['ngCookies','AuthService']) this.url = url; }, - auth: { 'Authorization': 'Token ' + Authorization.getToken() }, + //auth: { 'Authorization': 'Token ' + Authorization.getToken() }, + auth: function() { + var token = Authorization.getToken(); + return { 'Authorization': 'Token ' + token } + }, pReplace: function() { //in our url, replace :xx params with a value, assuming @@ -33,20 +37,20 @@ angular.module('RestServices',['ngCookies','AuthService']) this.pReplace(); return $http({method: 'GET', url: this.url, - headers: this.auth, + headers: this.auth(), params: this.params }); }, post: function(data) { return $http({method: 'POST', url: this.url, - headers: this.auth, + headers: this.auth(), data: data }); }, put: function(data) { return $http({method: 'PUT', url: this.url, - headers: this.auth, + headers: this.auth(), data: data }); }, @@ -54,7 +58,7 @@ angular.module('RestServices',['ngCookies','AuthService']) var url = this.url; return $http({method: 'DELETE', url: url, - headers: this.auth, + headers: this.auth(), data: data}); } } diff --git a/awx/ui/static/lib/ansible/utilities.js b/awx/ui/static/lib/ansible/utilities.js index b0f51145be..039acaf321 100644 --- a/awx/ui/static/lib/ansible/utilities.js +++ b/awx/ui/static/lib/ansible/utilities.js @@ -11,7 +11,7 @@ angular.module('Utilities',[]) return function(id) { var element = document.getElementById(id); var scope = angular.element(element).scope(); - scope.$destroy(); + scope.$destroy(); } })