Implement folder move restrictions in file explorer and backend; prevent moving a folder into itself or its own subfolder.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user