mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
PublicDashboards: support time range selection on the backend (#60203)
This commit is contained in:
committed by
GitHub
parent
6928ad2949
commit
8d5b19bc61
@@ -3,6 +3,7 @@ package validation
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
||||
"github.com/grafana/grafana/pkg/tsdb/legacydata"
|
||||
)
|
||||
|
||||
func ValidatePublicDashboard(dto *SavePublicDashboardDTO, dashboard *models.Dashboard) error {
|
||||
@@ -19,7 +20,7 @@ func hasTemplateVariables(dashboard *models.Dashboard) bool {
|
||||
return len(templateVariables) > 0
|
||||
}
|
||||
|
||||
func ValidateQueryPublicDashboardRequest(req PublicDashboardQueryDTO) error {
|
||||
func ValidateQueryPublicDashboardRequest(req PublicDashboardQueryDTO, pd *PublicDashboard) error {
|
||||
if req.IntervalMs < 0 {
|
||||
return ErrInvalidInterval.Errorf("ValidateQueryPublicDashboardRequest: intervalMS should be greater than 0")
|
||||
}
|
||||
@@ -28,5 +29,18 @@ func ValidateQueryPublicDashboardRequest(req PublicDashboardQueryDTO) error {
|
||||
return ErrInvalidMaxDataPoints.Errorf("ValidateQueryPublicDashboardRequest: maxDataPoints should be greater than 0")
|
||||
}
|
||||
|
||||
if pd.TimeSelectionEnabled {
|
||||
timeRange := legacydata.NewDataTimeRange(req.TimeRange.From, req.TimeRange.To)
|
||||
|
||||
_, err := timeRange.ParseFrom()
|
||||
if err != nil {
|
||||
return ErrInvalidTimeRange.Errorf("ValidateQueryPublicDashboardRequest: time range from is invalid")
|
||||
}
|
||||
_, err = timeRange.ParseTo()
|
||||
if err != nil {
|
||||
return ErrInvalidTimeRange.Errorf("ValidateQueryPublicDashboardRequest: time range to is invalid")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user