Chore: Fix fetching the General folder when nested folders is set and improve error handling (#62951)

* Nested folders: Modify Get() not to fail fetching the General folder

* Add test
This commit is contained in:
Sofia Papagiannaki
2023-02-08 17:16:53 +02:00
committed by GitHub
parent 4181acec72
commit 225c8dbba7
3 changed files with 39 additions and 3 deletions
+7 -3
View File
@@ -34,7 +34,7 @@ type Service struct {
features featuremgmt.FeatureToggles
accessControl accesscontrol.AccessControl
// bus is currently used to publish events that cause scheduler to update rules.
// bus is currently used to publish event in case of title change
bus bus.Bus
}
@@ -121,8 +121,12 @@ func (s *Service) Get(ctx context.Context, cmd *folder.GetFolderQuery) (*folder.
cmd.ID = nil
cmd.UID = &dashFolder.UID
}
f, err := s.store.Get(ctx, *cmd)
if dashFolder.IsGeneral() {
return dashFolder, nil
}
f, err := s.store.Get(ctx, *cmd)
if err != nil {
return nil, err
}
@@ -191,7 +195,7 @@ func (s *Service) GetParents(ctx context.Context, q folder.GetParentsQuery) ([]*
func (s *Service) getFolderByID(ctx context.Context, user *user.SignedInUser, id int64, orgID int64) (*folder.Folder, error) {
if id == 0 {
return &folder.Folder{ID: id, Title: "General"}, nil
return &folder.GeneralFolder, nil
}
dashFolder, err := s.dashboardFolderStore.GetFolderByID(ctx, orgID, id)