Skip to content

Add tenant query filtering in TenantInterceptor via OnQuery - #95

Draft
nygula with Copilot wants to merge 3 commits into
masterfrom
copilot/add-tenant-interceptor-query-filter
Draft

Add tenant query filtering in TenantInterceptor via OnQuery#95
nygula with Copilot wants to merge 3 commits into
masterfrom
copilot/add-tenant-interceptor-query-filter

Conversation

Copilot AI commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

TenantInterceptor only handled create/validate flows, so tenant-scoped entities were not consistently filtered during query construction. This change adds query-time tenant condition injection at the interceptor layer so tenant filtering is applied automatically for registered entities implementing ITenantScope.

  • Interceptor query-path fix

    • Added OnQuery(IEntityFactory, Expression?, QueryAction) to TenantInterceptor.
    • Normalizes incoming where (including null) and appends tenant constraints through existing ApplyTenant(factory) logic.
    • Keeps behavior centralized in interceptor pipeline instead of relying on manual ApplyTenant calls in business code.
  • Focused coverage for tenant query behavior

    • Added tests in TenantContextTests for:
      • auto-adding tenant filter when tenant context exists,
      • merging tenant filter with existing query predicates,
      • no-op when tenant context is absent.
protected override XCode.Expression? OnQuery(IEntityFactory factory, XCode.Expression? where, QueryAction action)
{
    return (where & XCode.Expression.Empty).ApplyTenant(factory);
}

Copilot AI linked an issue Aug 14, 2026 that may be closed by this pull request
Co-authored-by: nygula <13066114+nygula@users.noreply.github.com>
@nygula

nygula commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

须加测如下场景 : 1.有租户 + 已有whereexpression的情况 是否自动过滤 2. 有租户.纯FindAll() Find()等无whereexpression的情况 是否空查询也过滤 3. tennatid=0的情况 是否可见全部 4. 未设置租户上下文的情况 是否会报错 @copilot

Copilot AI changed the title [WIP] Add query filter to TenantInterceptor Add tenant query filtering in TenantInterceptor via OnQuery Aug 14, 2026
Copilot AI requested a review from nygula August 14, 2026 03:54
Co-authored-by: nygula <13066114+nygula@users.noreply.github.com>

Copilot AI commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

须加测如下场景 : 1.有租户 + 已有whereexpression的情况 是否自动过滤 2. 有租户.纯FindAll() Find()等无whereexpression的情况 是否空查询也过滤 3. tennatid=0的情况 ...

已补充你提到的四类场景测试并提交到 45a634a

  1. 有租户 + 已有 WhereExpression 自动合并租户条件;
  2. 有租户 + FindAll()/Find() 空条件查询自动加租户过滤;
  3. TenantId=0 时不过滤(可见全部);
  4. 未设置租户上下文时不报错。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

租户拦截过滤器缺少查询相关

3 participants