Support dashboard restore across API versions (#110694)

What

This commit refactors the logic to restore a dashboard from a version.
The logic is moved from the API handler to the dashboard versions service,
which now supports restoring dashboards of different API versions.

Why

To make sure that dashboard version restoration works with v2 dashboards
API, as well as future API versions.

Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com>
This commit is contained in:
Igor Suleymanov
2025-09-11 13:35:58 +03:00
committed by GitHub
parent 01b5543121
commit 4161f3a5ca
12 changed files with 1261 additions and 433 deletions
@@ -3,6 +3,7 @@ package dashvertest
import (
"context"
"github.com/grafana/grafana/pkg/services/dashboards"
dashver "github.com/grafana/grafana/pkg/services/dashboardversion"
)
@@ -13,6 +14,10 @@ type FakeDashboardVersionService struct {
ExpectedContinueToken string
counter int
ExpectedError error
// New fields for RestoreVersion testing
ExpectedRestoreResult *dashboards.Dashboard
RestoreVersionCalled bool
LastRestoreCommand *dashver.RestoreVersionCommand
}
func NewDashboardVersionServiceFake() *FakeDashboardVersionService {
@@ -37,3 +42,9 @@ func (f *FakeDashboardVersionService) List(ctx context.Context, query *dashver.L
Versions: f.ExpectedListDashboarVersions,
}, f.ExpectedError
}
func (f *FakeDashboardVersionService) RestoreVersion(ctx context.Context, cmd *dashver.RestoreVersionCommand) (*dashboards.Dashboard, error) {
f.RestoreVersionCalled = true
f.LastRestoreCommand = cmd
return f.ExpectedRestoreResult, f.ExpectedError
}