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

This commit is contained in:
Ryan McKinley 2021-06-08 14:00:24 -07:00 committed by GitHub
parent ec9b9d6ab1
commit 78d53c5e3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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