Public Dashboards: Dont make annotations request when access token is falsey (#60202)

dont make annotations request when access token is falsey
This commit is contained in:
owensmallwood 2022-12-12 15:52:49 -06:00 committed by GitHub
parent 46e86300cb
commit d2f9d7f39b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 1 deletions

View File

@ -45,6 +45,34 @@ describe('PublicDashboardDatasource', () => {
expect(annotation?.queryType).toEqual(GrafanaQueryType.Annotations);
});
test('will not fetch annotations when access token is falsey', async () => {
mockDatasourceRequest.mockReset();
mockDatasourceRequest.mockReturnValue(Promise.resolve([]));
const ds = new PublicDashboardDataSource('public');
const panelId = 1;
const publicDashboardAccessToken = undefined;
await ds.query({
maxDataPoints: 10,
intervalMs: 5000,
targets: [
{
refId: 'A',
datasource: { uid: GRAFANA_DATASOURCE_NAME, type: 'sample' },
queryType: GrafanaQueryType.Annotations,
},
],
panelId,
publicDashboardAccessToken,
range: { from: new Date().toLocaleString(), to: new Date().toLocaleString() } as unknown as TimeRange,
} as DataQueryRequest);
const mock = mockDatasourceRequest.mock;
expect(mock.calls.length).toBe(0);
});
test('fetches results from the pubdash annotations endpoint when it is an annotation query', async () => {
mockDatasourceRequest.mockReset();
mockDatasourceRequest.mockReturnValue(Promise.resolve([]));

View File

@ -130,7 +130,10 @@ export class PublicDashboardDataSource extends DataSourceApi<DataQuery, DataSour
from: from.valueOf(),
to: to.valueOf(),
};
const annotations = await getBackendSrv().get(`/api/public/dashboards/${accessToken}/annotations`, params);
const annotations = accessToken
? await getBackendSrv().get(`/api/public/dashboards/${accessToken}/annotations`, params)
: [];
return { data: [toDataFrame(annotations)] };
}