Repository navigation
Fix: move file check - #14681
Fix: move file check#14681
Conversation
📝 WalkthroughWalkthroughThe ChangesFolder Move Validation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@api/apps/services/file_api_service.py`:
- Around line 510-520: In move_files, add process logging for the early
rejection cases: when a file in files is the same folder as dest_folder
(currently returning "Cannot move a folder to itself.") and when a source folder
is an ancestor of dest_folder (currently returning "Cannot move a folder into
its own subfolder."); use the same logger used elsewhere in this module (e.g.,
processLogger or module logger) to emit an info/warn log that includes the
source folder id(s) and the destination folder id before each return; reference
the variables files, dest_folder, FileType, and
FileService.get_all_parent_folders to construct messages like "Reject move:
source_folder_id=<id> dest_folder_id=<id> reason=<...>" so both rejection paths
are logged for traceability.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: fdde969e-390a-479c-a0b9-4a3e7e58e441
📒 Files selected for processing (1)
api/apps/services/file_api_service.py
| if dest_folder: | ||
| for file in files: | ||
| if file.type == FileType.FOLDER.value and file.id == dest_folder.id: | ||
| return False, "Cannot move a folder to itself." | ||
| # Check if any source folder is an ancestor of the destination folder | ||
| # to prevent infinite recursion in _move_entry_recursive | ||
| dest_ancestors = FileService.get_all_parent_folders(dest_folder.id) | ||
| dest_ancestor_ids = {f.id for f in dest_ancestors} | ||
| for file in files: | ||
| if file.type == FileType.FOLDER.value and file.id in dest_ancestor_ids: | ||
| return False, "Cannot move a folder into its own subfolder." |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Add logs for the new rejection paths in move_files.
These new early returns are a new flow and should log the rejection reason (source folder ID + destination folder ID) to improve traceability in production.
Proposed patch
if dest_folder:
for file in files:
if file.type == FileType.FOLDER.value and file.id == dest_folder.id:
+ logging.warning(
+ "Rejected move: folder cannot be moved into itself (source_id=%s, dest_id=%s)",
+ file.id,
+ dest_folder.id,
+ )
return False, "Cannot move a folder to itself."
# Check if any source folder is an ancestor of the destination folder
# to prevent infinite recursion in _move_entry_recursive
dest_ancestors = FileService.get_all_parent_folders(dest_folder.id)
dest_ancestor_ids = {f.id for f in dest_ancestors}
for file in files:
if file.type == FileType.FOLDER.value and file.id in dest_ancestor_ids:
+ logging.warning(
+ "Rejected move: folder cannot be moved into its own subfolder (source_id=%s, dest_id=%s)",
+ file.id,
+ dest_folder.id,
+ )
return False, "Cannot move a folder into its own subfolder."
As per coding guidelines, **/*.py: Add logging for new flows.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@api/apps/services/file_api_service.py` around lines 510 - 520, In move_files,
add process logging for the early rejection cases: when a file in files is the
same folder as dest_folder (currently returning "Cannot move a folder to
itself.") and when a source folder is an ancestor of dest_folder (currently
returning "Cannot move a folder into its own subfolder."); use the same logger
used elsewhere in this module (e.g., processLogger or module logger) to emit an
info/warn log that includes the source folder id(s) and the destination folder
id before each return; reference the variables files, dest_folder, FileType, and
FileService.get_all_parent_folders to construct messages like "Reject move:
source_folder_id=<id> dest_folder_id=<id> reason=<...>" so both rejection paths
are logged for traceability.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14681 +/- ##
=======================================
Coverage 94.16% 94.16%
=======================================
Files 10 10
Lines 703 703
Branches 112 112
=======================================
Hits 662 662
Misses 25 25
Partials 16 16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
### What problem does this PR solve? Restrict file move operations: prevent moving a folder to itself or to one of its own subfolders. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
### What problem does this PR solve? Restrict file move operations: prevent moving a folder to itself or to one of its own subfolders. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
What problem does this PR solve?
Restrict file move operations: prevent moving a folder to itself or to one of its own subfolders.
Type of change