From 8c1b3265859ffa45cf58f0ddc675f9c4463fa129 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Wed, 9 Jun 2021 12:40:51 -0400 Subject: [PATCH] Live: only connect when user has a role (#35339) (#35395) (cherry picked from commit 78d53c5e3d7dad2bd67d74905f82d10568293548) Co-authored-by: Ryan McKinley --- public/app/features/live/live.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/public/app/features/live/live.ts b/public/app/features/live/live.ts index 89b802a3d53..eafbfa6cca9 100644 --- a/public/app/features/live/live.ts +++ b/public/app/features/live/live.ts @@ -36,6 +36,7 @@ import { GrafanaLiveStreamScope, } from './scopes'; import { registerLiveFeatures } from './features'; +import { contextSrv } from '../../core/services/context_srv'; import { perf } from './perf'; export const sessionId = @@ -56,7 +57,8 @@ export class CentrifugeSrv implements GrafanaLiveSrv { constructor() { const baseURL = window.location.origin.replace('http', 'ws'); const liveUrl = `${baseURL}${config.appSubUrl}/api/live/ws`; - this.orgId = (window as any).grafanaBootData.user.orgId; + + this.orgId = contextSrv.user.orgId; this.centrifuge = new Centrifuge(liveUrl, { debug: true, }); @@ -64,7 +66,8 @@ export class CentrifugeSrv implements GrafanaLiveSrv { sessionId, orgId: this.orgId, }); - if (config.liveEnabled) { + // orgRole is set when logged in *or* anonomus users can use grafana + if (config.liveEnabled && contextSrv.user.orgRole !== '') { this.centrifuge.connect(); // do connection } this.connectionState = new BehaviorSubject(this.centrifuge.isConnected());