Folders: Add max depth check with descendant to /apis (#115305)
This commit is contained in:
committed by
GitHub
parent
4164239f56
commit
2fbe2f77e3
@@ -726,19 +726,6 @@ func (s *Service) moveOnApiServer(ctx context.Context, cmd *folder.MoveFolderCom
|
||||
return nil, folder.ErrBadRequest.Errorf("k6 project may not be moved")
|
||||
}
|
||||
|
||||
f, err := s.unifiedStore.Get(ctx, folder.GetFolderQuery{
|
||||
UID: &cmd.UID,
|
||||
OrgID: cmd.OrgID,
|
||||
SignedInUser: cmd.SignedInUser,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if f != nil && f.ParentUID == accesscontrol.K6FolderUID {
|
||||
return nil, folder.ErrBadRequest.Errorf("k6 project may not be moved")
|
||||
}
|
||||
|
||||
// Check that the user is allowed to move the folder to the destination folder
|
||||
hasAccess, evalErr := s.canMoveViaApiServer(ctx, cmd)
|
||||
if evalErr != nil {
|
||||
@@ -748,30 +735,7 @@ func (s *Service) moveOnApiServer(ctx context.Context, cmd *folder.MoveFolderCom
|
||||
return nil, dashboards.ErrFolderAccessDenied
|
||||
}
|
||||
|
||||
// here we get the folder, we need to get the height of current folder
|
||||
// and the depth of the new parent folder, the sum can't bypass 8
|
||||
folderHeight, err := s.unifiedStore.GetHeight(ctx, cmd.UID, cmd.OrgID, &cmd.NewParentUID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
parents, err := s.unifiedStore.GetParents(ctx, folder.GetParentsQuery{UID: cmd.NewParentUID, OrgID: cmd.OrgID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// height of the folder that is being moved + this current folder itself + depth of the NewParent folder should be less than or equal MaxNestedFolderDepth
|
||||
if folderHeight+len(parents)+1 > folder.MaxNestedFolderDepth {
|
||||
return nil, folder.ErrMaximumDepthReached.Errorf("failed to move folder")
|
||||
}
|
||||
|
||||
for _, parent := range parents {
|
||||
// if the current folder is already a parent of newparent, we should return error
|
||||
if parent.UID == cmd.UID {
|
||||
return nil, folder.ErrCircularReference.Errorf("failed to move folder")
|
||||
}
|
||||
}
|
||||
|
||||
f, err = s.unifiedStore.Update(ctx, folder.UpdateFolderCommand{
|
||||
f, err := s.unifiedStore.Update(ctx, folder.UpdateFolderCommand{
|
||||
UID: cmd.UID,
|
||||
OrgID: cmd.OrgID,
|
||||
NewParentUID: &cmd.NewParentUID,
|
||||
|
||||
Reference in New Issue
Block a user