From fe29f5e0c992c1e060ea97cd77757d564f2425d0 Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Mon, 5 Dec 2016 19:46:36 -0800 Subject: [PATCH 1/3] Redirect to license page if no license This was broken due to the upgrade to UI-Router v.1.0.0-beta.3. I also tracked down the $stateChangeStart function in app.js that when missing some time in 3.1 development --- awx/ui/client/src/app.js | 54 +++++++++++++++++-- .../src/license/checkLicense.factory.js | 4 +- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index d903776765..ec6639ce7b 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -385,6 +385,11 @@ var tower = angular.module('Tower', [ }; $rootScope.$stateParams = $stateParams; + $state.defaultErrorHandler(function() { + // Do not log transitionTo errors + // $log.debug("transitionTo error: " + error ); + }); + I18NInit(); $stateExtender.addState({ name: 'dashboard', @@ -681,9 +686,52 @@ var tower = angular.module('Tower', [ $rootScope.crumbCache = []; - // $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState) { - // SocketService.subscribe(toState, toParams); - // }); + $rootScope.$on("$stateChangeStart", function (event, next) { + // Remove any lingering intervals + // except on jobDetails.* states + var jobDetailStates = [ + 'jobDetail', + 'jobDetail.host-summary', + 'jobDetail.host-event.details', + 'jobDetail.host-event.json', + 'jobDetail.host-events', + 'jobDetail.host-event.stdout' + ]; + if ($rootScope.jobDetailInterval && !_.includes(jobDetailStates, next.name) ) { + window.clearInterval($rootScope.jobDetailInterval); + } + if ($rootScope.jobStdOutInterval && !_.includes(jobDetailStates, next.name) ) { + window.clearInterval($rootScope.jobStdOutInterval); + } + + // On each navigation request, check that the user is logged in + if (!/^\/(login|logout)/.test($location.path())) { + // capture most recent URL, excluding login/logout + $rootScope.lastPath = $location.path(); + $rootScope.enteredPath = $location.path(); + $cookieStore.put('lastPath', $location.path()); + } + + if (Authorization.isUserLoggedIn() === false) { + if (next.name !== "signIn") { + $state.go('signIn'); + } + } else if ($rootScope && $rootScope.sessionTimer && $rootScope.sessionTimer.isExpired()) { + // gets here on timeout + if (next.name !== "signIn") { + $state.go('signIn'); + } + } else { + if ($rootScope.current_user === undefined || $rootScope.current_user === null) { + Authorization.restoreUserInfo(); //user must have hit browser refresh + } + if (next && (next.name !== "signIn" && next.name !== "signOut" && next.name !== "license")) { + // if not headed to /login or /logout, then check the license + CheckLicense.test(event); + } + } + activateTab(); + }); $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState) { diff --git a/awx/ui/client/src/license/checkLicense.factory.js b/awx/ui/client/src/license/checkLicense.factory.js index d68358cd29..c104ce091c 100644 --- a/awx/ui/client/src/license/checkLicense.factory.js +++ b/awx/ui/client/src/license/checkLicense.factory.js @@ -42,10 +42,10 @@ export default if(license === null || !$rootScope.license_tested){ if(this.valid(license) === false) { $rootScope.licenseMissing = true; + $state.go('license'); if(event){ event.preventDefault(); } - $state.go('license'); } else { $rootScope.licenseMissing = false; @@ -53,7 +53,7 @@ export default } else if(this.valid(license) === false) { $rootScope.licenseMissing = true; - $state.transitionTo('license'); + $state.go('license'); if(event){ event.preventDefault(); } From a9c1969aa058cc6a7e79f2acd379c6d0bcd36dbc Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Tue, 6 Dec 2016 09:13:19 -0800 Subject: [PATCH 2/3] adding useful comment to $state.defaultErrorHandler --- awx/ui/client/src/app.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index ec6639ce7b..9009cc0779 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -386,8 +386,9 @@ var tower = angular.module('Tower', [ $rootScope.$stateParams = $stateParams; $state.defaultErrorHandler(function() { - // Do not log transitionTo errors - // $log.debug("transitionTo error: " + error ); + // Do not log transitionTo errors. This function, + // left empty, will prevent errors being displayed on the + // JS console that are caused by ui-router transitions. }); I18NInit(); From 8dbaea59b4e8489667258a9f381d638d68ef1838 Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Tue, 6 Dec 2016 09:29:33 -0800 Subject: [PATCH 3/3] Using $log for debugging transitionTo errors --- awx/ui/client/src/app.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index 9009cc0779..3d23bdcf8f 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -385,10 +385,8 @@ var tower = angular.module('Tower', [ }; $rootScope.$stateParams = $stateParams; - $state.defaultErrorHandler(function() { - // Do not log transitionTo errors. This function, - // left empty, will prevent errors being displayed on the - // JS console that are caused by ui-router transitions. + $state.defaultErrorHandler(function(error) { + $log.debug(`$state.defaultErrorHandler: ${error}`); }); I18NInit();