From e54a2a4f9b5f13b36ff986b32cd83242fb28a2b5 Mon Sep 17 00:00:00 2001 From: VampireAchao Date: Mon, 9 Sep 2024 17:09:56 +0800 Subject: [PATCH 1/2] [Fix] fix data-permission namespace problem --- .../apache/shenyu/admin/model/dto/NamespaceDTO.java | 6 ++++-- .../admin/service/impl/DataPermissionServiceImpl.java | 11 +++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/NamespaceDTO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/NamespaceDTO.java index b3de304f2bd5..ea4eebef8ea0 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/NamespaceDTO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/NamespaceDTO.java @@ -19,6 +19,8 @@ import jakarta.validation.constraints.Max; import jakarta.validation.constraints.NotNull; +import org.hibernate.validator.constraints.Length; + import java.io.Serializable; /** @@ -36,14 +38,14 @@ public class NamespaceDTO implements Serializable { /** * namespace name. */ - @Max(value = 255, message = "The maximum length is 255") + @Length(max = 255, message = "The maximum length is 255") @NotNull(message = "namespace name not null") private String name; /** * namespace description. */ - @Max(value = 255, message = "The maximum length is 255") + @Length(max = 255, message = "The maximum length is 255") @NotNull(message = "namespace description not null") private String description; diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DataPermissionServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DataPermissionServiceImpl.java index 61910be24766..7dd9e1a82cd5 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DataPermissionServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DataPermissionServiceImpl.java @@ -164,10 +164,13 @@ public CommonPager listSelectorsByPage(final SelectorQuery if (totalCount > 0) { Supplier> selectorDOStreamSupplier = () -> selectorMapper.selectByQuery(selectorQuery).stream(); List selectorIds = selectorDOStreamSupplier.get().map(SelectorDO::getId).collect(Collectors.toList()); - - Set hasDataPermissionSelectorIds = new HashSet<>(dataPermissionMapper.selectDataIds(selectorIds, - userId, AdminDataPermissionTypeEnum.SELECTOR.ordinal())); - + + Set hasDataPermissionSelectorIds = new HashSet<>(); + if (!selectorIds.isEmpty()){ + hasDataPermissionSelectorIds.addAll(dataPermissionMapper.selectDataIds(selectorIds, + userId, AdminDataPermissionTypeEnum.SELECTOR.ordinal())); + } + selectorList = selectorDOStreamSupplier.get().map(selectorDO -> { boolean isChecked = hasDataPermissionSelectorIds.contains(selectorDO.getId()); return DataPermissionPageVO.buildPageVOBySelector(selectorDO, isChecked); From abcfe2764eaf64d4662cd0cb98e24c3ec8de2a42 Mon Sep 17 00:00:00 2001 From: VampireAchao Date: Mon, 9 Sep 2024 17:51:55 +0800 Subject: [PATCH 2/2] [style] fix code style for ci follow checkstyle --- .../java/org/apache/shenyu/admin/model/dto/NamespaceDTO.java | 1 - .../shenyu/admin/service/impl/DataPermissionServiceImpl.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/NamespaceDTO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/NamespaceDTO.java index ea4eebef8ea0..870b7bccaf73 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/NamespaceDTO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/NamespaceDTO.java @@ -17,7 +17,6 @@ package org.apache.shenyu.admin.model.dto; -import jakarta.validation.constraints.Max; import jakarta.validation.constraints.NotNull; import org.hibernate.validator.constraints.Length; diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DataPermissionServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DataPermissionServiceImpl.java index 7dd9e1a82cd5..0eac55aae5cd 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DataPermissionServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DataPermissionServiceImpl.java @@ -166,7 +166,7 @@ public CommonPager listSelectorsByPage(final SelectorQuery List selectorIds = selectorDOStreamSupplier.get().map(SelectorDO::getId).collect(Collectors.toList()); Set hasDataPermissionSelectorIds = new HashSet<>(); - if (!selectorIds.isEmpty()){ + if (!selectorIds.isEmpty()) { hasDataPermissionSelectorIds.addAll(dataPermissionMapper.selectDataIds(selectorIds, userId, AdminDataPermissionTypeEnum.SELECTOR.ordinal())); }