Folders: Add validation that folder is not a parent of itself (#101569)
This commit is contained in:
@@ -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{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package folder
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@@ -20,6 +21,7 @@ var ErrInternal = errutil.Internal("folder.internal")
|
||||
var ErrCircularReference = errutil.BadRequest("folder.circular-reference", errutil.WithPublicMessage("Circular reference detected"))
|
||||
var ErrTargetRegistrySrvConflict = errutil.Internal("folder.target-registry-srv-conflict")
|
||||
var ErrFolderNotEmpty = errutil.BadRequest("folder.not-empty", errutil.WithPublicMessage("Folder cannot be deleted: folder is not empty"))
|
||||
var ErrFolderCannotBeParentOfItself = errors.New("folder cannot be parent of itself")
|
||||
|
||||
const (
|
||||
GeneralFolderUID = "general"
|
||||
|
||||
Reference in New Issue
Block a user