mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Nested Folders: More API fixes (#59316)
* Nested Folder: Fix create, use camel case for JSON properties * Fix get parents if the folder does not exist * Add store test for get parents
This commit is contained in:
committed by
GitHub
parent
5a3f0e8696
commit
f5c41ea497
@@ -3,6 +3,7 @@ package folderimpl
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
@@ -517,7 +518,7 @@ func (s *Service) nestedFolderCreate(ctx context.Context, cmd *folder.CreateFold
|
||||
func (s *Service) validateParent(ctx context.Context, orgID int64, parentUID string) error {
|
||||
ancestors, err := s.store.GetParents(ctx, folder.GetParentsQuery{UID: parentUID, OrgID: orgID})
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed to get parents: %w", err)
|
||||
}
|
||||
|
||||
if len(ancestors) == folder.MaxNestedFolderDepth {
|
||||
|
||||
@@ -201,6 +201,13 @@ func (ss *sqlStore) GetParents(ctx context.Context, q folder.GetParentsQuery) ([
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(folders) < 1 {
|
||||
// the query is expected to return at least the same folder
|
||||
// if it's empty it means that the folder does not exist
|
||||
return nil, folder.ErrFolderNotFound
|
||||
}
|
||||
|
||||
return util.Reverse(folders[1:]), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -397,6 +397,11 @@ func TestIntegrationGetParents(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("get parents of unknown folder should return an error", func(t *testing.T) {
|
||||
_, err := folderStore.GetParents(context.Background(), folder.GetParentsQuery{})
|
||||
require.ErrorIs(t, err, folder.ErrFolderNotFound)
|
||||
})
|
||||
|
||||
t.Run("get parents of 1-st level folder should be empty", func(t *testing.T) {
|
||||
parents, err := folderStore.GetParents(context.Background(), folder.GetParentsQuery{
|
||||
UID: f.UID,
|
||||
|
||||
@@ -66,7 +66,7 @@ type CreateFolderCommand struct {
|
||||
OrgID int64 `json:"-"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
ParentUID string `json:"parent_uid"`
|
||||
ParentUID string `json:"parentUid"`
|
||||
|
||||
SignedInUser *user.SignedInUser `json:"-"`
|
||||
}
|
||||
@@ -86,7 +86,7 @@ type UpdateFolderCommand struct {
|
||||
// to move a folder.
|
||||
type MoveFolderCommand struct {
|
||||
UID string `json:"uid"`
|
||||
NewParentUID string `json:"new_parent_uid"`
|
||||
NewParentUID string `json:"newParentUid"`
|
||||
OrgID int64 `json:"-"`
|
||||
|
||||
SignedInUser *user.SignedInUser `json:"-"`
|
||||
|
||||
Reference in New Issue
Block a user