Repository navigation
Revert "fix(api): infer /documents/{id}/download Content-Type from filename when ext is omitted (#15052)" - #15138
Conversation
…lename w…" This reverts commit 889b5f0.
📝 WalkthroughWalkthroughThe PR simplifies the ChangesExtension Resolution Simplification
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
api/apps/restful_apis/document_api.py (1)
1880-1893:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winCritical:
download_attachmentis missing theDocumentService.accessibleauthorization check after the revert.
- In
api/apps/restful_apis/document_api.py(download_attachment, ~lines 1872-1890), the handler directly loads from storage (settings.STORAGE_IMPL.get(tenant_id, doc_id)) with noDocumentService.accessible(doc_id, current_user.id)/DocumentService.get_by_id(...)validation, even though the docstring claims it mirrors the preview endpoint’s authorization model.- The preview endpoint still enforces
if not DocumentService.accessible(doc_id, current_user.id): ..., and PR#15053added theaccessible+get_by_idpattern for the download route, but it’s absent in the current code.🤖 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/restful_apis/document_api.py` around lines 1880 - 1893, The download_attachment handler currently fetches raw data via settings.STORAGE_IMPL.get(tenant_id, doc_id) without authorization; update the function (download_attachment) to first call DocumentService.accessible(doc_id, current_user.id) and if accessible is True call DocumentService.get_by_id(doc_id, tenant_id) (or the existing get_by_id pattern used by preview) to validate ownership/permissions before calling settings.STORAGE_IMPL.get; preserve the existing ext, make_response, and apply_safe_file_response_headers flow but return an unauthorized/forbidden response when DocumentService.accessible returns False and only proceed to storage retrieval when get_by_id succeeds.
🤖 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.
Outside diff comments:
In `@api/apps/restful_apis/document_api.py`:
- Around line 1880-1893: The download_attachment handler currently fetches raw
data via settings.STORAGE_IMPL.get(tenant_id, doc_id) without authorization;
update the function (download_attachment) to first call
DocumentService.accessible(doc_id, current_user.id) and if accessible is True
call DocumentService.get_by_id(doc_id, tenant_id) (or the existing get_by_id
pattern used by preview) to validate ownership/permissions before calling
settings.STORAGE_IMPL.get; preserve the existing ext, make_response, and
apply_safe_file_response_headers flow but return an unauthorized/forbidden
response when DocumentService.accessible returns False and only proceed to
storage retrieval when get_by_id succeeds.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: dd51bc1e-4a0e-466f-9a2b-17e5c7720cec
📒 Files selected for processing (2)
api/apps/restful_apis/document_api.pytest/testcases/test_web_api/test_document_app/test_document_metadata.py
💤 Files with no reviewable changes (1)
- test/testcases/test_web_api/test_document_app/test_document_metadata.py
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15138 +/- ##
==========================================
- Coverage 94.53% 93.12% -1.41%
==========================================
Files 10 10
Lines 713 713
Branches 116 116
==========================================
- Hits 674 664 -10
- Misses 25 29 +4
- Partials 14 20 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Reverts #15053