mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Public Dashboards: Query Caching (#51403)
* passes id and uid to PublicDashboardDatasource * betterer results * If for a public dashboard, return the PublicDashboardDataSource first or else getDatasourceSrv.get() will fail bc of no authed user. Added some unit tests for resolving the uid from the many possible datasource types. * updates betterer * Exports DashboardService. Adds method to DashboardService to build anonymous user for use with public dashboards where there is no authed user. Adds method on dashboard_queries to get all dashboard uids from a dashboard. * refactors to get unique datasource uids * Adds tests for getting all unique datasource uids off a dashboard * adds test for building anonymous user with read and query actions that are scoped to each datasource uid in the dashboard * updates casing of DashboardService * updates test case to have additional panel with a different datasource * gives default interval to public dashboard data source
This commit is contained in:
@@ -1,19 +1,41 @@
|
||||
import { catchError, Observable, of, switchMap } from 'rxjs';
|
||||
|
||||
import { DataQuery, DataQueryRequest, DataQueryResponse, DataSourceApi, PluginMeta } from '@grafana/data';
|
||||
import {
|
||||
DataQuery,
|
||||
DataQueryRequest,
|
||||
DataQueryResponse,
|
||||
DataSourceApi,
|
||||
DataSourceRef,
|
||||
PluginMeta,
|
||||
} from '@grafana/data';
|
||||
import { BackendDataSourceResponse, getBackendSrv, toDataQueryResponse } from '@grafana/runtime';
|
||||
|
||||
export const PUBLIC_DATASOURCE = '-- Public --';
|
||||
|
||||
export class PublicDashboardDataSource extends DataSourceApi<any> {
|
||||
constructor() {
|
||||
constructor(datasource: DataSourceRef | string | DataSourceApi | null) {
|
||||
super({
|
||||
name: 'public-ds',
|
||||
id: 1,
|
||||
id: 0,
|
||||
type: 'public-ds',
|
||||
meta: {} as PluginMeta,
|
||||
uid: '1',
|
||||
uid: PublicDashboardDataSource.resolveUid(datasource),
|
||||
jsonData: {},
|
||||
access: 'proxy',
|
||||
});
|
||||
|
||||
this.interval = '1min';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the datasource uid based on the many types a datasource can be.
|
||||
*/
|
||||
private static resolveUid(datasource: DataSourceRef | string | DataSourceApi | null): string {
|
||||
if (typeof datasource === 'string') {
|
||||
return datasource;
|
||||
}
|
||||
|
||||
return datasource?.uid ?? PUBLIC_DATASOURCE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user