From c620387da1dab891ac91d03df95c5468f269731e Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Mon, 7 Aug 2023 18:38:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BB=84=E7=BB=87=E9=A1=B9=E7=9B=AE=E6=88=90?= =?UTF-8?q?=E5=91=98=E4=B8=8B=E6=8B=89=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/controller/UserController.java | 11 +++++++++++ .../java/io/metersphere/system/dto/UserExtend.java | 5 +++++ .../io/metersphere/system/mapper/ExtUserMapper.java | 10 ++++++++++ .../io/metersphere/system/mapper/ExtUserMapper.xml | 9 +++++++++ .../system/service/OrganizationService.java | 4 ++-- .../io/metersphere/system/service/UserService.java | 8 ++++++++ .../SystemOrganizationControllerTests.java | 13 +++++++++++++ 7 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserMapper.java create mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserMapper.xml diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserController.java index bb5f95a78c..53e0acc398 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserController.java @@ -14,6 +14,7 @@ import io.metersphere.sdk.util.Pager; import io.metersphere.sdk.util.SessionUtils; import io.metersphere.system.domain.User; import io.metersphere.system.dto.UserBatchCreateDTO; +import io.metersphere.system.dto.UserExtend; import io.metersphere.system.dto.UserRoleOption; import io.metersphere.system.dto.request.UserChangeEnableRequest; import io.metersphere.system.dto.request.UserEditRequest; @@ -25,6 +26,8 @@ import io.metersphere.system.service.UserService; import io.metersphere.validation.groups.Created; import io.metersphere.validation.groups.Updated; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Schema; import jakarta.annotation.Resource; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authz.annotation.Logical; @@ -118,4 +121,12 @@ public class UserController { userService.resetPassword(userId, SessionUtils.getUserId()); return true; } + + @GetMapping("/get-option/{sourceId}") + @Operation(summary = "系统-组织及项目, 获取用户下拉选项") + @RequiresPermissions(value = {PermissionConstants.SYSTEM_USER_READ}) + @Parameter(name = "sourceId", description = "组织ID或项目ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED)) + public List getMemberOption(@PathVariable String sourceId) { + return userService.getMemberOption(sourceId); + } } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/UserExtend.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/UserExtend.java index 8750d5b6c3..beb9c30d2f 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/UserExtend.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/UserExtend.java @@ -15,4 +15,9 @@ public class UserExtend extends User { * 是否管理员(组织, 项目) */ private boolean adminFlag; + + /** + * 是否成员(组织, 项目) + */ + private boolean memberFlag; } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserMapper.java b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserMapper.java new file mode 100644 index 0000000000..de9e08c460 --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserMapper.java @@ -0,0 +1,10 @@ +package io.metersphere.system.mapper; + +import io.metersphere.system.dto.UserExtend; + +import java.util.List; + +public interface ExtUserMapper { + + List getMemberOption(String sourceId); +} diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserMapper.xml new file mode 100644 index 0000000000..b3746744d2 --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserMapper.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file 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 f3285db925..a7bcd43e00 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 @@ -166,9 +166,9 @@ public class OrganizationService { if (userMap.get(userId) == null) { throw new MSException(Translator.get("user.not.exist") + ", id: " + userId); } - //组织用户成员关系已存在, 不再重复添加 + //组织用户关系已存在, 不再重复添加 UserRoleRelationExample example = new UserRoleRelationExample(); - example.createCriteria().andSourceIdEqualTo(organizationId).andUserIdEqualTo(userId).andRoleIdEqualTo(InternalUserRole.ORG_MEMBER.getValue()); + example.createCriteria().andSourceIdEqualTo(organizationId).andUserIdEqualTo(userId); if (userRoleRelationMapper.countByExample(example) > 0) { continue; } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserService.java index af40c3e352..ea8f1d8c3a 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserService.java @@ -17,6 +17,7 @@ import io.metersphere.system.domain.User; import io.metersphere.system.domain.UserExample; import io.metersphere.system.dto.UserBatchCreateDTO; import io.metersphere.system.dto.UserCreateInfo; +import io.metersphere.system.dto.UserExtend; import io.metersphere.system.dto.excel.UserExcel; import io.metersphere.system.dto.excel.UserExcelRowDTO; import io.metersphere.system.dto.request.UserChangeEnableRequest; @@ -24,6 +25,7 @@ import io.metersphere.system.dto.request.UserEditRequest; import io.metersphere.system.dto.response.UserBatchProcessResponse; import io.metersphere.system.dto.response.UserImportResponse; import io.metersphere.system.dto.response.UserTableResponse; +import io.metersphere.system.mapper.ExtUserMapper; import io.metersphere.system.mapper.UserMapper; import io.metersphere.system.utils.UserImportEventListener; import jakarta.annotation.Resource; @@ -55,6 +57,8 @@ public class UserService { @Resource private UserMapper userMapper; @Resource + private ExtUserMapper extUserMapper; + @Resource private UserRoleRelationService userRoleRelationService; @Resource private OperationLogService operationLogService; @@ -378,6 +382,10 @@ public class UserService { return userMapper.selectByExample(example); } + public List getMemberOption(String sourceId) { + return extUserMapper.getMemberOption(sourceId); + } + public void resetPassword(String userId, String operator) { User user = userMapper.selectByPrimaryKey(userId); if (user == null) { diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemOrganizationControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemOrganizationControllerTests.java index 3f096a0c2a..96d6a5fe60 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemOrganizationControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemOrganizationControllerTests.java @@ -48,6 +48,7 @@ public class SystemOrganizationControllerTests extends BaseTest{ public static final String ORGANIZATION_ADD_MEMBER = "/system/organization/add-member"; public static final String ORGANIZATION_REMOVE_MEMBER = "/system/organization/remove-member"; public static final String ORGANIZATION_LIST_PROJECT = "/system/organization/list-project"; + public static final String ORGANIZATION_MEMBER_OPTION = "/system/user/get-option"; @Test @Order(0) @@ -400,7 +401,19 @@ public class SystemOrganizationControllerTests extends BaseTest{ this.requestPost(ORGANIZATION_DEFAULT, null, status().isMethodNotAllowed()); } + @Test + @Order(16) + public void testGetOrganizationMemberOption() throws Exception { + MvcResult mvcResult = this.responseGet(SystemOrganizationControllerTests.ORGANIZATION_MEMBER_OPTION + "/default-organization-2"); + // 获取返回值 + String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); + // 返回请求正常 + Assertions.assertNotNull(resultHolder); + // 权限校验 + requestGetPermissionTest(PermissionConstants.SYSTEM_USER_READ, SystemOrganizationControllerTests.ORGANIZATION_MEMBER_OPTION + "/default-organization-2"); + } private void requestPost(String url, Object param, ResultMatcher resultMatcher) throws Exception { mockMvc.perform(MockMvcRequestBuilders.post(url)