Chore: Add context dashboard version (#41672)

* Add context dashboard version

* Fix codeql
This commit is contained in:
idafurjes
2021-11-17 10:57:37 +01:00
committed by GitHub
parent bc60ae3c66
commit bb01f8c4cf
6 changed files with 74 additions and 64 deletions
+8 -5
View File
@@ -7,6 +7,7 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"
"github.com/grafana/grafana/pkg/api/dtos"
"github.com/grafana/grafana/pkg/api/response"
@@ -20,6 +21,7 @@ import (
"github.com/grafana/grafana/pkg/services/guardian"
"github.com/grafana/grafana/pkg/util"
"github.com/grafana/grafana/pkg/web"
"gopkg.in/macaron.v1"
)
const (
@@ -519,7 +521,7 @@ func GetDashboardVersions(c *models.ReqContext) response.Response {
Start: c.QueryInt("start"),
}
if err := bus.Dispatch(&query); err != nil {
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
return response.Error(404, fmt.Sprintf("No versions found for dashboardId %d", dashID), err)
}
@@ -551,13 +553,14 @@ func GetDashboardVersion(c *models.ReqContext) response.Response {
return dashboardGuardianResponse(err)
}
version, _ := strconv.ParseInt(macaron.Params(c.Req)[":id"], 10, 32)
query := models.GetDashboardVersionQuery{
OrgId: c.OrgId,
DashboardId: dashID,
Version: int(c.ParamsInt64(":id")),
Version: int(version),
}
if err := bus.Dispatch(&query); err != nil {
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
return response.Error(500, fmt.Sprintf("Dashboard version %d not found for dashboardId %d", query.Version, dashID), err)
}
@@ -610,7 +613,7 @@ func CalculateDashboardDiff(c *models.ReqContext, apiOptions dtos.CalculateDiffO
},
}
result, err := dashdiffs.CalculateDiff(&options)
result, err := dashdiffs.CalculateDiff(c.Req.Context(), &options)
if err != nil {
if errors.Is(err, models.ErrDashboardVersionNotFound) {
return response.Error(404, "Dashboard version not found", err)
@@ -638,7 +641,7 @@ func (hs *HTTPServer) RestoreDashboardVersion(c *models.ReqContext, apiCmd dtos.
}
versionQuery := models.GetDashboardVersionQuery{DashboardId: dash.Id, Version: apiCmd.Version, OrgId: c.OrgId}
if err := bus.Dispatch(&versionQuery); err != nil {
if err := bus.DispatchCtx(c.Req.Context(), &versionQuery); err != nil {
return response.Error(404, "Dashboard version not found", nil)
}