Skip to content

Refact: Added a private helper _visibility_and_status_filter#13627

Open
Sank-WoT wants to merge 19 commits intoinfiniflow:mainfrom
Sank-WoT:main
Open

Refact: Added a private helper _visibility_and_status_filter#13627
Sank-WoT wants to merge 19 commits intoinfiniflow:mainfrom
Sank-WoT:main

Conversation

@Sank-WoT
Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Added a private helper _visibility_and_status_filter(joined_tenant_ids, user_id) that returns the Peewee condition: visible to user (team or own) and status is VALID.

Type of change

  • Refactoring

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 16, 2026
@Sank-WoT Sank-WoT changed the title [Refactoring] Added a private helper _visibility_and_status_filter [Refactor] Added a private helper _visibility_and_status_filter Mar 16, 2026
@Sank-WoT
Copy link
Copy Markdown
Contributor Author

I added refactoring changes 1db5409

@Sank-WoT Sank-WoT changed the title [Refactor] Added a private helper _visibility_and_status_filter Refact: Added a private helper _visibility_and_status_filter Mar 19, 2026
@yingfeng yingfeng added the ci Continue Integration label Mar 27, 2026
@yingfeng yingfeng marked this pull request as draft March 27, 2026 01:48
@yingfeng yingfeng marked this pull request as ready for review March 27, 2026 01:48
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.72%. Comparing base (6e309f9) to head (a894efd).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13627      +/-   ##
==========================================
- Coverage   98.14%   96.72%   -1.43%     
==========================================
  Files          10       10              
  Lines         702      702              
  Branches      112      112              
==========================================
- Hits          689      679      -10     
- Misses          3        5       +2     
- Partials       10       18       +8     

☔ 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a private query helper on KnowledgebaseService to centralize the Peewee WHERE condition for “KB visible to user (team or own) AND status is VALID”, and refactors several query methods to reuse it.

Changes:

  • Added KnowledgebaseService._visibility_and_status_filter(joined_tenant_ids, user_id) to encapsulate visibility + StatusEnum.VALID filtering.
  • Refactored get_by_tenant_ids and get_list to reuse the helper instead of repeating the same condition.
  • Updated get_all_kb_by_tenant_ids to use the helper as well.

cls.model.tenant_id == user_id
)
)
kbs = cls.model.select(*fields).where(cls._visibility_and_status_filter(tenant_ids, user_id))
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

get_all_kb_by_tenant_ids previously returned all visible KBs regardless of status, but switching to _visibility_and_status_filter(...) now implicitly filters to StatusEnum.VALID. If this method is used for admin/debug flows (e.g., showing soft-deleted KBs), this changes behavior beyond a refactor—either keep the old semantics (separate visibility vs status helpers) or update the PR description/callers to reflect the intentional filtering.

Copilot uses AI. Check for mistakes.
Comment on lines +58 to +60
- Team KBs (`permission == TenantPermission.TEAM`) owned by any tenant in `joined_tenant_ids`
- KBs owned by the current user (`tenant_id == user_id`)
Always constrained to `StatusEnum.VALID`.
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

The helper docstring says permission == TenantPermission.TEAM, but the actual predicate compares against TenantPermission.TEAM.value. Please align the docstring with the real condition to avoid confusion for future callers.

Suggested change
- Team KBs (`permission == TenantPermission.TEAM`) owned by any tenant in `joined_tenant_ids`
- KBs owned by the current user (`tenant_id == user_id`)
Always constrained to `StatusEnum.VALID`.
- Team KBs (`permission == TenantPermission.TEAM.value`) owned by any tenant in `joined_tenant_ids`
- KBs owned by the current user (`tenant_id == user_id`)
Always constrained to `StatusEnum.VALID.value`.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants