Skip to content

Revert "fix(api): infer /documents/{id}/download Content-Type from filename when ext is omitted (#15052)" - #15138

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
buua436:revert-15053-fix/15052-download-content-type
May 22, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
buua436:revert-15053-fix/15052-download-content-type

Conversation

@buua436

@buua436 buua436 commented May 22, 2026

Copy link
Copy Markdown
Contributor

Reverts #15053

@coderabbitai

coderabbitai Bot commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR simplifies the download_attachment endpoint's file extension and content-type resolution. The endpoint now defaults the ext query parameter to "markdown" and computes content-type directly from a static mapping, removing prior logic that validated document accessibility and derived the extension from stored metadata. Corresponding test cases covering the removed filename-inference path are deleted.

Changes

Extension Resolution Simplification

Layer / File(s) Summary
Extension parameter and content-type resolution
api/apps/restful_apis/document_api.py, test/testcases/test_web_api/test_document_app/test_document_metadata.py
The download_attachment endpoint now defaults ext to "markdown" when not provided and derives content_type directly from CONTENT_TYPE_MAP or application/{ext}, removing prior document record lookups. Test coverage for filename-based inference when ext is absent is removed, and a redundant monkeypatch in another test is deleted.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • infiniflow/ragflow#15053: Both PRs modify the download_attachment endpoint's extension resolution logic around the ext query parameter, with this PR simplifying to direct parameter defaults while the related PR infers from stored document filename.

Suggested labels

size:S

Poem

🐰 A simpler path the download takes,
No metadata lookups to make,
Just "markdown" by default it speaks,
Content-type maps do the work for weeks! 📄✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is minimal and does not follow the required template; it lacks sections for problem statement, change type, and rationale. Add required sections: explain what problem this revert solves, select the appropriate change type (e.g., Bug Fix), and provide context for why the prior fix is being reverted.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically identifies the main change—reverting a prior fix for Content-Type inference—making it immediately understandable to reviewers scanning the history.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@buua436
buua436 marked this pull request as ready for review May 22, 2026 03:12
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label May 22, 2026
@buua436 buua436 added the ci Continue Integration label May 22, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Critical: download_attachment is missing the DocumentService.accessible authorization 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 no DocumentService.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 #15053 added the accessible + get_by_id pattern 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

📥 Commits

Reviewing files that changed from the base of the PR and between 57ddd79 and 9c13e3e.

📒 Files selected for processing (2)
  • api/apps/restful_apis/document_api.py
  • test/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

@buua436
buua436 marked this pull request as draft May 22, 2026 03:17
@buua436
buua436 marked this pull request as ready for review May 22, 2026 03:17
@codecov

codecov Bot commented May 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.12%. Comparing base (57ddd79) to head (9c13e3e).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wangq8
wangq8 merged commit ea1764a into infiniflow:main May 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants