mirror of
https://github.com/ansible/awx.git
synced 2024-11-01 16:51:11 +03:00
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:
parent
25cc341888
commit
bf6c16197c
@ -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');
|
||||
|
@ -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
|
||||
|
@ -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' ];
|
||||
|
Loading…
Reference in New Issue
Block a user