2022-07-21 14:56:20 -05:00
|
|
|
package validation
|
|
|
|
|
|
|
|
import (
|
2022-08-29 16:13:06 -05:00
|
|
|
"fmt"
|
|
|
|
|
2022-07-21 14:56:20 -05:00
|
|
|
"github.com/grafana/grafana/pkg/models"
|
2022-10-06 15:35:19 -05:00
|
|
|
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
2022-07-21 14:56:20 -05:00
|
|
|
)
|
|
|
|
|
2022-10-27 20:08:11 -05:00
|
|
|
func ValidateSavePublicDashboard(dto *SavePublicDashboardDTO, dashboard *models.Dashboard) error {
|
2022-07-21 14:56:20 -05:00
|
|
|
if hasTemplateVariables(dashboard) {
|
2022-10-06 15:35:19 -05:00
|
|
|
return ErrPublicDashboardHasTemplateVariables
|
2022-07-21 14:56:20 -05:00
|
|
|
}
|
|
|
|
|
2022-08-26 14:28:54 -05:00
|
|
|
return nil
|
2022-07-21 14:56:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func hasTemplateVariables(dashboard *models.Dashboard) bool {
|
|
|
|
templateVariables := dashboard.Data.Get("templating").Get("list").MustArray()
|
|
|
|
|
|
|
|
return len(templateVariables) > 0
|
|
|
|
}
|
2022-08-29 16:13:06 -05:00
|
|
|
|
2022-10-06 15:35:19 -05:00
|
|
|
func ValidateQueryPublicDashboardRequest(req PublicDashboardQueryDTO) error {
|
2022-08-29 16:13:06 -05:00
|
|
|
if req.IntervalMs < 0 {
|
|
|
|
return fmt.Errorf("intervalMS should be greater than 0")
|
|
|
|
}
|
|
|
|
|
|
|
|
if req.MaxDataPoints < 0 {
|
|
|
|
return fmt.Errorf("maxDataPoints should be greater than 0")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|