From 695c26d6d3210628fe06b755b7203ac47e793087 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Tue, 3 Sep 2024 14:35:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=B3=BB=E7=BB=9F):=20=E7=B3=BB=E7=BB=9F-?= =?UTF-8?q?=E7=BB=84=E7=BB=87=E4=B8=8E=E9=A1=B9=E7=9B=AE-=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=88=90=E5=91=98=E5=88=97=E8=A1=A8=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=88=90=E5=91=98=E7=94=A8=E6=88=B7=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ProjectMemberController.java | 10 +++++++++- .../ProjectMemberControllerTests.java | 18 ++++++++++++++++++ .../mapper/ExtUserRoleRelationMapper.java | 2 ++ .../mapper/ExtUserRoleRelationMapper.xml | 15 +++++++++++++++ .../system/service/SystemProjectService.java | 18 +++++++++++++++++- 5 files changed, 61 insertions(+), 2 deletions(-) diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectMemberController.java b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectMemberController.java index 8b40528b6a..14ef5242e8 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectMemberController.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectMemberController.java @@ -57,7 +57,7 @@ public class ProjectMemberController { @CheckOwner(resourceId = "#projectId", resourceType = "project") public List getMemberOption(@PathVariable String projectId, @Schema(description = "查询关键字,根据邮箱和用户名查询") - @RequestParam(value = "keyword", required = false) String keyword) { + @RequestParam(value = "keyword", required = false) String keyword) { return projectMemberService.getMemberOption(projectId, keyword); } @@ -125,4 +125,12 @@ public class ProjectMemberController { public List selectCommentUser(@PathVariable String projectId, @RequestParam(value = "keyword", required = false) String keyword) { return projectMemberService.selectCommentUser(projectId, keyword); } + + @PostMapping("/update-member") + @Operation(summary = "系统设置-系统-组织与项-项目-更新成员用户组") + @RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_MEMBER_UPDATE) + @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") + public void updateProjectMemberRole(@RequestBody ProjectMemberEditRequest request) { + projectMemberService.updateMember(request, SessionUtils.getUserId()); + } } diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectMemberControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectMemberControllerTests.java index d46812f5a8..ffd3490c88 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectMemberControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectMemberControllerTests.java @@ -43,6 +43,7 @@ public class ProjectMemberControllerTests extends BaseTest { public static final String ADD_ROLE = "/project/member/add-role"; public static final String BATCH_REMOVE_MEMBER = "/project/member/batch/remove"; public static final String COMMENT_USER_OPTION = "/project/member/comment/user-option"; + public static final String UPDATE_MEMBER_ROLE = "/project/member/update-member"; @Test @Order(1) @@ -301,4 +302,21 @@ public class ProjectMemberControllerTests extends BaseTest { .andExpect(resultMatcher) .andExpect(content().contentType(MediaType.APPLICATION_JSON)); } + + @Test + @Order(18) + public void testUpdateMemberRole() throws Exception { + // 不存在的用户组 + ProjectMemberEditRequest request = new ProjectMemberEditRequest(); + request.setProjectId("default-project-member-test"); + request.setUserId("default-project-member-user-1"); + request.setRoleIds(List.of("project_admin_x")); + this.requestPost(UPDATE_MEMBER, request, status().isOk()); + // 存在的用户组 + request.setRoleIds(List.of("project_admin", "project_member")); + this.requestPost(UPDATE_MEMBER, request, status().isOk()); + // 权限校验 + request.setProjectId(DEFAULT_PROJECT_ID); + requestPostPermissionTest(PermissionConstants.PROJECT_USER_UPDATE, UPDATE_MEMBER, request); + } } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserRoleRelationMapper.java b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserRoleRelationMapper.java index 461c7a408f..3727aaa170 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserRoleRelationMapper.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserRoleRelationMapper.java @@ -18,4 +18,6 @@ public interface ExtUserRoleRelationMapper { List listGlobal(@Param("request") GlobalUserRoleRelationQueryRequest request); List selectUserRoleByUserIds(@Param("userIds") List userIds, @Param("orgId") String orgId); + + List selectProjectUserRoleByUserIds(@Param("userIds") List userIds, @Param("projectId") String projectId); } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserRoleRelationMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserRoleRelationMapper.xml index 957cf7c116..e71169e5f2 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserRoleRelationMapper.xml +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserRoleRelationMapper.xml @@ -62,4 +62,19 @@ and organization_id = #{orgId} and source_id = #{orgId} + + \ No newline at end of file diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/SystemProjectService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/SystemProjectService.java index fdcb6766ff..4794afed8c 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/SystemProjectService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/SystemProjectService.java @@ -10,11 +10,13 @@ import io.metersphere.system.dto.*; import io.metersphere.system.dto.request.*; import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.user.UserExtendDTO; +import io.metersphere.system.dto.user.UserRoleOptionDto; import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.dto.LogDTO; import io.metersphere.system.log.service.OperationLogService; import io.metersphere.system.mapper.ExtSystemProjectMapper; +import io.metersphere.system.mapper.ExtUserRoleRelationMapper; import io.metersphere.system.mapper.UserRoleRelationMapper; import io.metersphere.system.uid.IDGenerator; import jakarta.annotation.Resource; @@ -26,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; @Service @Transactional(rollbackFor = Exception.class) @@ -41,6 +44,8 @@ public class SystemProjectService { private UserRoleRelationMapper userRoleRelationMapper; @Resource private OperationLogService operationLogService; + @Resource + private ExtUserRoleRelationMapper extUserRoleRelationMapper; private final static String PREFIX = "/system/project"; private final static String ADD_PROJECT = PREFIX + "/add"; @@ -74,7 +79,18 @@ public class SystemProjectService { } public List getProjectMember(ProjectMemberRequest request) { - return extSystemProjectMapper.getProjectMemberList(request); + List memberList = extSystemProjectMapper.getProjectMemberList(request); + if (CollectionUtils.isNotEmpty(memberList)) { + List userIds = memberList.stream().map(UserExtendDTO::getId).toList(); + List userRole = extUserRoleRelationMapper.selectProjectUserRoleByUserIds(userIds, request.getProjectId()); + Map> roleMap = userRole.stream().collect(Collectors.groupingBy(UserRoleOptionDto::getUserId)); + memberList.forEach(user -> { + if (roleMap.containsKey(user.getId())) { + user.setUserRoleList(roleMap.get(user.getId())); + } + }); + } + return memberList; } /***