Refactor: Add UID endpoint for get dashboard version (#48600)
* Refactor: Add UID endpoint for get dashboard version * Add initial docs language * Add new endpoint in swagger * Change access control to dashboards * Add parameters to swagger endpoint * Return UID in response; Update docs to reflect this; Implement Ying suggestion * Update docs/sources/http_api/dashboard_versions.md Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com> * Update pkg/api/api.go Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com> * Update pkg/models/dashboard_version.go Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com> * Rename UID to DashboardUID for clarity; use dashUID in method Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>
This commit is contained in:
co-authored by
Sofia Papagiannaki
parent
ce6a5694ff
commit
9a0f2ec449
+20
-3
@@ -558,9 +558,25 @@ func (hs *HTTPServer) GetDashboardVersions(c *models.ReqContext) response.Respon
|
||||
|
||||
// GetDashboardVersion returns the dashboard version with the given ID.
|
||||
func (hs *HTTPServer) GetDashboardVersion(c *models.ReqContext) response.Response {
|
||||
dashID, err := strconv.ParseInt(web.Params(c.Req)[":dashboardId"], 10, 64)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "dashboardId is invalid", err)
|
||||
var dashID int64
|
||||
|
||||
var err error
|
||||
dashUID := web.Params(c.Req)[":uid"]
|
||||
|
||||
if dashUID == "" {
|
||||
dashID, err = strconv.ParseInt(web.Params(c.Req)[":dashboardId"], 10, 64)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "dashboardId is invalid", err)
|
||||
}
|
||||
} else {
|
||||
q := models.GetDashboardQuery{
|
||||
OrgId: c.SignedInUser.OrgId,
|
||||
Uid: dashUID,
|
||||
}
|
||||
if err := hs.SQLStore.GetDashboard(c.Req.Context(), &q); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "failed to get dashboard by UID", err)
|
||||
}
|
||||
dashID = q.Result.Id
|
||||
}
|
||||
|
||||
guardian := guardian.New(c.Req.Context(), dashID, c.OrgId, c.SignedInUser)
|
||||
@@ -587,6 +603,7 @@ func (hs *HTTPServer) GetDashboardVersion(c *models.ReqContext) response.Respons
|
||||
dashVersionMeta := &models.DashboardVersionMeta{
|
||||
Id: query.Result.Id,
|
||||
DashboardId: query.Result.DashboardId,
|
||||
DashboardUID: dashUID,
|
||||
Data: query.Result.Data,
|
||||
ParentVersion: query.Result.ParentVersion,
|
||||
RestoredFrom: query.Result.RestoredFrom,
|
||||
|
||||
Reference in New Issue
Block a user