PublicDashboards: Fix unsafe code snippets (#57641)

* return an error if we can't extract queries from a panel

* check for null or undefined
This commit is contained in:
Michael Mandrus
2022-10-25 20:16:10 -04:00
committed by GitHub
parent e6575bab76
commit 5879805e4b
3 changed files with 7 additions and 3 deletions

View File

@@ -61,6 +61,10 @@ var (
Reason: "bad Request",
StatusCode: 400,
}
ErrNoPanelQueriesFound = PublicDashboardErr{
Reason: "failed to extract queries from panel",
StatusCode: 400,
}
)
type PublicDashboard struct {

View File

@@ -131,7 +131,7 @@ func (pd *PublicDashboardServiceImpl) GetQueryDataResponse(ctx context.Context,
}
if len(metricReq.Queries) == 0 {
return nil, nil
return nil, models.ErrNoPanelQueriesFound
}
anonymousUser := buildAnonymousUser(ctx, dashboard)

View File

@@ -59,7 +59,7 @@ export class PublicDashboardDataSource extends DataSourceApi<DataQuery, DataSour
}
private static isMixedDatasource(datasource: DataSourceRef | string | DataSourceApi | null): boolean {
if (typeof datasource === 'string' || datasource === null) {
if (typeof datasource === 'string' || datasource == null) {
return false;
}
@@ -67,7 +67,7 @@ export class PublicDashboardDataSource extends DataSourceApi<DataQuery, DataSour
}
private static resolveInterval(datasource: DataSourceRef | string | DataSourceApi | null): string {
if (typeof datasource === 'string' || datasource === null) {
if (typeof datasource === 'string' || datasource == null) {
return DEFAULT_INTERVAL;
}