mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
parent
4181acec72
commit
225c8dbba7
@ -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)
|
||||
|
@ -763,6 +763,32 @@ func TestNestedFolderService(t *testing.T) {
|
||||
assert.ErrorIs(t, err, folder.ErrMaximumDepthReached)
|
||||
require.NotNil(t, actualCmd)
|
||||
})
|
||||
|
||||
t.Run("get default folder, no error", func(t *testing.T) {
|
||||
g := guardian.New
|
||||
guardian.MockDashboardGuardian(&guardian.FakeDashboardGuardian{CanSaveValue: true})
|
||||
t.Cleanup(func() {
|
||||
guardian.New = g
|
||||
})
|
||||
|
||||
// dashboard store commands that should be called.
|
||||
dashStore := &dashboards.FakeDashboardStore{}
|
||||
|
||||
dashboardFolderStore := foldertest.NewFakeFolderStore(t)
|
||||
|
||||
nestedFolderStore := NewFakeStore()
|
||||
nestedFolderStore.ExpectedError = folder.ErrFolderNotFound
|
||||
|
||||
folderSvc := setup(t, dashStore, dashboardFolderStore, nestedFolderStore, featuremgmt.WithFeatures("nestedFolders"), actest.FakeAccessControl{
|
||||
ExpectedEvaluate: true,
|
||||
})
|
||||
_, err := folderSvc.Get(context.Background(), &folder.GetFolderQuery{
|
||||
OrgID: orgID,
|
||||
ID: &folder.GeneralFolder.ID,
|
||||
SignedInUser: usr,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,12 @@ type Folder struct {
|
||||
HasACL bool
|
||||
}
|
||||
|
||||
var GeneralFolder = Folder{ID: 0, Title: "General"}
|
||||
|
||||
func (f *Folder) IsGeneral() bool {
|
||||
return f.ID == GeneralFolder.ID && f.Title == GeneralFolder.Title
|
||||
}
|
||||
|
||||
type FolderDTO struct {
|
||||
Folder
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user