From de74dac4b89d9d16fa5146baede30b475c8c16c6 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Sun, 4 Feb 2024 14:55:06 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=94=A8=E4=BE=8B=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=89=B9=E9=87=8F=E9=87=8D=E6=96=B0=E8=AF=84?= =?UTF-8?q?=E5=AE=A1=E6=97=B6=EF=BC=8C=E5=A4=9A=E4=BA=BA=E8=AF=84=E5=AE=A1?= =?UTF-8?q?=E8=A7=84=E5=88=99=E7=9A=84=E7=94=A8=E4=BE=8B=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CaseReviewFunctionalCaseController.java | 6 +- .../CaseReviewFunctionalCaseService.java | 19 ++++- ...seReviewFunctionalCaseControllerTests.java | 71 +++++++++++++++---- .../dml/init_review_functional_case_test.sql | 4 +- 4 files changed, 84 insertions(+), 16 deletions(-) diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/CaseReviewFunctionalCaseController.java b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/CaseReviewFunctionalCaseController.java index 8f95eee296..335d93d994 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/CaseReviewFunctionalCaseController.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/CaseReviewFunctionalCaseController.java @@ -21,6 +21,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; +import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -85,6 +86,7 @@ public class CaseReviewFunctionalCaseController { @PostMapping("/batch/disassociate") @Operation(summary = "用例管理-用例评审-评审列表-评审详情-列表-批量取消关联用例") + @RequiresPermissions(PermissionConstants.CASE_REVIEW_RELEVANCE) @Log(type = OperationLogType.DISASSOCIATE, expression = "#msClass.batchDisassociateCaseLog(#request)", msClass = CaseReviewLogService.class) @CheckOwner(resourceId = "#request.getReviewId()", resourceType = "case_review") public void batchDisassociate(@Validated @RequestBody BaseReviewCaseBatchRequest request) { @@ -101,15 +103,17 @@ public class CaseReviewFunctionalCaseController { @PostMapping("/batch/review") @Operation(summary = "用例管理-用例评审-评审列表-评审详情-列表-批量评审") - @RequiresPermissions(PermissionConstants.CASE_REVIEW_REVIEW) + @RequiresPermissions(value = {PermissionConstants.CASE_REVIEW_REVIEW, PermissionConstants.CASE_REVIEW_READ_UPDATE}, logical = Logical.OR) @CheckOwner(resourceId = "#request.getReviewId()", resourceType = "case_review") public void batchReview(@Validated @RequestBody BatchReviewFunctionalCaseRequest request) { caseReviewFunctionalCaseService.batchReview(request, SessionUtils.getUserId()); } + @PostMapping("/batch/edit/reviewers") @Operation(summary = "用例管理-用例评审-评审列表-评审详情-列表-批量修改评审人") @CheckOwner(resourceId = "#request.getReviewId()", resourceType = "case_review") + @RequiresPermissions(PermissionConstants.CASE_REVIEW_READ_UPDATE) public void batchEditReviewUser(@Validated @RequestBody BatchEditReviewerRequest request) { caseReviewFunctionalCaseService.batchEditReviewUser(request, SessionUtils.getUserId()); } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewFunctionalCaseService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewFunctionalCaseService.java index 4fa9680c12..96eeb6d366 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewFunctionalCaseService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewFunctionalCaseService.java @@ -16,8 +16,10 @@ import io.metersphere.project.domain.ProjectVersion; import io.metersphere.project.dto.ModuleCountDTO; import io.metersphere.project.mapper.ExtBaseProjectVersionMapper; import io.metersphere.project.mapper.ProjectApplicationMapper; +import io.metersphere.project.service.PermissionCheckService; import io.metersphere.provider.BaseCaseProvider; import io.metersphere.sdk.constants.InternalUserRole; +import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.ProjectApplicationType; import io.metersphere.sdk.constants.UserRoleScope; import io.metersphere.sdk.exception.MSException; @@ -94,6 +96,10 @@ public class CaseReviewFunctionalCaseService { private CaseReviewUserMapper caseReviewUserMapper; @Resource private UserRoleRelationMapper userRoleRelationMapper; + @Resource + private PermissionCheckService permissionCheckService; + @Resource + private CaseReviewMapper caseReviewMapper; private static final String CASE_MODULE_COUNT_ALL = "all"; @@ -325,7 +331,12 @@ public class CaseReviewFunctionalCaseService { */ public void batchReview(BatchReviewFunctionalCaseRequest request, String userId) { String reviewId = request.getReviewId(); - + CaseReview caseReview = caseReviewMapper.selectByPrimaryKey(reviewId); + request.setReviewPassRule(caseReview.getReviewPassRule()); + //检查权限 + if (!permissionCheckService.userHasProjectPermission(userId, caseReview.getProjectId(), PermissionConstants.CASE_REVIEW_READ_UPDATE) && StringUtils.equalsIgnoreCase(request.getStatus(), FunctionalCaseReviewStatus.RE_REVIEWED.toString()) ) { + throw new MSException("http_result_forbidden"); + } List caseReviewFunctionalCaseList = doCaseReviewFunctionalCases(request); if(CollectionUtils.isEmpty(caseReviewFunctionalCaseList)) { return; @@ -379,7 +390,7 @@ public class CaseReviewFunctionalCaseService { } else { caseHistoryMap.get(caseId).add(caseReviewHistory); } - //根据评审规则更新用例评审和功能用例关系表中的状态 1.单人评审直接更新评审结果 2.多人评审需要计算 + //根据评审规则更新用例评审和功能用例关系表中的状态 1.单人评审直接更新评审结果 2.多人评审需要计算 3.如果是重新评审,直接全部变成重新评审 setStatus(request, caseReviewFunctionalCase, caseHistoryMap, reviewerMap, isAdmin); statusMap.put(caseReviewFunctionalCase.getCaseId(), caseReviewFunctionalCase.getStatus()); caseReviewFunctionalCaseMapper.updateByPrimaryKeySelective(caseReviewFunctionalCase); @@ -419,6 +430,10 @@ public class CaseReviewFunctionalCaseService { private static void setStatus(BatchReviewFunctionalCaseRequest request, CaseReviewFunctionalCase caseReviewFunctionalCase, Map> caseHistoryMap, Map> reviewerMap, boolean isAdmin) { + if (StringUtils.equalsIgnoreCase(request.getStatus(), FunctionalCaseReviewStatus.RE_REVIEWED.toString())) { + caseReviewFunctionalCase.setStatus(request.getStatus()); + return; + } if (StringUtils.equals(request.getReviewPassRule(), CaseReviewPassRule.SINGLE.toString())) { if (!StringUtils.equalsIgnoreCase(request.getStatus(), FunctionalCaseReviewStatus.UNDER_REVIEWED.toString()) && !isAdmin) { caseReviewFunctionalCase.setStatus(request.getStatus()); diff --git a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewFunctionalCaseControllerTests.java b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewFunctionalCaseControllerTests.java index 68cee76b39..9338e642ee 100644 --- a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewFunctionalCaseControllerTests.java +++ b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewFunctionalCaseControllerTests.java @@ -259,13 +259,66 @@ public class CaseReviewFunctionalCaseControllerTests extends BaseTest { public void testBatchReview() throws Exception { BatchReviewFunctionalCaseRequest request = new BatchReviewFunctionalCaseRequest(); - request.setReviewId("wx_review_id_1"); + request.setReviewId("wx_review_id_3"); request.setReviewPassRule(CaseReviewPassRule.MULTIPLE.toString()); - request.setStatus(FunctionalCaseReviewStatus.RE_REVIEWED.toString()); + request.setStatus(FunctionalCaseReviewStatus.PASS.toString()); request.setSelectAll(true); request.setContent("测试批量评审通过"); this.requestPostWithOk(REVIEW_FUNCTIONAL_CASE_BATCH_REVIEW, request); + request = new BatchReviewFunctionalCaseRequest(); + request.setReviewId("wx_review_id_2"); + request.setReviewPassRule(CaseReviewPassRule.MULTIPLE.toString()); + request.setStatus(FunctionalCaseReviewStatus.UN_PASS.toString()); + request.setSelectAll(true); + request.setContent("测试批量评审失败"); + this.requestPostWithOk(REVIEW_FUNCTIONAL_CASE_BATCH_REVIEW, request); + + request = new BatchReviewFunctionalCaseRequest(); + request.setReviewId("wx_review_id_1"); + request.setReviewPassRule(CaseReviewPassRule.SINGLE.toString()); + request.setStatus(FunctionalCaseReviewStatus.UN_PASS.toString()); + request.setSelectAll(true); + request.setContent("测试批量评审重新评审"); + this.requestPostWithOk(REVIEW_FUNCTIONAL_CASE_BATCH_REVIEW, request); + + request = new BatchReviewFunctionalCaseRequest(); + request.setReviewId("wx_review_id_1"); + request.setReviewPassRule(CaseReviewPassRule.SINGLE.toString()); + request.setStatus(FunctionalCaseReviewStatus.RE_REVIEWED.toString()); + request.setSelectAll(true); + request.setContent("测试批量评审重新评审"); + this.requestPostWithOk(REVIEW_FUNCTIONAL_CASE_BATCH_REVIEW, request); + try { + caseReviewFunctionalCaseService.batchReview(request, "GGG"); + } catch (Exception e){ + Assertions.assertNotNull(e); + } + + request = new BatchReviewFunctionalCaseRequest(); + request.setReviewId("wx_review_id_4"); + request.setReviewPassRule(CaseReviewPassRule.MULTIPLE.toString()); + request.setStatus(FunctionalCaseReviewStatus.UNDER_REVIEWED.toString()); + request.setSelectAll(true); + request.setContent("测试批量评审人"); + caseReviewFunctionalCaseService.batchReview(request, "666"); + + request = new BatchReviewFunctionalCaseRequest(); + request.setReviewId("wx_review_id_4"); + request.setReviewPassRule(CaseReviewPassRule.MULTIPLE.toString()); + request.setStatus(FunctionalCaseReviewStatus.UNDER_REVIEWED.toString()); + request.setSelectAll(true); + request.setContent("测试批量评审人"); + caseReviewFunctionalCaseService.batchReview(request, "GGG"); + + request = new BatchReviewFunctionalCaseRequest(); + request.setReviewId("wx_review_id_4"); + request.setReviewPassRule(CaseReviewPassRule.MULTIPLE.toString()); + request.setStatus(FunctionalCaseReviewStatus.UN_PASS.toString()); + request.setSelectAll(true); + request.setContent("测试批量评审人"); + caseReviewFunctionalCaseService.batchReview(request, "123"); + request = new BatchReviewFunctionalCaseRequest(); request.setReviewId("wx_review_id_1"); request.setReviewPassRule(CaseReviewPassRule.MULTIPLE.toString()); @@ -276,8 +329,6 @@ public class CaseReviewFunctionalCaseControllerTests extends BaseTest { request.setExcludeIds(excludeIds); request.setContent("测试批量评审不通过"); this.requestPostWithOk(REVIEW_FUNCTIONAL_CASE_BATCH_REVIEW, request); - CaseReviewFunctionalCase caseReviewFunctionalCase = caseReviewFunctionalCaseMapper.selectByPrimaryKey("gyq_test_4"); - Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCase.getStatus(), FunctionalCaseReviewStatus.UNDER_REVIEWED.toString())); request = new BatchReviewFunctionalCaseRequest(); request.setReviewId("wx_review_id_1"); @@ -288,8 +339,7 @@ public class CaseReviewFunctionalCaseControllerTests extends BaseTest { ids.add("gyq_test_3"); request.setSelectIds(ids); this.requestPostWithOk(REVIEW_FUNCTIONAL_CASE_BATCH_REVIEW, request); - caseReviewFunctionalCase = caseReviewFunctionalCaseMapper.selectByPrimaryKey("gyq_test_3"); - Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCase.getStatus(), FunctionalCaseReviewStatus.PASS.toString())); + request = new BatchReviewFunctionalCaseRequest(); request.setReviewId("wx_review_id_1"); @@ -301,8 +351,7 @@ public class CaseReviewFunctionalCaseControllerTests extends BaseTest { ids.add("gyq_test_3"); request.setSelectIds(ids); caseReviewFunctionalCaseService.batchReview(request, "multiple_review_admin"); - caseReviewFunctionalCase = caseReviewFunctionalCaseMapper.selectByPrimaryKey("gyq_test_3"); - Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCase.getStatus(), FunctionalCaseReviewStatus.PASS.toString())); + request = new BatchReviewFunctionalCaseRequest(); request.setReviewId("wx_review_id_1"); @@ -313,8 +362,7 @@ public class CaseReviewFunctionalCaseControllerTests extends BaseTest { ids.add("gyq_test_3"); request.setSelectIds(ids); caseReviewFunctionalCaseService.batchReview(request, "admin"); - caseReviewFunctionalCase = caseReviewFunctionalCaseMapper.selectByPrimaryKey("gyq_test_3"); - Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCase.getStatus(), FunctionalCaseReviewStatus.PASS.toString())); + request = new BatchReviewFunctionalCaseRequest(); request.setReviewId("wx_review_id_1"); @@ -337,8 +385,7 @@ public class CaseReviewFunctionalCaseControllerTests extends BaseTest { request.setSelectIds(ids); request.setContent("测试批量评审通过"); this.requestPostWithOk(REVIEW_FUNCTIONAL_CASE_BATCH_REVIEW, request); - caseReviewFunctionalCase = caseReviewFunctionalCaseMapper.selectByPrimaryKey("gyq_test_5"); - + CaseReviewFunctionalCase caseReviewFunctionalCase = caseReviewFunctionalCaseMapper.selectByPrimaryKey("gyq_test_5"); request = new BatchReviewFunctionalCaseRequest(); request.setReviewId("wx_review_id_1"); diff --git a/backend/services/case-management/src/test/resources/dml/init_review_functional_case_test.sql b/backend/services/case-management/src/test/resources/dml/init_review_functional_case_test.sql index c2bcec673b..ec830c458a 100644 --- a/backend/services/case-management/src/test/resources/dml/init_review_functional_case_test.sql +++ b/backend/services/case-management/src/test/resources/dml/init_review_functional_case_test.sql @@ -115,7 +115,9 @@ INSERT INTO user(id, name, email, password, create_time, update_time, language, last_project_id, create_user, update_user, deleted) VALUES ('gyq_case_review', 'gyq_case_review', 'gyq_case_review_case@fit2cloud.com', MD5('metersphere'),UNIX_TIMESTAMP() * 1000,UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin', false), ('GGG', 'GGG', 'GGG_case_review_case@metersphere.io', MD5('metersphere'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin', false), - ('multiple_review_admin', 'multiple_review_admin', 'multiple_review_admin@metersphere.io', MD5('metersphere'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin', false); + ('multiple_review_admin', 'multiple_review_admin', 'multiple_review_admin@metersphere.io', MD5('metersphere'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin', false), + ('123', '123', '123@metersphere.io', MD5('metersphere'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin', false); + INSERT INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user) VALUE (UUID(), 'multiple_review_admin', 'admin', 'system',