mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
API: Fix "Updated by" Column in dashboard versions table (#65351)
* API: Fix dashboard versions created by field * Add tests * Update OpenAPI specs * Apply suggestion from code review
This commit is contained in:
committed by
GitHub
parent
71ef159150
commit
3cd3bb00ec
@@ -660,25 +660,52 @@ func (hs *HTTPServer) GetDashboardVersions(c *contextmodel.ReqContext) response.
|
||||
Start: c.QueryInt("start"),
|
||||
}
|
||||
|
||||
res, err := hs.dashboardVersionService.List(c.Req.Context(), &query)
|
||||
versions, err := hs.dashboardVersionService.List(c.Req.Context(), &query)
|
||||
if err != nil {
|
||||
return response.Error(404, fmt.Sprintf("No versions found for dashboardId %d", dash.ID), err)
|
||||
}
|
||||
|
||||
for _, version := range res {
|
||||
loginMem := make(map[int64]string, len(versions))
|
||||
res := make([]dashver.DashboardVersionMeta, 0, len(versions))
|
||||
for _, version := range versions {
|
||||
msg := version.Message
|
||||
if version.RestoredFrom == version.Version {
|
||||
version.Message = "Initial save (created by migration)"
|
||||
continue
|
||||
msg = "Initial save (created by migration)"
|
||||
}
|
||||
|
||||
if version.RestoredFrom > 0 {
|
||||
version.Message = fmt.Sprintf("Restored from version %d", version.RestoredFrom)
|
||||
continue
|
||||
msg = fmt.Sprintf("Restored from version %d", version.RestoredFrom)
|
||||
}
|
||||
|
||||
if version.ParentVersion == 0 {
|
||||
version.Message = "Initial save"
|
||||
msg = "Initial save"
|
||||
}
|
||||
|
||||
creator := anonString
|
||||
if version.CreatedBy > 0 {
|
||||
login, found := loginMem[version.CreatedBy]
|
||||
if found {
|
||||
creator = login
|
||||
} else {
|
||||
creator = hs.getUserLogin(c.Req.Context(), version.CreatedBy)
|
||||
if creator != anonString {
|
||||
loginMem[version.CreatedBy] = creator
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res = append(res, dashver.DashboardVersionMeta{
|
||||
ID: version.ID,
|
||||
DashboardID: version.DashboardID,
|
||||
DashboardUID: dash.UID,
|
||||
Data: version.Data,
|
||||
ParentVersion: version.ParentVersion,
|
||||
RestoredFrom: version.RestoredFrom,
|
||||
Version: version.Version,
|
||||
Created: version.Created,
|
||||
Message: msg,
|
||||
CreatedBy: creator,
|
||||
})
|
||||
}
|
||||
|
||||
return response.JSON(http.StatusOK, res)
|
||||
@@ -1267,7 +1294,7 @@ type GetHomeDashboardResponseBody struct {
|
||||
// swagger:response dashboardVersionsResponse
|
||||
type DashboardVersionsResponse struct {
|
||||
// in: body
|
||||
Body []*dashver.DashboardVersionDTO `json:"body"`
|
||||
Body []dashver.DashboardVersionMeta `json:"body"`
|
||||
}
|
||||
|
||||
// swagger:response dashboardVersionResponse
|
||||
|
||||
Reference in New Issue
Block a user