From e2ecb7005163ddb42b9bdedbc98784644b31c073 Mon Sep 17 00:00:00 2001 From: Oscar Kilhed Date: Thu, 4 Feb 2021 15:29:38 +0100 Subject: [PATCH] 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. --- public/app/core/services/backend_srv.ts | 1 + public/app/core/services/context_srv.ts | 8 ++++++++ public/app/features/dashboard/services/ChangeTracker.ts | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/public/app/core/services/backend_srv.ts b/public/app/core/services/backend_srv.ts index 4bda41d328e..ac61f6bd3f6 100644 --- a/public/app/core/services/backend_srv.ts +++ b/public/app/core/services/backend_srv.ts @@ -39,6 +39,7 @@ export class BackendSrv implements BackendService { appEvents: appEvents, contextSrv: contextSrv, logout: () => { + contextSrv.setLoggedOut(); window.location.reload(); }, }; diff --git a/public/app/core/services/context_srv.ts b/public/app/core/services/context_srv.ts index c65d763270d..ff98c016370 100644 --- a/public/app/core/services/context_srv.ts +++ b/public/app/core/services/context_srv.ts @@ -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; } diff --git a/public/app/features/dashboard/services/ChangeTracker.ts b/public/app/features/dashboard/services/ChangeTracker.ts index afe7b7bde8b..c9dde5246a7 100644 --- a/public/app/features/dashboard/services/ChangeTracker.ts +++ b/public/app/features/dashboard/services/ChangeTracker.ts @@ -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; }