Dashboard: Ignore changes to dashboard when the user session expires (#30897)

When the user session expires, and the 401 triggers a page reload to get the user to the login page, ChangeTracker will interfer. By setting the user as logged out in the context when the session is timed out, we can ignore the changes in ChangeTracker.
This commit is contained in:
Oscar Kilhed
2021-02-04 15:29:38 +01:00
committed by GitHub
parent 0ddf1c8ee0
commit e2ecb70051
3 changed files with 14 additions and 0 deletions

View File

@@ -39,6 +39,7 @@ export class BackendSrv implements BackendService {
appEvents: appEvents,
contextSrv: contextSrv,
logout: () => {
contextSrv.setLoggedOut();
window.location.reload();
},
};

View File

@@ -49,6 +49,14 @@ export class ContextSrv {
this.minRefreshInterval = config.minRefreshInterval;
}
/**
* Indicate the user has been logged out
*/
setLoggedOut() {
this.user.isSignedIn = false;
this.isSignedIn = false;
}
hasRole(role: string) {
return this.user.orgRole === role;
}

View File

@@ -93,6 +93,11 @@ export class ChangeTracker {
return true;
}
//Ignore changes if the user has been signed out
if (!this.contextSrv.isSignedIn) {
return true;
}
const meta = this.current.meta;
return !meta.canSave || meta.fromScript || meta.fromFile;
}