From fdbe2d1796911ec0d8245b72b8423593efc26c9d Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Thu, 31 Aug 2023 16:46:36 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):?= =?UTF-8?q?=20=E9=A1=B9=E7=9B=AE=E6=88=90=E5=91=98=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E5=8F=8A=E6=9D=83=E9=99=90&=E7=BB=84?= =?UTF-8?q?=E7=BB=87=E5=88=97=E8=A1=A8SQL=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ProjectMemberController.java | 3 +- .../mapper/ExtProjectMemberMapper.java | 8 + .../project/mapper/ExtProjectMemberMapper.xml | 27 +++ .../project/service/ProjectMemberService.java | 186 ++++++++++++++---- .../ProjectMemberControllerTests.java | 78 ++++++-- .../system/mapper/ExtOrganizationMapper.java | 7 - .../system/mapper/ExtOrganizationMapper.xml | 33 ++-- 7 files changed, 258 insertions(+), 84 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 30df624023..5cf5f64715 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 @@ -20,7 +20,6 @@ import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; -import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -89,7 +88,7 @@ public class ProjectMemberController { @Operation(summary = "项目管理-成员-批量添加至用户组") @RequiresPermissions(PermissionConstants.PROJECT_MEMBER_UPDATE) public void addMemberRole(@RequestBody ProjectMemberAddRequest request) { - projectMemberService.addMemberRole(request, SessionUtils.getUserId()); + projectMemberService.addRole(request, SessionUtils.getUserId()); } @PostMapping("/batch/remove") diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectMemberMapper.java b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectMemberMapper.java index 72962dcdca..79ba49eeb4 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectMemberMapper.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectMemberMapper.java @@ -1,6 +1,7 @@ package io.metersphere.project.mapper; import io.metersphere.project.request.ProjectMemberRequest; +import io.metersphere.system.dto.UserExtend; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -17,4 +18,11 @@ public interface ExtProjectMemberMapper { * @return 成员列表及用户组关联信息 */ List listMember(@Param("request") ProjectMemberRequest request); + + /** + * 获取所有组织成员 + * @param organizationId 组织ID + * @return 成员 + */ + List getMemberByOrg(String organizationId); } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectMemberMapper.xml b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectMemberMapper.xml index 83bc64f43c..932f7f8398 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectMemberMapper.xml +++ b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectMemberMapper.xml @@ -12,6 +12,33 @@ or u.email like CONCAT('%', #{request.keyword},'%') or u.phone like CONCAT('%', #{request.keyword},'%')) + + + + + + + + + + + and urr.id in + + + + + + + \ No newline at end of file diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectMemberService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectMemberService.java index 5cf65d66c2..2201eb78fc 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectMemberService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectMemberService.java @@ -8,26 +8,31 @@ import io.metersphere.project.request.ProjectMemberAddRequest; import io.metersphere.project.request.ProjectMemberBatchDeleteRequest; import io.metersphere.project.request.ProjectMemberEditRequest; import io.metersphere.project.request.ProjectMemberRequest; +import io.metersphere.sdk.constants.HttpMethodConstants; import io.metersphere.sdk.constants.UserRoleEnum; import io.metersphere.sdk.constants.UserRoleType; +import io.metersphere.sdk.dto.LogDTO; import io.metersphere.sdk.dto.OptionDTO; import io.metersphere.sdk.exception.MSException; +import io.metersphere.sdk.log.constants.OperationLogModule; +import io.metersphere.sdk.log.constants.OperationLogType; +import io.metersphere.sdk.log.service.OperationLogService; import io.metersphere.sdk.mapper.BaseUserMapper; import io.metersphere.sdk.util.BeanUtils; +import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.Translator; import io.metersphere.system.domain.*; import io.metersphere.system.dto.UserExtend; -import io.metersphere.system.mapper.ExtOrganizationMapper; import io.metersphere.system.mapper.UserMapper; import io.metersphere.system.mapper.UserRoleMapper; import io.metersphere.system.mapper.UserRoleRelationMapper; -import io.metersphere.system.request.OrganizationRequest; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; /** @@ -48,9 +53,9 @@ public class ProjectMemberService { @Resource private ProjectMapper projectMapper; @Resource - private ExtOrganizationMapper extOrganizationMapper; - @Resource private ExtProjectMemberMapper extProjectMemberMapper; + @Resource + private OperationLogService operationLogService; /** * 获取成员列表 @@ -61,6 +66,9 @@ public class ProjectMemberService { public List listMember(ProjectMemberRequest request) { // 查询当前项目成员 List members = extProjectMemberMapper.listMember(request); + if (CollectionUtils.isEmpty(members)) { + return new ArrayList<>(); + } UserRoleRelationExample relationExample = new UserRoleRelationExample(); relationExample.createCriteria().andSourceIdEqualTo(request.getProjectId()).andUserIdIn(members); List userRoleRelates = userRoleRelationMapper.selectByExample(relationExample); @@ -101,7 +109,7 @@ public class ProjectMemberService { if (project == null) { return new ArrayList<>(); } - return extOrganizationMapper.getMemberByOrg(project.getOrganizationId()); + return extProjectMemberMapper.getMemberByOrg(project.getOrganizationId()); } /** @@ -125,38 +133,7 @@ public class ProjectMemberService { * @param currentUserId 当前用户ID */ public void addMember(ProjectMemberAddRequest request, String currentUserId) { - // 项目不存在, 则不添加 - checkProjectExist(request.getProjectId()); - // 获取已经存在的用户组 - UserRoleRelationExample example = new UserRoleRelationExample(); - example.createCriteria().andSourceIdEqualTo(request.getProjectId()) - .andUserIdIn(request.getUserIds()).andRoleIdIn(request.getRoleIds()); - List userRoleRelations = userRoleRelationMapper.selectByExample(example); - Map> existUserRelations = userRoleRelations.stream().collect( - Collectors.groupingBy(UserRoleRelation::getUserId, Collectors.mapping(UserRoleRelation::getRoleId, Collectors.toList()))); - // 比较用户组是否已经存在, 如果不存在则添加 - List relations = new ArrayList<>(); - request.getUserIds().forEach(userId -> request.getRoleIds().forEach(roleId -> { - // 用户不存在或用户组不存在, 则不添加 - if (isUserOrRoleNotExist(userId, roleId)) { - return; - } - // 如果该用户已经添加至该用户组, 则不再添加 - if (existUserRelations.containsKey(userId) && existUserRelations.get(userId).contains(roleId)) { - return; - } - UserRoleRelation relation = new UserRoleRelation(); - relation.setId(UUID.randomUUID().toString()); - relation.setUserId(userId); - relation.setRoleId(roleId); - relation.setSourceId(request.getProjectId()); - relation.setCreateTime(System.currentTimeMillis()); - relation.setCreateUser(currentUserId); - relations.add(relation); - })); - if (!CollectionUtils.isEmpty(relations)) { - userRoleRelationMapper.batchInsert(relations); - } + addMemberRole(request, currentUserId, OperationLogType.ADD.name(), "/project/member/add"); } /** @@ -166,12 +143,16 @@ public class ProjectMemberService { * @param currentUserId 当前用户ID */ public void updateMember(ProjectMemberEditRequest request, String currentUserId) { + // 操作记录 + List logs = new ArrayList<>(); // 项目不存在 checkProjectExist(request.getProjectId()); // 移除已经存在的用户组 UserRoleRelationExample example = new UserRoleRelationExample(); example.createCriteria().andSourceIdEqualTo(request.getProjectId()) .andUserIdEqualTo(request.getUserId()); + // 旧的用户组关系, 操作记录使用 + List oldRelations = userRoleRelationMapper.selectByExample(example); userRoleRelationMapper.deleteByExample(example); // 添加新的用户组 List relations = new ArrayList<>(); @@ -192,6 +173,19 @@ public class ProjectMemberService { if (!CollectionUtils.isEmpty(relations)) { userRoleRelationMapper.batchInsert(relations); } + // 操作记录 + UserRoleExample roleExample = new UserRoleExample(); + roleExample.createCriteria().andIdIn(request.getRoleIds()); + List newRoles = userRoleMapper.selectByExample(roleExample); + List oldRoles = new ArrayList<>(); + if (!CollectionUtils.isEmpty(oldRelations)) { + List oldRoleIds = oldRelations.stream().map(UserRoleRelation::getRoleId).toList(); + roleExample.clear(); + roleExample.createCriteria().andIdIn(oldRoleIds); + oldRoles = userRoleMapper.selectByExample(roleExample); + } + setLog(request.getProjectId(), request.getUserId(), currentUserId, OperationLogType.UPDATE.name(), "/project/member/update", HttpMethodConstants.POST.name(), oldRoles, newRoles, logs); + operationLogService.batchAdd(logs); } /** @@ -201,12 +195,17 @@ public class ProjectMemberService { * @param userId 用户ID */ public void removeMember(String projectId, String userId) { + // 操作记录 + List logs = new ArrayList<>(); // 项目不存在, 则不移除 checkProjectExist(projectId); // 移除成员, 则移除该成员在该项目下的所有用户组 UserRoleRelationExample example = new UserRoleRelationExample(); example.createCriteria().andSourceIdEqualTo(projectId).andUserIdEqualTo(userId); userRoleRelationMapper.deleteByExample(example); + // 操作记录 + setLog(projectId, userId, null, OperationLogType.DELETE.name(), "/project/member/remove", HttpMethodConstants.GET.name(), null, null, logs); + operationLogService.batchAdd(logs); } /** @@ -214,9 +213,71 @@ public class ProjectMemberService { * @param request 请求参数 * @param currentUserId 当前用户ID */ - public void addMemberRole(ProjectMemberAddRequest request, String currentUserId) { + public void addRole(ProjectMemberAddRequest request, String currentUserId) { // 添加用户用户组(已经添加的用户组不再添加) - addMember(request, currentUserId); + addMemberRole(request, currentUserId, OperationLogType.UPDATE.name(), "/project/member/add-role"); + } + + /** + * 处理成员及用户组关系, 并生成操作记录 + * + * @param request 请求参数 + * @param currentUserId 创建人 + * @param operationType 操作记录类型 + * @param path 操作记录路径 + */ + public void addMemberRole(ProjectMemberAddRequest request, String currentUserId, String operationType, String path) { + // 操作记录 + List logs = new ArrayList<>(); + // 项目不存在, 则不添加 + checkProjectExist(request.getProjectId()); + // 获取已经存在的用户组 + UserRoleRelationExample example = new UserRoleRelationExample(); + example.createCriteria().andSourceIdEqualTo(request.getProjectId()) + .andUserIdIn(request.getUserIds()).andRoleIdIn(request.getRoleIds()); + List userRoleRelations = userRoleRelationMapper.selectByExample(example); + Map> existUserRelations = userRoleRelations.stream().collect( + Collectors.groupingBy(UserRoleRelation::getUserId, Collectors.mapping(UserRoleRelation::getRoleId, Collectors.toList()))); + // 比较用户组是否已经存在, 如果不存在则添加 + List relations = new ArrayList<>(); + request.getUserIds().forEach(userId ->{ + AtomicBoolean isLog = new AtomicBoolean(false); + // 追加的用户组ID, 操作记录使用 + List roleIds = new ArrayList<>(); + request.getRoleIds().forEach(roleId -> { + // 用户不存在或用户组不存在, 则不添加 + if (isUserOrRoleNotExist(userId, roleId)) { + return; + } + // 如果该用户已经添加至该用户组, 则不再添加 + if (existUserRelations.containsKey(userId) && existUserRelations.get(userId).contains(roleId)) { + return; + } + UserRoleRelation relation = new UserRoleRelation(); + relation.setId(UUID.randomUUID().toString()); + relation.setUserId(userId); + relation.setRoleId(roleId); + relation.setSourceId(request.getProjectId()); + relation.setCreateTime(System.currentTimeMillis()); + relation.setCreateUser(currentUserId); + relations.add(relation); + isLog.set(true); + roleIds.add(roleId); + }); + // 成员添加操作记录 + if (isLog.get()) { + UserRoleExample roleExample = new UserRoleExample(); + roleExample.createCriteria().andIdIn(roleIds); + List userRoles = userRoleMapper.selectByExample(roleExample); + // 追加了哪些用户组 + setLog(request.getProjectId(), userId, currentUserId, operationType, path, HttpMethodConstants.POST.name(), null, userRoles, logs); + } + }); + if (!CollectionUtils.isEmpty(relations)) { + userRoleRelationMapper.batchInsert(relations); + } + // 操作记录 + operationLogService.batchAdd(logs); } /** @@ -224,6 +285,8 @@ public class ProjectMemberService { * @param request 请求参数 */ public void batchRemove(ProjectMemberBatchDeleteRequest request) { + // 操作记录 + List logs = new ArrayList<>(); // 项目不存在, 则不移除 checkProjectExist(request.getProjectId()); // 批量移除成员, 则移除该成员在该项目下的所有用户组 @@ -231,8 +294,18 @@ public class ProjectMemberService { example.createCriteria().andSourceIdEqualTo(request.getProjectId()) .andUserIdIn(request.getUserIds()); userRoleRelationMapper.deleteByExample(example); + // 操作记录 + request.getUserIds().forEach(userId -> { + // 操作记录 + setLog(request.getProjectId(), userId, null, OperationLogType.DELETE.name(), "/project/member/remove", HttpMethodConstants.GET.name(), null, null, logs); + }); + operationLogService.batchAdd(logs); } + /** + * 查看项目是否存在 + * @param projectId 项目ID + */ private void checkProjectExist(String projectId) { Project project = projectMapper.selectByPrimaryKey(projectId); if (project == null) { @@ -240,9 +313,44 @@ public class ProjectMemberService { } } + /** + * 查看用户或用户组是否存在 + * @param userId 用户ID + * @param roleId 用户组ID + * @return 是否存在 + */ private boolean isUserOrRoleNotExist(String userId, String roleId) { UserExample example = new UserExample(); example.createCriteria().andIdEqualTo(userId).andDeletedEqualTo(false); return userMapper.selectByExample(example) == null || userRoleMapper.selectByPrimaryKey(roleId) == null; } + + /** + * 操作记录 + * + * @param projectId 项目ID + * @param memberId 成员ID + * @param createUserId 创建用户 + * @param type 操作类型 + * @param path 路径 + * @param method 请求方法 + * @param logs 日志集合 + */ + private void setLog(String projectId, String memberId, String createUserId, String type, String path, String method, Object originalVal, Object modifiedVal, List logs) { + Project project = projectMapper.selectByPrimaryKey(projectId); + User user = userMapper.selectByPrimaryKey(memberId); + LogDTO dto = new LogDTO( + projectId, + project.getOrganizationId(), + memberId, + createUserId, + type, + OperationLogModule.PROJECT_MANAGEMENT_PERMISSION_MEMBER, + user.getName()); + dto.setPath(path); + dto.setMethod(method); + dto.setOriginalValue(JSON.toJSONBytes(originalVal)); + dto.setModifiedValue(JSON.toJSONBytes(modifiedVal)); + logs.add(dto); + } } 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 32ec16e984..72690cca16 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 @@ -6,8 +6,10 @@ import io.metersphere.project.request.ProjectMemberBatchDeleteRequest; import io.metersphere.project.request.ProjectMemberEditRequest; import io.metersphere.project.request.ProjectMemberRequest; import io.metersphere.sdk.base.BaseTest; +import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.SessionConstants; import io.metersphere.sdk.controller.handler.ResultHolder; +import io.metersphere.sdk.log.constants.OperationLogType; import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.Pager; import org.apache.commons.lang3.StringUtils; @@ -68,10 +70,24 @@ public class ProjectMemberControllerTests extends BaseTest { Assertions.assertTrue(StringUtils.contains(projectUserDTO.getName(), request.getKeyword()) || StringUtils.contains(projectUserDTO.getEmail(), request.getKeyword()) || StringUtils.contains(projectUserDTO.getPhone(), request.getKeyword())); + // 权限校验 + request.setProjectId(DEFAULT_PROJECT_ID); + requestPostPermissionTest(PermissionConstants.PROJECT_MEMBER_READ, LIST_MEMBER, request); } @Test @Order(2) + public void testListMemberEmpty() throws Exception { + // 空数据覆盖 + ProjectMemberRequest request = new ProjectMemberRequest(); + request.setProjectId("default-project-member-x"); + request.setCurrent(1); + request.setPageSize(10); + this.requestPost(LIST_MEMBER, request, status().isOk()); + } + + @Test + @Order(3) public void testListMemberError() throws Exception { // 页码有误 ProjectMemberRequest request = new ProjectMemberRequest(); @@ -86,31 +102,40 @@ public class ProjectMemberControllerTests extends BaseTest { } @Test - @Order(3) + @Order(4) public void testGetMemberOption() throws Exception { this.requestGet(GET_MEMBER + "/default-project-member-test", status().isOk()); // 覆盖空数据 this.requestGet(GET_MEMBER + "/default-project-member-x", status().isOk()); - } - - @Test - @Order(4) - public void testGetRoleOption() throws Exception { - this.requestGet(GET_ROLE + "/default-project-member-test", status().isOk()); + // 权限校验 + requestGetPermissionTest(PermissionConstants.PROJECT_MEMBER_ADD, GET_MEMBER + "/" + DEFAULT_PROJECT_ID); } @Test @Order(5) + public void testGetRoleOption() throws Exception { + this.requestGet(GET_ROLE + "/default-project-member-test", status().isOk()); + // 权限校验 + requestGetPermissionTest(PermissionConstants.PROJECT_MEMBER_ADD, GET_ROLE + "/" + DEFAULT_PROJECT_ID); + } + + @Test + @Order(6) public void testAddMemberSuccess() throws Exception { ProjectMemberAddRequest request = new ProjectMemberAddRequest(); request.setProjectId("default-project-member-test"); request.setUserIds(List.of("default-project-member-user-1", "default-project-member-user-del")); request.setRoleIds(List.of("project_admin", "project_admin_x", "project_member")); this.requestPost(ADD_MEMBER, request, status().isOk()); + // 日志 + checkLog("default-project-member-user-1", OperationLogType.ADD); + // 权限校验 + request.setProjectId(DEFAULT_PROJECT_ID); + requestPostPermissionTest(PermissionConstants.PROJECT_MEMBER_ADD, ADD_MEMBER, request); } @Test - @Order(6) + @Order(7) public void testAddMemberRepeat() throws Exception { ProjectMemberAddRequest request = new ProjectMemberAddRequest(); request.setProjectId("default-project-member-test"); @@ -120,7 +145,7 @@ public class ProjectMemberControllerTests extends BaseTest { } @Test - @Order(7) + @Order(8) public void testAddMemberError() throws Exception { ProjectMemberAddRequest request = new ProjectMemberAddRequest(); request.setProjectId("default-project-member-x"); @@ -130,7 +155,7 @@ public class ProjectMemberControllerTests extends BaseTest { } @Test - @Order(8) + @Order(9) public void testUpdateMemberSuccess() throws Exception { // 不存在的用户组 ProjectMemberEditRequest request = new ProjectMemberEditRequest(); @@ -141,10 +166,15 @@ public class ProjectMemberControllerTests extends BaseTest { // 存在的用户组 request.setRoleIds(List.of("project_admin", "project_member")); this.requestPost(UPDATE_MEMBER, request, status().isOk()); + // 日志 + checkLog("default-project-member-user-1", OperationLogType.UPDATE); + // 权限校验 + request.setProjectId(DEFAULT_PROJECT_ID); + requestPostPermissionTest(PermissionConstants.PROJECT_MEMBER_UPDATE, UPDATE_MEMBER, request); } @Test - @Order(9) + @Order(10) public void testUpdateMemberError() throws Exception { ProjectMemberEditRequest request = new ProjectMemberEditRequest(); request.setProjectId("default-project-member-x"); @@ -154,29 +184,38 @@ public class ProjectMemberControllerTests extends BaseTest { } @Test - @Order(10) + @Order(11) public void testRemoveMemberSuccess() throws Exception { this.requestGet(REMOVE_MEMBER + "/default-project-member-test/default-project-member-user-1", status().isOk()); + // 日志 + checkLog("default-project-member-user-1", OperationLogType.DELETE); + // 权限校验 + requestGetPermissionTest(PermissionConstants.PROJECT_MEMBER_DELETE, REMOVE_MEMBER + "/" + DEFAULT_PROJECT_ID + "/default-project-member-user-1"); } @Test - @Order(11) + @Order(12) public void testRemoveMemberError() throws Exception { this.requestGet(REMOVE_MEMBER + "/default-project-member-x/default-project-member-user-1", status().is5xxServerError()); } @Test - @Order(12) + @Order(13) public void testAddMemberRoleSuccess() throws Exception { ProjectMemberAddRequest request = new ProjectMemberAddRequest(); request.setProjectId("default-project-member-test"); request.setUserIds(List.of("default-project-member-user-1", "default-project-member-user-2")); request.setRoleIds(List.of("project_admin", "project_member")); this.requestPost(ADD_ROLE, request, status().isOk()); + // 日志 + checkLog("default-project-member-user-2", OperationLogType.UPDATE); + // 权限校验 + request.setProjectId(DEFAULT_PROJECT_ID); + requestPostPermissionTest(PermissionConstants.PROJECT_MEMBER_UPDATE, ADD_ROLE, request); } @Test - @Order(13) + @Order(14) public void testAddMemberRoleError() throws Exception { ProjectMemberAddRequest request = new ProjectMemberAddRequest(); request.setProjectId("default-project-member-x"); @@ -186,16 +225,21 @@ public class ProjectMemberControllerTests extends BaseTest { } @Test - @Order(14) + @Order(15) public void testBatchRemoveMemberSuccess() throws Exception { ProjectMemberBatchDeleteRequest request = new ProjectMemberBatchDeleteRequest(); request.setProjectId("default-project-member-test"); request.setUserIds(List.of("default-project-member-user-1", "default-project-member-user-2")); this.requestPost(BATCH_REMOVE_MEMBER, request, status().isOk()); + // 日志 + checkLog("default-project-member-user-1", OperationLogType.DELETE); + // 权限校验 + request.setProjectId(DEFAULT_PROJECT_ID); + requestPostPermissionTest(PermissionConstants.PROJECT_MEMBER_DELETE, BATCH_REMOVE_MEMBER, request); } @Test - @Order(15) + @Order(16) public void testBatchRemoveMember() throws Exception { ProjectMemberBatchDeleteRequest request = new ProjectMemberBatchDeleteRequest(); request.setProjectId("default-project-member-x"); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtOrganizationMapper.java b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtOrganizationMapper.java index 7607feae0f..6ab81103d1 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtOrganizationMapper.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtOrganizationMapper.java @@ -83,11 +83,4 @@ public interface ExtOrganizationMapper { * @return 组织下拉选项 */ List getOptionsByIds(@Param("ids") List ids); - - /** - * 获取所有组织成员 - * @param organizationId 组织ID - * @return 成员 - */ - List getMemberByOrg(String organizationId); } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtOrganizationMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtOrganizationMapper.xml index ca53ac5838..83b4aacb73 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtOrganizationMapper.xml +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtOrganizationMapper.xml @@ -1,15 +1,21 @@ - + select o.id, o.num, o.name, o.description, o.create_time, + o.update_time, o.create_user, o.deleted, o.delete_user, o.delete_time, o.enable, + coalesce(membercount, 0) as memberCount, coalesce(projectcount, 0) as projectCount + from organization o + left join ( + select source_id, count(distinct u.id) as membercount from user_role_relation ur + join user u on ur.user_id = u.id and u.deleted = 0 + group by source_id + ) as members_group on o.id = members_group.source_id + left join ( + select organization_id, count(project.id) as projectcount from project + group by organization_id + ) as projects_group on o.id = projects_group.organization_id - group by o.id - -