7525-devToTest #2542

Merged
alexm merged 231 commits from 7525-devToTest into test 2024-06-04 07:59:34 +00:00
1 changed files with 54 additions and 15 deletions
Showing only changes of commit 5bbf5887b9 - Show all commits

View File

@ -7,10 +7,12 @@ import UserError from 'core/lib/user-error';
* @property {Boolean} loggedIn Whether the user is currently logged * @property {Boolean} loggedIn Whether the user is currently logged
*/ */
export default class Auth { export default class Auth {
constructor($http, $q, $state, $transitions, $window, vnToken, vnModules, aclService) { constructor($http, $q, vnApp, $translate, $state, $transitions, $window, vnToken, vnModules, aclService) {
Object.assign(this, { Object.assign(this, {
$http, $http,
$q, $q,
vnApp,
$translate,
$state, $state,
$transitions, $transitions,
$window, $window,
@ -39,9 +41,31 @@ export default class Auth {
}; };
if (this.vnToken.token) { if (this.vnToken.token) {
return this.loadAcls() const maxRetries = 5;
let retryCount = 0;
const retryDelay = 2000; // Milisegundos (1 segundo)
const loadAclsWithRetry = () => {
return this.loadAcls(maxRetries)
.then(() => true) .then(() => true)
.catch(redirectToLogin); .catch(error => {
retryCount++;
if (retryCount < maxRetries) {
return new Promise(resolve => {
setTimeout(() => {
this.vnApp.showMessage(this.$translate.instant('Loading...'));
resolve(loadAclsWithRetry(maxRetries - retryCount));
}, retryDelay);
});
} else {
// Retry limit reached, redirect to login
return redirectToLogin();
}
});
};
// Start loading ACLs with retry
return loadAclsWithRetry();
} else } else
return redirectToLogin(); return redirectToLogin();
}); });
@ -113,18 +137,33 @@ export default class Auth {
return promise; return promise;
} }
loadAcls() { loadAcls(maxRetries = 1) {
const attemptLoad = retryCount => {
return this.aclService.load() return this.aclService.load()
.then(() => { .then(() => {
this.loggedIn = true; this.loggedIn = true;
this.vnModules.reset(); this.vnModules.reset();
}) })
.catch(err => { .catch(err => {
if (retryCount >= maxRetries) {
this.vnToken.unset(); this.vnToken.unset();
throw err; throw err;
} else {
// Retry after delay
return new Promise((resolve, reject) => {
reject(new Error('Error al cargar los ACLs'));
}); });
} }
});
};
// Start loading with retry
return attemptLoad(1);
} }
Auth.$inject = ['$http', '$q', '$state', '$transitions', '$window', 'vnToken', 'vnModules', 'aclService']; }
Auth.$inject = [
'$http', '$q', 'vnApp', '$translate', '$state',
'$transitions', '$window', 'vnToken', 'vnModules',
'aclService'];
ngModule.service('vnAuth', Auth); ngModule.service('vnAuth', Auth);