Dashboard migration: Implement v2 to v0 conversions (#114812)
* Update docs * Remove 406 response since now it is converted * fix linter --------- Co-authored-by: Stephanie Hingtgen <stephanie.hingtgen@grafana.com>
This commit is contained in:
co-authored by
Stephanie Hingtgen
parent
dcd2086212
commit
c8853f50cf
@@ -96,12 +96,6 @@ func (hs *HTTPServer) GetDashboard(c *contextmodel.ReqContext) response.Response
|
||||
return rsp
|
||||
}
|
||||
|
||||
// v2 is not supported in /api
|
||||
if strings.HasPrefix(dash.APIVersion, "v2") {
|
||||
url := fmt.Sprintf("/apis/dashboard.grafana.app/%s/namespaces/%s/dashboards/%s", dash.APIVersion, hs.namespacer(c.GetOrgID()), dash.UID)
|
||||
return response.Error(http.StatusNotAcceptable, "dashboard api version not supported, use "+url+" instead", nil)
|
||||
}
|
||||
|
||||
var (
|
||||
publicDashboardEnabled = false
|
||||
err error
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -868,45 +867,6 @@ func TestIntegrationDashboardAPIEndpoint(t *testing.T) {
|
||||
assert.Equal(t, false, dash.Meta.Provisioned)
|
||||
}, mockSQLStore)
|
||||
})
|
||||
|
||||
t.Run("v2 dashboards should not be returned in api", func(t *testing.T) {
|
||||
mockSQLStore := dbtest.NewFakeDB()
|
||||
dashboardService := dashboards.NewFakeDashboardService(t)
|
||||
dashboardProvisioningService := dashboards.NewFakeDashboardProvisioning(t)
|
||||
|
||||
dataValue, err := simplejson.NewJson([]byte(`{"id": 1, "apiVersion": "v2"}`))
|
||||
require.NoError(t, err)
|
||||
qResult := &dashboards.Dashboard{
|
||||
ID: 1,
|
||||
UID: "dash",
|
||||
OrgID: 1,
|
||||
APIVersion: "v2",
|
||||
Data: dataValue,
|
||||
}
|
||||
dashboardService.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Return(qResult, nil)
|
||||
|
||||
loggedInUserScenarioWithRole(t, "When calling GET on", "GET", "/api/dashboards/uid/dash", "/api/dashboards/uid/:uid", org.RoleEditor, func(sc *scenarioContext) {
|
||||
hs := &HTTPServer{
|
||||
Cfg: setting.NewCfg(),
|
||||
LibraryElementService: &libraryelementsfake.LibraryElementService{},
|
||||
SQLStore: mockSQLStore,
|
||||
AccessControl: actest.FakeAccessControl{ExpectedEvaluate: true},
|
||||
DashboardService: dashboardService,
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
starService: startest.NewStarServiceFake(),
|
||||
tracer: tracing.InitializeTracerForTest(),
|
||||
dashboardProvisioningService: dashboardProvisioningService,
|
||||
folderService: foldertest.NewFakeService(),
|
||||
log: log.New("test"),
|
||||
namespacer: func(orgID int64) string { return strconv.FormatInt(orgID, 10) },
|
||||
}
|
||||
hs.callGetDashboard(sc)
|
||||
|
||||
assert.Equal(t, http.StatusNotAcceptable, sc.resp.Code)
|
||||
result := sc.ToJSON()
|
||||
assert.Equal(t, "dashboard api version not supported, use /apis/dashboard.grafana.app/v2/namespaces/1/dashboards/dash instead", result.Get("message").MustString())
|
||||
}, mockSQLStore)
|
||||
})
|
||||
}
|
||||
|
||||
func TestDashboardVersionsAPIEndpoint(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user