Live: only connect when user has a role (#35339) (#35395)

(cherry picked from commit 78d53c5e3d)

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
Grot (@grafanabot)
2021-06-09 09:40:51 -07:00
committed by GitHub
co-authored by Ryan McKinley
parent 8b6c978d6d
commit 8c1b326585
+5 -2
View File
@@ -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<boolean>(this.centrifuge.isConnected());