← Back to Pull requests

fix(admin): scope namespace plugin enable to the request namespace #8029

Merged
Duansg merged 4 files (48 lines) on Oct 25, 2026 01:08 UTC
View on GitHub
Duansg Duansg commented on Oct 23, 2026 05:45 UTC
Author

Modifications

POST /namespacePlugin/enabled receives a BatchCommonDTO that carries namespaceId, but the controller forwarded only the ids: enabled(ids, enabled) loaded the relations with the unscoped selectByIds and updated them with updateEnableByIdList (WHERE id IN (...)), so a request for one namespace could enable or disable another namespace's plugin relations. The onEnabled event then synced the change to that namespace's gateways. #7571 fixed the same issue for batch delete.

The namespaceId is now passed through the service signature, and the loaded relations are filtered to the request namespace before updating and publishing, mirroring #7571:

List<NamespacePluginVO> namespacePluginVOList = namespacePluginRelMapper.selectByIds(ids).stream()
        .filter(vo -> Objects.equals(vo.getNamespaceId(), namespaceId))
        .toList();
...
namespacePluginRelMapper.updateEnableByIdList(ListUtil.map(namespacePluginVOList, NamespacePluginVO::getId), enabled);

If no relation remains after filtering, the method returns the existing SYS_PLUGIN_ID_NOT_EXIST error.

Verifying this change

  • New NamespacePluginServiceTest#testEnabledScopedToRequestNamespace: enables one own (namespace-a) and one foreign (namespace-b) relation for namespace-a, and asserts only the own id reaches updateEnableByIdList and only the own VO is published to onEnabled.

  • New NamespacePluginServiceTest#testEnabledRejectsForeignNamespaceOnly: a foreign-only request returns SYS_PLUGIN_ID_NOT_EXIST with no update and no event.

  • ./mvnw -pl shenyu-admin test -Dtest='NamespacePluginServiceTest,NamespacePluginController*': NamespacePluginServiceTest 13/13, NamespacePluginControllerTest 1/1, related mapper/event/publisher tests green; checkstyle clean.
  • Notes

  • Performance: query count is unchanged (one selectByIds, one updateEnableByIdList). The only addition is an in-memory filter over the already-loaded list. No SQL or mapper changes.

  • Compatibility: the dashboard (namespacePlugin/updateEn) already sends namespaceId in the request body, so normal use is unchanged. A direct API call without namespaceId now gets SYS_PLUGIN_ID_NOT_EXIST instead of a global update, which is the unscoped path this PR closes.

  • Scope: /enabledByNamespace was already scoped in SQL and is untouched. @NotEmpty was not added to BatchCommonDTO#namespaceId, because PluginController, AppAuthController and SelectorController share that DTO.

  • The Notes in #7571 described /enabled as taking a "plain BatchCommonDTO, no namespace field"; the DTO does carry namespaceId, and this PR applies the same scoping to it.
  • Make sure that:

  • You have read the contribution guidelines.

  • You submit test cases (unit or integration tests) that back your changes.

  • Your local test passed ./mvnw clean install -Dmaven.javadoc.skip=true
  • Diff: 48 lines (+43 / -5) across 4 files Reviewer: Aias00 Review duration: 2603m
    All Vouch review confidence checks passed
    Residual risk 0.04 = Change Risk (0.31) × (1 − Review Confidence (0.89)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.31 · 48 lines diff across 4 files
    0.31
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.97 · 2 substantive comment(s)
    0.97
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    88%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.233
    Real PR Conversation Timeline
    4 items
    Aias00 Aias00 approved these changes on Oct 23, 2026 06:13 UTC
    Approved Reviewer

    LGTM. The enable path is now scoped to the request namespace, which matches the delete path already merged.

    Checked:

  • BatchCommonDTO.namespaceId exists, so the controller signature change is safe.

  • updateEnableByIdList now receives the filtered id list instead of the raw request ids, so foreign-namespace relations are never mutated.

  • Objects and ListUtil are already imported in NamespacePluginServiceImpl.

  • Both new tests cover the mixed case and the foreign-only rejection.
  • One non-blocking note: when the request mixes own and foreign ids the call silently applies to the owned subset. That is consistent with deleteNamespacePlugin, so fine as is.

    Aias00 Aias00 commented on Oct 23, 2026 14:20 UTC
    Contributor

    Approved this earlier, but the checks are still red on a failure that is not yours.

    build (shenyu-integrated-test-http) fails in CachePluginTest, and it is not caused by this PR:

    [ERROR] CachePluginTest.testMemoryModle:54 expected: <true> but was: <false>
    [ERROR] CachePluginTest.testRedisModle:73  expected: <true> but was: <false>
    [ERROR] Tests run: 103, Failures: 2, Errors: 0, Skipped: 5
    

    The same two cases are red on every other PR that touches this module right now, so this is the shared e2e case rather than your change. build is only an aggregate gate, so a single shared case turns the whole check red.

    Could you keep this rebased and re-run once the http e2e case is fixed upstream? Nothing else blocks my approval.

    Aias00 Aias00 commented on Oct 24, 2026 07:49 UTC
    Contributor

    @Duansg This PR is approved, but 11 checks are red: build (shenyu-integrated-test-websocket), build (shenyu-integrated-test-sdk-http), build (shenyu-integrated-test-combination), build (shenyu-integrated-test-tracing) (+7 more).

    I inspected these lanes today and they fail for infrastructure reasons rather than on the diff — the integrated-test jobs die while starting their containers (Elasticsearch /_cat/health returning 000 until the job is cancelled), and the http lane also hits the known CachePluginTest.testMemoryModle / testRedisModle flake. The same jobs are red on master and on unrelated PRs right now.

    Please rebase onto master and push (or ask for a re-run) so the checks execute again. If a case is still failing on a fresh run, paste the test name and I'll look properly.

    Reviewers
    Assignees
    Duansg Duansg
    Labels
    risk: low confidence: 88.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 30.7% (LOW) · Higher = larger blast radius
    30.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 88.5% · Lower = rushed or shallow review
    88.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 3.5% · Safe to merge
    3.5%
    Repository