mirror of https://github.com/grafana/grafana.git
fix(unified-storage): dashboards not persisting folder_id with unified storage (#100844)
* fix dashboards not persisting folder_id with unified storage
This commit is contained in:
parent
b4c4b9abbd
commit
c8d4ff28a4
|
@ -400,6 +400,20 @@ func saveDashboard(sess *db.Session, cmd *dashboards.SaveDashboardCommand, emitE
|
|||
userId = -1
|
||||
}
|
||||
|
||||
// we don't save FolderID in kubernetes object when saving through k8s
|
||||
// this block guarantees we save dashboards with folder_id and folder_uid in those cases
|
||||
if !dash.IsFolder && dash.FolderUID != "" && dash.FolderID == 0 { // nolint:staticcheck
|
||||
var existing dashboards.Dashboard
|
||||
folderIdFound, err := sess.Where("uid=? AND org_id=?", dash.FolderUID, dash.OrgID).Get(&existing)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if folderIdFound {
|
||||
dash.FolderID = existing.ID // nolint:staticcheck
|
||||
}
|
||||
}
|
||||
|
||||
if dash.ID > 0 {
|
||||
var existing dashboards.Dashboard
|
||||
dashWithIdExists, err := sess.Where("id=? AND org_id=?", dash.ID, dash.OrgID).Get(&existing)
|
||||
|
|
|
@ -378,6 +378,23 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
|||
require.False(t, dashboard.Updated.IsZero())
|
||||
})
|
||||
|
||||
t.Run("Should populate FolderID if FolderUID is provided when creating a dashboard", func(t *testing.T) {
|
||||
setup()
|
||||
cmd := dashboards.SaveDashboardCommand{
|
||||
OrgID: 1,
|
||||
Dashboard: simplejson.NewFromAny(map[string]interface{}{
|
||||
"title": "folderId",
|
||||
"tags": []interface{}{},
|
||||
}),
|
||||
FolderUID: savedFolder.UID,
|
||||
UserID: 100,
|
||||
}
|
||||
dashboard, err := dashboardStore.SaveDashboard(context.Background(), cmd)
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, dashboard.FolderID, savedFolder.ID) //nolint:staticcheck
|
||||
require.EqualValues(t, dashboard.FolderUID, savedFolder.UID)
|
||||
})
|
||||
|
||||
t.Run("Should be able to update dashboard by id and remove folderId", func(t *testing.T) {
|
||||
setup()
|
||||
cmd := dashboards.SaveDashboardCommand{
|
||||
|
|
Loading…
Reference in New Issue