PublicDashboards: disable annotations (#50984)

* PublicDashboards: disable annotations
This commit is contained in:
Ezequiel Victorero
2022-06-23 13:09:30 -03:00
committed by GitHub
parent 64356509b5
commit 25d4ddf959
4 changed files with 25 additions and 7 deletions

View File

@@ -86,6 +86,15 @@ describe('AnnotationsWorker', () => {
});
});
describe('when canWork is called with correct props for a public dashboard with public view', () => {
it('then it should return true', () => {
const options = getDefaultOptions();
options.dashboard.meta.publicDashboardAccessToken = 'accessTokenString';
expect(worker.canWork(options)).toBe(false);
});
});
describe('when canWork is called with incorrect props', () => {
it('then it should return false', () => {
const dashboard: any = { annotations: { list: [] } };

View File

@@ -6,6 +6,7 @@ import { AnnotationQuery, DataSourceApi } from '@grafana/data';
import { getDataSourceSrv } from '@grafana/runtime';
import { AnnotationQueryFinished, AnnotationQueryStarted } from '../../../../types/events';
import { DashboardModel } from '../../../dashboard/state';
import { AnnotationsQueryRunner } from './AnnotationsQueryRunner';
import { getDashboardQueryRunner } from './DashboardQueryRunner';
@@ -28,7 +29,8 @@ export class AnnotationsWorker implements DashboardQueryRunnerWorker {
canWork({ dashboard }: DashboardQueryRunnerOptions): boolean {
const annotations = dashboard.annotations.list.find(AnnotationsWorker.getAnnotationsToProcessFilter);
return Boolean(annotations);
// We shouldn't return annotations for public dashboards v1
return Boolean(annotations) && !this.publicDashboardViewMode(dashboard);
}
work(options: DashboardQueryRunnerOptions): Observable<DashboardQueryRunnerWorkerResult> {
@@ -91,4 +93,8 @@ export class AnnotationsWorker implements DashboardQueryRunnerWorker {
private static getAnnotationsToProcessFilter(annotation: AnnotationQuery): boolean {
return annotation.enable && !Boolean(annotation.snapshotData);
}
publicDashboardViewMode(dashboard: DashboardModel): boolean {
return dashboard.meta.publicDashboardAccessToken !== undefined && dashboard.meta.publicDashboardAccessToken !== '';
}
}

View File

@@ -55,6 +55,9 @@ export function getDefaultOptions(): DashboardQueryRunnerOptions {
publish: jest.fn(),
},
panels: [{ alert: {} } as any],
meta: {
publicDashboardAccessToken: '',
},
};
const range = getDefaultTimeRange();