Folders: Add validation that folder is not a parent of itself (#101569)

This commit is contained in:
Stephanie Hingtgen
2025-03-04 13:56:21 -06:00
committed by GitHub
parent e933f7cf01
commit 7c35d741ba
5 changed files with 54 additions and 6 deletions
@@ -39,6 +39,10 @@ func (ss *FolderStoreImpl) Create(ctx context.Context, cmd folder.CreateFolderCo
return nil, folder.ErrBadRequest.Errorf("missing UID")
}
if cmd.UID == cmd.ParentUID {
return nil, folder.ErrFolderCannotBeParentOfItself
}
var foldr *folder.Folder
/*
version := 1
@@ -60,6 +60,18 @@ func TestIntegrationCreate(t *testing.T) {
require.Error(t, err)
})
t.Run("creating a folder with itself as a parent should fail", func(t *testing.T) {
uid := util.GenerateShortUID()
_, err := folderStore.Create(context.Background(), folder.CreateFolderCommand{
Title: folderTitle,
OrgID: orgID,
ParentUID: uid,
Description: folderDsc,
UID: uid,
})
require.ErrorIs(t, err, folder.ErrFolderCannotBeParentOfItself)
})
t.Run("creating a folder without providing a parent should default to the empty parent folder", func(t *testing.T) {
uid := util.GenerateShortUID()
f, err := folderStore.Create(context.Background(), folder.CreateFolderCommand{