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

@@ -1456,11 +1456,39 @@ class _FileExplorerState extends State<FileExplorer> {
);
},
onAcceptWithDetails: (draggedFile) {
final sourcePath = draggedFile.data.path;
final targetPath = file.path;
// Prevent dragging a folder into itself
if (sourcePath == targetPath) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
'Cannot move a folder into itself',
),
),
);
return;
}
// Prevent dragging a folder into its own subfolder
if (targetPath.startsWith('$sourcePath/') ||
targetPath.startsWith('$sourcePath\\')) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
'Cannot move a folder into its own subfolder',
),
),
);
return;
}
context.read<FileBrowserBloc>().add(
MoveFile(
orgId: widget.orgId,
sourcePath: draggedFile.data.path,
targetPath: file.path,
sourcePath: sourcePath,
targetPath: targetPath,
),
);
},