Moves config request out to block of code that gets executed before the app is bootstrapped. This should allow us to redirect to the override url before the app begins to render, improving the UX.

This commit is contained in:
mabashian
2019-12-11 11:19:55 -05:00
committed by Graham Mainwaring
parent 25cc341888
commit bf6c16197c
3 changed files with 49 additions and 51 deletions

View File

@@ -375,13 +375,7 @@ angular
if (!/^\/(login|logout)/.test($location.path())) { if (!/^\/(login|logout)/.test($location.path())) {
$rootScope.preAuthUrl = $location.path(); $rootScope.preAuthUrl = $location.path();
} }
if ($location.path() !== '/login') { $location.path('/login');
if (global.$AnsibleConfig.login_redirect_override) {
window.location.replace(global.$AnsibleConfig.login_redirect_override);
} else {
$location.path('/login');
}
}
} else { } else {
var lastUser = $cookies.getObject('current_user'), var lastUser = $cookies.getObject('current_user'),
timestammp = Store('sessionTime'); timestammp = Store('sessionTime');

View File

@@ -15,7 +15,9 @@ function bootstrap (callback) {
angular.module('I18N').constant('LOCALE', locale); 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 })); 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. * Grabs the language off of navigator for browser compatibility.
* If the language isn't set, then it falls back to the DEFAULT_LOCALE. The * If the language isn't set, then it falls back to the DEFAULT_LOCALE. The

View File

@@ -1,57 +1,40 @@
export default export default
function LoadConfig($log, $rootScope, $http, Store) { function LoadConfig($rootScope, Store, ConfigSettings) {
return function() { return function() {
var configSettings = {}; var configSettings = {};
var configInit = function() { if(ConfigSettings.custom_logo) {
// Auto-resolving what used to be found when attempting to load local_setting.json configSettings.custom_logo = true;
if ($rootScope.loginConfig) { $rootScope.custom_logo = ConfigSettings.custom_logo;
$rootScope.loginConfig.resolve('config loaded'); } else {
} configSettings.custom_logo = false;
global.$AnsibleConfig = configSettings; }
Store('AnsibleConfig', global.$AnsibleConfig);
$rootScope.$emit('ConfigReady');
// Load new hardcoded settings from above if(ConfigSettings.custom_login_info) {
$rootScope.$emit('LoadConfig'); 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 if (ConfigSettings.login_redirect_override) {
$http({ configSettings.login_redirect_override = ConfigSettings.login_redirect_override;
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(data.custom_login_info) { // Auto-resolving what used to be found when attempting to load local_setting.json
configSettings.custom_login_info = data.custom_login_info; if ($rootScope.loginConfig) {
$rootScope.custom_login_info = data.custom_login_info; $rootScope.loginConfig.resolve('config loaded');
} else { }
configSettings.custom_login_info = false; global.$AnsibleConfig = configSettings;
} Store('AnsibleConfig', global.$AnsibleConfig);
$rootScope.$emit('ConfigReady');
if (data.login_redirect_override) { // Load new hardcoded settings from above
configSettings.login_redirect_override = data.login_redirect_override; $rootScope.$emit('LoadConfig');
}
configInit();
}).catch(({error}) => {
$log.debug(error);
configInit();
});
}; };
} }
LoadConfig.$inject = LoadConfig.$inject =
[ '$log', '$rootScope', '$http', [ '$rootScope', 'Store', 'ConfigSettings' ];
'Store'
];