From 30aa1d74d896d418e748f4fdb20701185f7272df Mon Sep 17 00:00:00 2001 From: chouseknecht Date: Wed, 31 Jul 2013 17:14:29 -0400 Subject: [PATCH] AC-325 We now check before each call to the API that the token is not empty. If empty, return false. The false will throw a javascript error to the console, but not noticeable, unless you're watching the console. Stops API login dialog box from appearing. User just sees login dialog with correct message. --- awx/ui/static/css/ansible-ui.css | 1 - awx/ui/static/lib/ansible/rest-services.js | 67 ++++++++++++++-------- 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/awx/ui/static/css/ansible-ui.css b/awx/ui/static/css/ansible-ui.css index e5e8b9cf63..64acfb83c0 100644 --- a/awx/ui/static/css/ansible-ui.css +++ b/awx/ui/static/css/ansible-ui.css @@ -12,7 +12,6 @@ } body { - //color: #171717; color: #171717; padding-top: 60px; } diff --git a/awx/ui/static/lib/ansible/rest-services.js b/awx/ui/static/lib/ansible/rest-services.js index 9a8d570699..8aa7fcf854 100644 --- a/awx/ui/static/lib/ansible/rest-services.js +++ b/awx/ui/static/lib/ansible/rest-services.js @@ -11,13 +11,7 @@ angular.module('RestServices',['ngCookies','AuthService']) setUrl: function (url) { this.url = url; }, - - //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 //we can find it in user supplied params. @@ -35,30 +29,53 @@ angular.module('RestServices',['ngCookies','AuthService']) args = (args) ? args : {}; this.params = (args.params) ? args.params : null; this.pReplace(); - return $http({method: 'GET', - url: this.url, - headers: this.auth(), - params: this.params - }); + var token = Authorization.getToken(); + if (token) { + return $http({method: 'GET', + url: this.url, + headers: { 'Authorization': 'Token ' + token }, + params: this.params + }); + } + else { + return false; + } }, post: function(data) { - return $http({method: 'POST', - url: this.url, - headers: this.auth(), - data: data }); + var token = Authorization.getToken(); + if (token) { + return $http({method: 'POST', + url: this.url, + headers: { 'Authorization': 'Token ' + token }, + data: data }); + } + else { + return false; + } }, put: function(data) { - return $http({method: 'PUT', - url: this.url, - headers: this.auth(), - data: data }); - + var token = Authorization.getToken(); + if (token) { + return $http({method: 'PUT', + url: this.url, + headers: { 'Authorization': 'Token ' + token }, + data: data }); + } + else { + return false; + } }, destroy: function(data) { - return $http({method: 'DELETE', - url: this.url, - headers: this.auth(), - data: data}); + var token = Authorization.getToken(); + if (token) { + return $http({method: 'DELETE', + url: this.url, + headers: { 'Authorization': 'Token ' + token }, + data: data}); + } + else { + return false; + } } } }]);