From 43394a1b282aacf74eac45348db016137ed0ee64 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Tue, 5 Sep 2023 15:01:44 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=BB=84=E7=BB=87=E7=AE=A1=E7=90=86):?= =?UTF-8?q?=20=E5=A2=9E=E5=8A=A0=E7=BB=84=E7=BB=87=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E6=B5=8B=E8=AF=95=E8=A6=86=E7=9B=96=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/service/OrganizationService.java | 10 ++++------ .../controller/OrganizationControllerTests.java | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationService.java index b1db77a9fa..ed9ef2ccbb 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationService.java @@ -299,12 +299,10 @@ public class OrganizationService { } Set userRoleIds = userIdRoleIdMap.get(orgUserExtend.getId()); - if (CollectionUtils.isNotEmpty(userRoleIds)){ - List userRoleFilters = userRoles.stream().filter(t -> userRoleIds.contains(t.getId())).toList(); - List userRoleList = new ArrayList<>(); - setUserRoleList(userRoleList, userRoleFilters); - orgUserExtend.setUserRoleIdNameMap(userRoleList); - } + List userRoleFilters = userRoles.stream().filter(t -> userRoleIds.contains(t.getId())).toList(); + List userRoleList = new ArrayList<>(); + setUserRoleList(userRoleList, userRoleFilters); + orgUserExtend.setUserRoleIdNameMap(userRoleList); } return orgUserExtends; diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationControllerTests.java index 0890acccf3..adda35766e 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationControllerTests.java @@ -224,6 +224,11 @@ public class OrganizationControllerTests extends BaseTest { organizationMemberRequest.setMemberIds(Arrays.asList("sys_default_user", "sys_default_user2")); organizationMemberRequest.setProjectIds(Arrays.asList("sys_org_projectId2", "sys_org_projectId3")); this.requestPost(ORGANIZATION_PROJECT_ADD_MEMBER, organizationMemberRequest, status().isOk()); + organizationMemberRequest = new OrgMemberExtendProjectRequest(); + organizationMemberRequest.setOrganizationId("sys_default_organization_3"); + organizationMemberRequest.setMemberIds(Arrays.asList("sys_default_user")); + organizationMemberRequest.setProjectIds(Arrays.asList("sys_org_projectId2")); + this.requestPost(ORGANIZATION_PROJECT_ADD_MEMBER, organizationMemberRequest, status().isOk()); // 批量添加成员成功后, 验证是否添加成功 listByKeyWord("testUserOne", "sys_default_organization_3", false, InternalUserRole.PROJECT_MEMBER.getValue(), "sys_org_projectId2", false, null, null); } @@ -250,6 +255,8 @@ public class OrganizationControllerTests extends BaseTest { organizationMemberRequest.setUserRoleIds(Arrays.asList("sys_default_org_role_id_3")); this.requestPost(ORGANIZATION_LIST_ADD_MEMBER, organizationMemberRequest, status().isOk()); listByKeyWord("testUserThree", "sys_default_organization_3", false, null, null, false, null, null); + listByKeyWord(null, "sys_default_organization_3", false, null, null, false, null, null); + } @Test @@ -488,9 +495,11 @@ public class OrganizationControllerTests extends BaseTest { Assertions.assertTrue(JSON.parseArray(JSON.toJSONString(pageData.getList())).size() <= organizationRequest.getPageSize()); // 返回值中取出第一条数据, 并判断是否包含关键字admin OrgUserExtend orgUserExtend = JSON.parseArray(JSON.toJSONString(pageData.getList()), OrgUserExtend.class).get(0); - Assertions.assertTrue(StringUtils.contains(orgUserExtend.getName(), organizationRequest.getKeyword()) - || StringUtils.contains(orgUserExtend.getEmail(), organizationRequest.getKeyword()) - || StringUtils.contains(orgUserExtend.getPhone(), organizationRequest.getKeyword())); + if (StringUtils.isNotBlank(keyWord)) { + Assertions.assertTrue(StringUtils.contains(orgUserExtend.getName(), organizationRequest.getKeyword()) + || StringUtils.contains(orgUserExtend.getEmail(), organizationRequest.getKeyword()) + || StringUtils.contains(orgUserExtend.getPhone(), organizationRequest.getKeyword())); + } if (compare) { Assertions.assertNotNull(orgUserExtend.getUserRoleIdNameMap()); List userRoleIds = orgUserExtend.getUserRoleIdNameMap().stream().map(IdNameStructureDTO::getId).toList();