This is an automated email from the ASF dual-hosted git repository.
Aias00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 8fee975cd0 fix(admin): scope rule enable/disable to the request
namespace (#7525)
8fee975cd0 is described below
commit 8fee975cd03800f526d034dae003fb3b77469ac6
Author: Sean-Walker0 <[email protected]>
AuthorDate: Sat Oct 10 09:18:56 2026 +0800
fix(admin): scope rule enable/disable to the request namespace (#7525)
enabledByIdsAndNamespaceId accepted a namespaceId but never used it:
each id was loaded with the unscoped selectById and toggled directly,
so a request for one namespace could enable or disable rules
belonging to another namespace. The sibling delete path already
filters by namespace (selectByIdsAndNamespaceId) before acting.
Skip ids whose rule is missing or belongs to another namespace.
Regression test toggles one own and one foreign rule and asserts only
the own one reaches updateEnable (red on the previous code, which
toggled both).
Co-authored-by: Sean-Walker0
<[email protected]>
---
.../shenyu/admin/service/impl/RuleServiceImpl.java | 4 ++++
.../apache/shenyu/admin/service/RuleServiceTest.java | 19 +++++++++++++++++++
2 files changed, 23 insertions(+)
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java
index 460bfa777e..5e835604bd 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java
@@ -425,6 +425,10 @@ public class RuleServiceImpl implements RuleService {
public Boolean enabledByIdsAndNamespaceId(final List<String> ids, final
Boolean enabled, final String namespaceId) {
ids.forEach(id -> {
RuleDO ruleDO = ruleMapper.selectById(id);
+ if (Objects.isNull(ruleDO) ||
!Objects.equals(ruleDO.getNamespaceId(), namespaceId)) {
+ // the rule does not belong to the request namespace; skip it
+ return;
+ }
RuleDO before = JsonUtils.jsonToObject(JsonUtils.toJson(ruleDO),
RuleDO.class);
ruleDO.setEnabled(enabled);
if (ruleMapper.updateEnable(id, enabled) > 0) {
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java
index a4f222397c..6999eae704 100644
---
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java
@@ -635,4 +635,23 @@ public final class RuleServiceTest {
ruleConditionQuery.setRuleId("123");
return ruleConditionQuery;
}
+
+ @Test
+ public void enabledByIdsAndNamespaceIdSkipsForeignRules() {
+ RuleDO own = new RuleDO();
+ own.setId("rule-own");
+ own.setNamespaceId("ns-a");
+ RuleDO foreign = new RuleDO();
+ foreign.setId("rule-foreign");
+ foreign.setNamespaceId("ns-b");
+ when(ruleMapper.selectById("rule-own")).thenReturn(own);
+ when(ruleMapper.selectById("rule-foreign")).thenReturn(foreign);
+ when(ruleMapper.updateEnable(anyString(), any())).thenReturn(1);
+
when(ruleConditionMapper.selectByQuery(any())).thenReturn(Collections.emptyList());
+
+ ruleService.enabledByIdsAndNamespaceId(Arrays.asList("rule-own",
"rule-foreign"), false, "ns-a");
+
+ verify(ruleMapper).updateEnable("rule-own", false);
+ verify(ruleMapper, never()).updateEnable("rule-foreign", false);
+ }
}