Validate panels in Store.AddPanel/UpdatePanel, not just at the handler
CreateDashboard's inline panel-creation path already called validatePanel before insert; AddPanel and UpdatePanel relied on the HTTP handler to validate first instead of enforcing it themselves. Found via a live Postgres integration test: calling store.AddPanel directly (bypassing the handler) hit a viz_config NOT NULL constraint violation instead of getting the same default-empty-JSON treatment every other panel-creation path gets.
This commit is contained in:
@@ -183,6 +183,9 @@ func (s *Store) DeleteDashboard(ctx context.Context, tenantID, id string) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) AddPanel(ctx context.Context, tenantID, dashboardID string, p *Panel) error {
|
func (s *Store) AddPanel(ctx context.Context, tenantID, dashboardID string, p *Panel) error {
|
||||||
|
if err := validatePanel(p); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
ok, err := s.dashboardTenantMatches(ctx, tenantID, dashboardID)
|
ok, err := s.dashboardTenantMatches(ctx, tenantID, dashboardID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -203,6 +206,9 @@ func (s *Store) AddPanel(ctx context.Context, tenantID, dashboardID string, p *P
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) UpdatePanel(ctx context.Context, tenantID string, p *Panel) error {
|
func (s *Store) UpdatePanel(ctx context.Context, tenantID string, p *Panel) error {
|
||||||
|
if err := validatePanel(p); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
ok, err := s.dashboardTenantMatches(ctx, tenantID, p.DashboardID)
|
ok, err := s.dashboardTenantMatches(ctx, tenantID, p.DashboardID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user