fix(salix): refs #7272 #7272 Bug when acl not loaded
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Javier Segarra 2024-04-25 13:15:05 +02:00
parent b8fdd7d726
commit 5bbf5887b9
1 changed files with 54 additions and 15 deletions

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);