diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index e6902339e2..071db41067 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -375,13 +375,7 @@ angular if (!/^\/(login|logout)/.test($location.path())) { $rootScope.preAuthUrl = $location.path(); } - if ($location.path() !== '/login') { - if (global.$AnsibleConfig.login_redirect_override) { - window.location.replace(global.$AnsibleConfig.login_redirect_override); - } else { - $location.path('/login'); - } - } + $location.path('/login'); } else { var lastUser = $cookies.getObject('current_user'), timestammp = Store('sessionTime'); diff --git a/awx/ui/client/src/app.start.js b/awx/ui/client/src/app.start.js index 44f8113567..61c8ac5bb4 100644 --- a/awx/ui/client/src/app.start.js +++ b/awx/ui/client/src/app.start.js @@ -15,7 +15,9 @@ function bootstrap (callback) { angular.module('I18N').constant('LOCALE', locale); } - angular.element(document).ready(() => callback()); + fetchConfig((config) => { + angular.element(document).ready(() => callback()); + }); }); } @@ -49,6 +51,25 @@ function fetchLocaleStrings (callback) { request.fail(() => callback({ code: DEFAULT_LOCALE })); } +function fetchConfig (callback) { + const request = $.ajax(`/api`); + + request.done(res => { + angular.module('awApp').constant('ConfigSettings', res); + if (res.login_redirect_override) { + if (!document.cookie.split(';').filter((item) => item.includes('userLoggedIn=true')).length && !window.location.href.includes('/#/login')) { + window.location.replace(res.login_redirect_override); + } else { + callback(); + } + } else { + callback(); + } + }); + + request.fail(() => callback()); +} + /** * Grabs the language off of navigator for browser compatibility. * If the language isn't set, then it falls back to the DEFAULT_LOCALE. The diff --git a/awx/ui/client/src/shared/load-config/load-config.factory.js b/awx/ui/client/src/shared/load-config/load-config.factory.js index 38a2d8b3b7..c1adfeee8f 100644 --- a/awx/ui/client/src/shared/load-config/load-config.factory.js +++ b/awx/ui/client/src/shared/load-config/load-config.factory.js @@ -1,57 +1,40 @@ export default - function LoadConfig($log, $rootScope, $http, Store) { + function LoadConfig($rootScope, Store, ConfigSettings) { return function() { var configSettings = {}; - var configInit = function() { - // Auto-resolving what used to be found when attempting to load local_setting.json - if ($rootScope.loginConfig) { - $rootScope.loginConfig.resolve('config loaded'); - } - global.$AnsibleConfig = configSettings; - Store('AnsibleConfig', global.$AnsibleConfig); - $rootScope.$emit('ConfigReady'); + if(ConfigSettings.custom_logo) { + configSettings.custom_logo = true; + $rootScope.custom_logo = ConfigSettings.custom_logo; + } else { + configSettings.custom_logo = false; + } - // Load new hardcoded settings from above - $rootScope.$emit('LoadConfig'); - }; + if(ConfigSettings.custom_login_info) { + configSettings.custom_login_info = ConfigSettings.custom_login_info; + $rootScope.custom_login_info = ConfigSettings.custom_login_info; + } else { + configSettings.custom_login_info = false; + } - // Retrieve the custom logo information - update configSettings from above - $http({ - method: 'GET', - url: '/api/', - }) - .then(function({data}) { - if(data.custom_logo) { - configSettings.custom_logo = true; - $rootScope.custom_logo = data.custom_logo; - } else { - configSettings.custom_logo = false; - } + if (ConfigSettings.login_redirect_override) { + configSettings.login_redirect_override = ConfigSettings.login_redirect_override; + } - if(data.custom_login_info) { - configSettings.custom_login_info = data.custom_login_info; - $rootScope.custom_login_info = data.custom_login_info; - } else { - configSettings.custom_login_info = false; - } + // Auto-resolving what used to be found when attempting to load local_setting.json + if ($rootScope.loginConfig) { + $rootScope.loginConfig.resolve('config loaded'); + } + global.$AnsibleConfig = configSettings; + Store('AnsibleConfig', global.$AnsibleConfig); + $rootScope.$emit('ConfigReady'); - if (data.login_redirect_override) { - configSettings.login_redirect_override = data.login_redirect_override; - } - - configInit(); - - }).catch(({error}) => { - $log.debug(error); - configInit(); - }); + // Load new hardcoded settings from above + $rootScope.$emit('LoadConfig'); }; } LoadConfig.$inject = - [ '$log', '$rootScope', '$http', - 'Store' - ]; + [ '$rootScope', 'Store', 'ConfigSettings' ];