Implement folder move restrictions in file explorer and backend; prevent moving a folder into itself or its own subfolder.

This commit is contained in:
Leon Bösche
2026-01-14 18:26:02 +01:00
parent 0f2aa9c49f
commit 453b60032c
2 changed files with 58 additions and 2 deletions

View File

@@ -1464,6 +1464,20 @@ func moveOrgFileHandler(w http.ResponseWriter, r *http.Request, db *database.DB,
return
}
// Prevent moving a folder into itself or its own subfolders
if sourceFile.Type == "folder" {
// Check if trying to move into itself
if req.SourcePath == req.TargetPath {
errors.WriteError(w, errors.CodeInvalidArgument, "Cannot move a folder into itself", http.StatusBadRequest)
return
}
// Check if target is a subfolder of source
if strings.HasPrefix(req.TargetPath, req.SourcePath+"/") {
errors.WriteError(w, errors.CodeInvalidArgument, "Cannot move a folder into its own subfolder", http.StatusBadRequest)
return
}
}
// Determine new file name - check if target is a folder
var newPath string
var targetFile *database.File
@@ -1670,6 +1684,20 @@ func moveUserFileHandler(w http.ResponseWriter, r *http.Request, db *database.DB
return
}
// Prevent moving a folder into itself or its own subfolders
if sourceFile.Type == "folder" {
// Check if trying to move into itself
if req.SourcePath == req.TargetPath {
errors.WriteError(w, errors.CodeInvalidArgument, "Cannot move a folder into itself", http.StatusBadRequest)
return
}
// Check if target is a subfolder of source
if strings.HasPrefix(req.TargetPath, req.SourcePath+"/") {
errors.WriteError(w, errors.CodeInvalidArgument, "Cannot move a folder into its own subfolder", http.StatusBadRequest)
return
}
}
// Determine new file name - check if target is a folder
var newPath string
var targetFile *database.File