Dashboards: Fix restoring dashboard to root folder (#89020)

* Fix restoring dashboard to root folder

* use a root folder representation instead of nil

* change root folder by general folder

---------

Co-authored-by: Ezequiel Victorero <ezequiel.victorero@grafana.com>
This commit is contained in:
Sofia Papagiannaki
2024-06-18 14:21:40 +03:00
committed by GitHub
parent b4c5c62f59
commit 0afbaa39df
3 changed files with 23 additions and 1 deletions
+4 -1
View File
@@ -209,7 +209,10 @@ func (s *Service) Get(ctx context.Context, q *folder.GetFolderQuery) (*folder.Fo
var dashFolder *folder.Folder
var err error
switch {
case q.UID != nil && *q.UID != "":
case q.UID != nil:
if *q.UID == "" {
return &folder.GeneralFolder, nil
}
dashFolder, err = s.getFolderByUID(ctx, q.OrgID, *q.UID)
if err != nil {
return nil, err
@@ -395,6 +395,21 @@ func TestIntegrationFolderService(t *testing.T) {
"For error '%s' expected error '%s', actual '%s'", tc.ActualError, tc.ExpectedError, actualError)
}
})
t.Run("Returns root folder", func(t *testing.T) {
t.Run("When the folder UID is blank should return the root folder", func(t *testing.T) {
emptyString := ""
actual, err := service.Get(context.Background(), &folder.GetFolderQuery{
UID: &emptyString,
OrgID: 1,
SignedInUser: usr,
})
assert.NoError(t, err)
assert.Equal(t, folder.GeneralFolder.UID, actual.UID)
assert.Equal(t, folder.GeneralFolder.Title, actual.Title)
})
})
})
}