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 26350ad1fc fix(admin): scope selector enable/disable to the request 
namespace (#7524)
26350ad1fc is described below

commit 26350ad1fcaf35d73881bb867bad2ed1b673969b
Author: Sean-Walker0 <[email protected]>
AuthorDate: Sat Oct 10 09:31:15 2026 +0800

    fix(admin): scope selector enable/disable to the request namespace (#7524)
    
    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 selectors
    belonging to another namespace. The sibling delete path already
    filters by namespace before acting.
    
    Skip ids whose selector is missing or belongs to another namespace,
    mirroring the deleteByIdsAndNamespaceId behavior. Regression test
    toggles one own and one foreign selector and asserts only the own one
    reaches updateEnable (red on the previous code, which toggled both).
    
    Co-authored-by: Sean-Walker0 
<[email protected]>
---
 .../admin/service/impl/SelectorServiceImpl.java    |  4 ++++
 .../shenyu/admin/service/SelectorServiceTest.java  | 25 ++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java
index 0b373de389..466cd4314f 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java
@@ -626,6 +626,10 @@ public class SelectorServiceImpl implements 
SelectorService {
     public Boolean enabledByIdsAndNamespaceId(final List<String> ids, final 
Boolean enabled, final String namespaceId) {
         ids.forEach(id -> {
             SelectorDO selectorDO = selectorMapper.selectById(id);
+            if (Objects.isNull(selectorDO) || 
!Objects.equals(selectorDO.getNamespaceId(), namespaceId)) {
+                // the selector does not belong to the request namespace; skip 
it
+                return;
+            }
             SelectorDO before = 
JsonUtils.jsonToObject(JsonUtils.toJson(selectorDO), SelectorDO.class);
             selectorDO.setEnabled(enabled);
             if (selectorMapper.updateEnable(id, enabled) > 0) {
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SelectorServiceTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SelectorServiceTest.java
index c2d5557d75..65cf361621 100644
--- 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SelectorServiceTest.java
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SelectorServiceTest.java
@@ -473,4 +473,29 @@ public final class SelectorServiceTest {
         metaDataRegisterDTO.setRpcType("test");
         return metaDataRegisterDTO;
     }
+
+    @Test
+    public void enabledByIdsAndNamespaceIdSkipsForeignSelectors() {
+        SelectorDO own = new SelectorDO();
+        own.setId("sel-own");
+        own.setNamespaceId("ns-a");
+        own.setPluginId("plugin-1");
+        SelectorDO foreign = new SelectorDO();
+        foreign.setId("sel-foreign");
+        foreign.setNamespaceId("ns-b");
+        foreign.setPluginId("plugin-1");
+        when(selectorMapper.selectById("sel-own")).thenReturn(own);
+        when(selectorMapper.selectById("sel-foreign")).thenReturn(foreign);
+        when(selectorMapper.updateEnable(anyString(), any())).thenReturn(1);
+        
when(selectorConditionMapper.selectByQuery(any())).thenReturn(Collections.emptyList());
+        PluginDO pluginDO = new PluginDO();
+        pluginDO.setId("plugin-1");
+        pluginDO.setName("tcp");
+        when(pluginMapper.selectById(anyString())).thenReturn(pluginDO);
+
+        selectorService.enabledByIdsAndNamespaceId(Arrays.asList("sel-own", 
"sel-foreign"), false, "ns-a");
+
+        verify(selectorMapper).updateEnable("sel-own", false);
+        verify(selectorMapper, never()).updateEnable("sel-foreign", false);
+    }
 }

Reply via email to