From df60bef5f6d60590b9372316cdd3b3c0a2efe263 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Thu, 18 Apr 2024 14:52:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E9=A1=B9=E7=9B=AE=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A1=B9=E7=9B=AE=E6=88=90=E5=91=98=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E7=A7=BB=E9=99=A4=E5=A4=B1=E8=B4=A5=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E7=94=A8=E4=BE=8B=E6=89=B9=E9=87=8F=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1039613 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001039613 --- .../functional/mapper/ExtCaseReviewMapper.xml | 4 +- .../mapper/ExtProjectUserRoleMapper.java | 5 ++- .../mapper/ExtProjectUserRoleMapper.xml | 38 +++++++++++++++++++ .../ProjectMemberBatchDeleteRequest.java | 10 +---- .../project/service/ProjectMemberService.java | 19 +++++++++- .../ProjectMemberControllerTests.java | 4 +- 6 files changed, 65 insertions(+), 15 deletions(-) diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewMapper.xml b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewMapper.xml index 3fa461e03d..2a574c94e2 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewMapper.xml +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewMapper.xml @@ -63,8 +63,8 @@ and ( - case_review.name like concat('%', #{request.keyword},'%') - or case_review.num like concat('%', #{request.keyword},'%') + case_review.name like concat('%', #{request.condition.keyword},'%') + or case_review.num like concat('%', #{request.condition.keyword},'%') ) diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectUserRoleMapper.java b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectUserRoleMapper.java index 6231f5f0d0..14b840a355 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectUserRoleMapper.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectUserRoleMapper.java @@ -1,11 +1,12 @@ package io.metersphere.project.mapper; import io.metersphere.project.dto.ProjectUserRoleDTO; +import io.metersphere.project.request.ProjectMemberBatchDeleteRequest; import io.metersphere.project.request.ProjectUserRoleMemberRequest; import io.metersphere.project.request.ProjectUserRoleRequest; -import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.domain.User; import io.metersphere.system.domain.UserRoleRelation; +import io.metersphere.system.dto.sdk.OptionDTO; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -55,4 +56,6 @@ public interface ExtProjectUserRoleMapper { * @return List */ List getProjectUserSelectList(@Param("projectId") String projectId, @Param("keyword") String keyword); + + ListgetProjectRoleMemberIds(@Param("request") ProjectMemberBatchDeleteRequest request); } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectUserRoleMapper.xml b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectUserRoleMapper.xml index 3e8b929abc..c561598bc6 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectUserRoleMapper.xml +++ b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectUserRoleMapper.xml @@ -63,4 +63,42 @@ order by u.update_time desc limit 100 + + + + + + and ( + u.name like concat('%', #{request.condition.keyword}, '%') + or u.email like concat('%', #{request.condition.keyword}, '%') + or u.phone like concat('%', #{request.condition.keyword}, '%') + ) + + + + + + + + + + + + + + and urr.role_id in + + + + + + + + \ No newline at end of file diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/request/ProjectMemberBatchDeleteRequest.java b/backend/services/project-management/src/main/java/io/metersphere/project/request/ProjectMemberBatchDeleteRequest.java index 4619eaf49a..e2d9feca1f 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/request/ProjectMemberBatchDeleteRequest.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/request/ProjectMemberBatchDeleteRequest.java @@ -1,26 +1,20 @@ package io.metersphere.project.request; +import io.metersphere.system.dto.table.TableBatchProcessDTO; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotEmpty; import lombok.Data; import lombok.EqualsAndHashCode; -import java.io.Serializable; -import java.util.List; - /** * @author song-cc-rock */ @Data @EqualsAndHashCode(callSuper = false) -public class ProjectMemberBatchDeleteRequest implements Serializable { +public class ProjectMemberBatchDeleteRequest extends TableBatchProcessDTO { @Schema(description = "项目ID", requiredMode = Schema.RequiredMode.REQUIRED) @NotBlank(message = "{project.id.not_blank}") private String projectId; - @Schema(description = "用户ID集合", requiredMode = Schema.RequiredMode.REQUIRED) - @NotEmpty(message = "{user.id.not_blank}") - private List userIds; } 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 f5ee0750a8..4e1e640955 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 @@ -3,6 +3,7 @@ package io.metersphere.project.service; import io.metersphere.project.domain.Project; import io.metersphere.project.dto.ProjectUserDTO; import io.metersphere.project.mapper.ExtProjectMemberMapper; +import io.metersphere.project.mapper.ExtProjectUserRoleMapper; import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.project.request.ProjectMemberAddRequest; import io.metersphere.project.request.ProjectMemberBatchDeleteRequest; @@ -56,6 +57,8 @@ public class ProjectMemberService { private ExtProjectMemberMapper extProjectMemberMapper; @Resource private OperationLogService operationLogService; + @Resource + private ExtProjectUserRoleMapper extProjectUserRoleMapper; /** * 获取成员列表 @@ -325,13 +328,25 @@ public class ProjectMemberService { List logs = new ArrayList<>(); // 项目不存在, 则不移除 checkProjectExist(request.getProjectId()); + if (!request.isSelectAll() && CollectionUtils.isEmpty(request.getSelectIds())) { + throw new MSException(Translator.get("user.not.empty")); + } // 批量移除成员, 则移除该成员在该项目下的所有用户组 + ListuserIds; + if (request.isSelectAll()) { + userIds = extProjectUserRoleMapper.getProjectRoleMemberIds(request); + if (!CollectionUtils.isEmpty(request.getExcludeIds())) { + userIds.removeAll(request.getExcludeIds()); + } + } else { + userIds = request.getSelectIds(); + } UserRoleRelationExample example = new UserRoleRelationExample(); example.createCriteria().andSourceIdEqualTo(request.getProjectId()) - .andUserIdIn(request.getUserIds()); + .andUserIdIn(userIds); userRoleRelationMapper.deleteByExample(example); // 操作记录 - request.getUserIds().forEach(userId -> { + userIds.forEach(userId -> { // 操作记录 setLog(request.getProjectId(), userId, currentUserId, OperationLogType.DELETE.name(), "/project/member/remove", HttpMethodConstants.GET.name(), null, null, logs); }); 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 f2da1accd0..7402f0f95c 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 @@ -227,7 +227,7 @@ public class ProjectMemberControllerTests extends BaseTest { 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")); + request.setSelectIds(List.of("default-project-member-user-1", "default-project-member-user-2")); this.requestPost(BATCH_REMOVE_MEMBER, request, status().isOk()); // 权限校验 request.setProjectId(DEFAULT_PROJECT_ID); @@ -239,7 +239,7 @@ public class ProjectMemberControllerTests extends BaseTest { public void testBatchRemoveMember() throws Exception { ProjectMemberBatchDeleteRequest request = new ProjectMemberBatchDeleteRequest(); request.setProjectId("default-project-member-x"); - request.setUserIds(List.of("default-project-member-user-1", "default-project-member-user-2")); + request.setSelectIds(List.of("default-project-member-user-1", "default-project-member-user-2")); this.requestPost(BATCH_REMOVE_MEMBER, request, status().is5xxServerError()); }