Chore: Remove unused+experimental /dashboards/calculate-diff API support (#114151)
This commit is contained in:
@@ -656,10 +656,6 @@ const injectedRtkApi = api
|
||||
}),
|
||||
providesTags: ['dashboards', 'snapshots'],
|
||||
}),
|
||||
calculateDashboardDiff: build.mutation<CalculateDashboardDiffApiResponse, CalculateDashboardDiffApiArg>({
|
||||
query: (queryArg) => ({ url: `/dashboards/calculate-diff`, method: 'POST', body: queryArg.body }),
|
||||
invalidatesTags: ['dashboards'],
|
||||
}),
|
||||
postDashboard: build.mutation<PostDashboardApiResponse, PostDashboardApiArg>({
|
||||
query: (queryArg) => ({ url: `/dashboards/db`, method: 'POST', body: queryArg.saveDashboardCommand }),
|
||||
invalidatesTags: ['dashboards'],
|
||||
@@ -2556,18 +2552,6 @@ export type SearchDashboardSnapshotsApiArg = {
|
||||
/** Limit the number of returned results */
|
||||
limit?: number;
|
||||
};
|
||||
export type CalculateDashboardDiffApiResponse = /** status 200 (empty) */ number[];
|
||||
export type CalculateDashboardDiffApiArg = {
|
||||
body: {
|
||||
base?: CalculateDiffTarget;
|
||||
/** The type of diff to return
|
||||
Description:
|
||||
`basic`
|
||||
`json` */
|
||||
diffType?: 'basic' | 'json';
|
||||
new?: CalculateDiffTarget;
|
||||
};
|
||||
};
|
||||
export type PostDashboardApiResponse = /** status 200 (empty) */ {
|
||||
/** FolderUID The unique identifier (uid) of the folder the dashboard belongs to. */
|
||||
folderUid?: string;
|
||||
@@ -4400,11 +4384,6 @@ export type DashboardSnapshotDto = {
|
||||
name?: string;
|
||||
updated?: string;
|
||||
};
|
||||
export type CalculateDiffTarget = {
|
||||
dashboardId?: number;
|
||||
unsavedDashboard?: Json;
|
||||
version?: number;
|
||||
};
|
||||
export type SaveDashboardCommand = {
|
||||
UpdatedAt?: string;
|
||||
dashboard?: Json;
|
||||
@@ -6636,7 +6615,6 @@ export const {
|
||||
useLazyRouteConvertPrometheusGetRuleGroupQuery,
|
||||
useSearchDashboardSnapshotsQuery,
|
||||
useLazySearchDashboardSnapshotsQuery,
|
||||
useCalculateDashboardDiffMutation,
|
||||
usePostDashboardMutation,
|
||||
useGetHomeDashboardQuery,
|
||||
useLazyGetHomeDashboardQuery,
|
||||
|
||||
@@ -473,8 +473,6 @@ func (hs *HTTPServer) registerRoutes() {
|
||||
})
|
||||
})
|
||||
|
||||
dashboardRoute.Post("/calculate-diff", authorize(ac.EvalPermission(dashboards.ActionDashboardsWrite)), routing.Wrap(hs.CalculateDashboardDiff))
|
||||
|
||||
dashboardRoute.Post("/db", authorize(ac.EvalAny(ac.EvalPermission(dashboards.ActionDashboardsCreate), ac.EvalPermission(dashboards.ActionDashboardsWrite))), routing.Wrap(hs.PostDashboard))
|
||||
dashboardRoute.Get("/home", routing.Wrap(hs.GetHomeDashboard))
|
||||
dashboardRoute.Get("/tags", hs.GetDashboardTags)
|
||||
|
||||
@@ -19,7 +19,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
"github.com/grafana/grafana/pkg/components/dashdiffs"
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/infra/metrics"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
@@ -829,102 +828,6 @@ func (hs *HTTPServer) GetDashboardVersion(c *contextmodel.ReqContext) response.R
|
||||
return response.JSON(http.StatusOK, dashVersionMeta)
|
||||
}
|
||||
|
||||
// swagger:route POST /dashboards/calculate-diff dashboards calculateDashboardDiff
|
||||
//
|
||||
// Perform diff on two dashboards.
|
||||
//
|
||||
// Produces:
|
||||
// - application/json
|
||||
// - text/html
|
||||
//
|
||||
// Responses:
|
||||
// 200: calculateDashboardDiffResponse
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) CalculateDashboardDiff(c *contextmodel.ReqContext) response.Response {
|
||||
ctx, span := tracer.Start(c.Req.Context(), "api.CalculateDashboardDiff")
|
||||
defer span.End()
|
||||
c.Req = c.Req.WithContext(ctx)
|
||||
|
||||
apiOptions := dtos.CalculateDiffOptions{}
|
||||
if err := web.Bind(c.Req, &apiOptions); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
}
|
||||
|
||||
evaluator := accesscontrol.EvalPermission(dashboards.ActionDashboardsWrite, dashboards.ScopeDashboardsProvider.GetResourceScope(strconv.FormatInt(apiOptions.Base.DashboardId, 10)))
|
||||
if canWrite, err := hs.AccessControl.Evaluate(c.Req.Context(), c.SignedInUser, evaluator); err != nil || !canWrite {
|
||||
return dashboardGuardianResponse(err)
|
||||
}
|
||||
|
||||
if apiOptions.Base.DashboardId != apiOptions.New.DashboardId {
|
||||
evaluator = accesscontrol.EvalPermission(dashboards.ActionDashboardsWrite, dashboards.ScopeDashboardsProvider.GetResourceScope(strconv.FormatInt(apiOptions.New.DashboardId, 10)))
|
||||
if canWrite, err := hs.AccessControl.Evaluate(c.Req.Context(), c.SignedInUser, evaluator); err != nil || !canWrite {
|
||||
return dashboardGuardianResponse(err)
|
||||
}
|
||||
}
|
||||
|
||||
options := dashdiffs.Options{
|
||||
OrgId: c.GetOrgID(),
|
||||
DiffType: dashdiffs.ParseDiffType(apiOptions.DiffType),
|
||||
Base: dashdiffs.DiffTarget{
|
||||
DashboardId: apiOptions.Base.DashboardId,
|
||||
Version: apiOptions.Base.Version,
|
||||
UnsavedDashboard: apiOptions.Base.UnsavedDashboard,
|
||||
},
|
||||
New: dashdiffs.DiffTarget{
|
||||
DashboardId: apiOptions.New.DashboardId,
|
||||
Version: apiOptions.New.Version,
|
||||
UnsavedDashboard: apiOptions.New.UnsavedDashboard,
|
||||
},
|
||||
}
|
||||
|
||||
baseVersionQuery := dashver.GetDashboardVersionQuery{
|
||||
DashboardID: options.Base.DashboardId,
|
||||
Version: options.Base.Version,
|
||||
OrgID: options.OrgId,
|
||||
}
|
||||
|
||||
baseVersionRes, err := hs.dashboardVersionService.Get(c.Req.Context(), &baseVersionQuery)
|
||||
if err != nil {
|
||||
if errors.Is(err, dashver.ErrDashboardVersionNotFound) {
|
||||
return response.Error(http.StatusNotFound, "Dashboard version not found", err)
|
||||
}
|
||||
return response.Error(http.StatusInternalServerError, "Unable to compute diff", err)
|
||||
}
|
||||
|
||||
newVersionQuery := dashver.GetDashboardVersionQuery{
|
||||
DashboardID: options.New.DashboardId,
|
||||
Version: options.New.Version,
|
||||
OrgID: options.OrgId,
|
||||
}
|
||||
|
||||
newVersionRes, err := hs.dashboardVersionService.Get(c.Req.Context(), &newVersionQuery)
|
||||
if err != nil {
|
||||
if errors.Is(err, dashver.ErrDashboardVersionNotFound) {
|
||||
return response.Error(http.StatusNotFound, "Dashboard version not found", err)
|
||||
}
|
||||
return response.Error(http.StatusInternalServerError, "Unable to compute diff", err)
|
||||
}
|
||||
|
||||
baseData := baseVersionRes.Data
|
||||
newData := newVersionRes.Data
|
||||
|
||||
result, err := dashdiffs.CalculateDiff(c.Req.Context(), &options, baseData, newData)
|
||||
if err != nil {
|
||||
if errors.Is(err, dashver.ErrDashboardVersionNotFound) {
|
||||
return response.Error(http.StatusNotFound, "Dashboard version not found", err)
|
||||
}
|
||||
return response.Error(http.StatusInternalServerError, "Unable to compute diff", err)
|
||||
}
|
||||
|
||||
if options.DiffType == dashdiffs.DiffDelta {
|
||||
return response.Respond(http.StatusOK, result.Delta).SetHeader("Content-Type", "application/json")
|
||||
}
|
||||
|
||||
return response.Respond(http.StatusOK, result.Delta).SetHeader("Content-Type", "text/html")
|
||||
}
|
||||
|
||||
// swagger:route POST /dashboards/uid/{uid}/restore dashboards versions restoreDashboardVersionByUID
|
||||
//
|
||||
// Restore a dashboard to a given dashboard version using UID.
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -335,17 +334,6 @@ func TestHTTPServer_GetDashboardVersions_AccessControl(t *testing.T) {
|
||||
return server.Send(webtest.RequestWithSignedInUser(server.NewGetRequest("/api/dashboards/uid/1/versions"), userWithPermissions(1, permissions)))
|
||||
}
|
||||
|
||||
calculateDiff := func(server *webtest.Server, permissions []accesscontrol.Permission) (*http.Response, error) {
|
||||
cmd := &dtos.CalculateDiffOptions{
|
||||
Base: dtos.CalculateDiffTarget{DashboardId: 1, Version: 1},
|
||||
New: dtos.CalculateDiffTarget{DashboardId: 1, Version: 2},
|
||||
DiffType: "json",
|
||||
}
|
||||
jsonBytes, err := json.Marshal(cmd)
|
||||
require.NoError(t, err)
|
||||
return server.SendJSON(webtest.RequestWithSignedInUser(server.NewPostRequest("/api/dashboards/calculate-diff", bytes.NewReader(jsonBytes)), userWithPermissions(1, permissions)))
|
||||
}
|
||||
|
||||
t.Run("Should not be able to list dashboard versions without correct permission", func(t *testing.T) {
|
||||
server := setup()
|
||||
|
||||
@@ -379,28 +367,6 @@ func TestHTTPServer_GetDashboardVersions_AccessControl(t *testing.T) {
|
||||
|
||||
require.NoError(t, res.Body.Close())
|
||||
})
|
||||
|
||||
t.Run("Should be able to diff dashboards with correct permissions", func(t *testing.T) {
|
||||
server := setup()
|
||||
|
||||
permissions := []accesscontrol.Permission{
|
||||
{Action: dashboards.ActionDashboardsWrite, Scope: dashboards.ScopeDashboardsAll},
|
||||
}
|
||||
|
||||
res, err := calculateDiff(server, permissions)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, res.StatusCode)
|
||||
require.NoError(t, res.Body.Close())
|
||||
})
|
||||
|
||||
t.Run("Should not be able to diff dashboards without permissions", func(t *testing.T) {
|
||||
server := setup()
|
||||
|
||||
res, err := calculateDiff(server, []accesscontrol.Permission{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, http.StatusForbidden, res.StatusCode)
|
||||
require.NoError(t, res.Body.Close())
|
||||
})
|
||||
}
|
||||
|
||||
func TestIntegrationDashboardAPIEndpoint(t *testing.T) {
|
||||
|
||||
Generated
-53
@@ -3353,59 +3353,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/dashboards/calculate-diff": {
|
||||
"post": {
|
||||
"produces": [
|
||||
"application/json",
|
||||
"text/html"
|
||||
],
|
||||
"tags": [
|
||||
"dashboards"
|
||||
],
|
||||
"summary": "Perform diff on two dashboards.",
|
||||
"operationId": "calculateDashboardDiff",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "Body",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"base": {
|
||||
"$ref": "#/definitions/CalculateDiffTarget"
|
||||
},
|
||||
"diffType": {
|
||||
"description": "The type of diff to return\nDescription:\n`basic`\n`json`",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"basic",
|
||||
"json"
|
||||
]
|
||||
},
|
||||
"new": {
|
||||
"$ref": "#/definitions/CalculateDiffTarget"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/calculateDashboardDiffResponse"
|
||||
},
|
||||
"401": {
|
||||
"$ref": "#/responses/unauthorisedError"
|
||||
},
|
||||
"403": {
|
||||
"$ref": "#/responses/forbiddenError"
|
||||
},
|
||||
"500": {
|
||||
"$ref": "#/responses/internalServerError"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/dashboards/db": {
|
||||
"post": {
|
||||
"description": "Creates a new dashboard or updates an existing dashboard.\nNote: This endpoint is not intended for creating folders, use `POST /api/folders` for that.",
|
||||
|
||||
Generated
-50
@@ -17605,56 +17605,6 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/dashboards/calculate-diff": {
|
||||
"post": {
|
||||
"operationId": "calculateDashboardDiff",
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"base": {
|
||||
"$ref": "#/components/schemas/CalculateDiffTarget"
|
||||
},
|
||||
"diffType": {
|
||||
"description": "The type of diff to return\nDescription:\n`basic`\n`json`",
|
||||
"enum": [
|
||||
"basic",
|
||||
"json"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"new": {
|
||||
"$ref": "#/components/schemas/CalculateDiffTarget"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true,
|
||||
"x-originalParamName": "Body"
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/components/responses/calculateDashboardDiffResponse"
|
||||
},
|
||||
"401": {
|
||||
"$ref": "#/components/responses/unauthorisedError"
|
||||
},
|
||||
"403": {
|
||||
"$ref": "#/components/responses/forbiddenError"
|
||||
},
|
||||
"500": {
|
||||
"$ref": "#/components/responses/internalServerError"
|
||||
}
|
||||
},
|
||||
"summary": "Perform diff on two dashboards.",
|
||||
"tags": [
|
||||
"dashboards"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/dashboards/db": {
|
||||
"post": {
|
||||
"description": "Creates a new dashboard or updates an existing dashboard.\nNote: This endpoint is not intended for creating folders, use `POST /api/folders` for that.",
|
||||
|
||||
Reference in New Issue
Block a user