7565-testToMaster #2567

Merged
alexm merged 250 commits from 7565-testToMaster into master 2024-06-11 06:31:18 +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;
.then(() => true) let retryCount = 0;
.catch(redirectToLogin); const retryDelay = 2000; // Milisegundos (1 segundo)
const loadAclsWithRetry = () => {
return this.loadAcls(maxRetries)
.then(() => true)
.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) {
return this.aclService.load() const attemptLoad = retryCount => {
.then(() => { return this.aclService.load()
this.loggedIn = true; .then(() => {
this.vnModules.reset(); this.loggedIn = true;
}) this.vnModules.reset();
.catch(err => { })
this.vnToken.unset(); .catch(err => {
throw err; if (retryCount >= maxRetries) {
}); this.vnToken.unset();
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);