mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
refactor public dashboards middleware testing (#55706)
This PR refactors how we add the orgId to the context on a public dashboard paths. We also split out accessToken handling into its own package and rework status code for "RequiresValidAccessToken". We will be modeling all endpoints to use these status codes going forward. Additionally, it includes a scaffold for better middleware testing and refactors existing tests to table drive tests.
This commit is contained in:
34
pkg/services/publicdashboards/validation/validation.go
Normal file
34
pkg/services/publicdashboards/validation/validation.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
||||
)
|
||||
|
||||
func ValidateSavePublicDashboard(dto *SavePublicDashboardConfigDTO, dashboard *models.Dashboard) error {
|
||||
if hasTemplateVariables(dashboard) {
|
||||
return ErrPublicDashboardHasTemplateVariables
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func hasTemplateVariables(dashboard *models.Dashboard) bool {
|
||||
templateVariables := dashboard.Data.Get("templating").Get("list").MustArray()
|
||||
|
||||
return len(templateVariables) > 0
|
||||
}
|
||||
|
||||
func ValidateQueryPublicDashboardRequest(req PublicDashboardQueryDTO) error {
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user