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 ced8c05a84..7d0c965262 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 @@ -332,7 +332,7 @@ public class CaseReviewFunctionalCaseService { caseReviewHistory.setCaseId(item.getCaseId()); caseReviewHistory.setReviewId(item.getReviewId()); caseReviewHistory.setStatus(FunctionalCaseReviewStatus.RE_REVIEWED.name()); - caseReviewHistory.setCreateUser("system"); + caseReviewHistory.setCreateUser(UserRoleScope.SYSTEM); caseReviewHistory.setCreateTime(System.currentTimeMillis()); caseReviewHistory.setDeleted(false); caseReviewHistoryMapper.insertSelective(caseReviewHistory); @@ -490,6 +490,10 @@ public class CaseReviewFunctionalCaseService { unPassCount.set(unPassCount.get() + 1); } }); + //检查是否全部是通过,全是才是PASS,否则是评审中(如果时自动重新提审,会有个system用户,这里需要排出一下) + if (hasReviewedUserMap.get(UserRoleScope.SYSTEM) !=null) { + hasReviewedUserMap.remove(UserRoleScope.SYSTEM); + } if (unPassCount.get() > 0) { caseReviewFunctionalCase.setStatus(FunctionalCaseReviewStatus.UN_PASS.toString()); } else if (caseReviewFunctionalCaseUsersExp != null && caseReviewFunctionalCaseUsersExp.size() > hasReviewedUserMap.size()) { diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseReviewService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseReviewService.java index 5c575e339e..a4b8091b56 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseReviewService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseReviewService.java @@ -6,6 +6,7 @@ import io.metersphere.functional.dto.FunctionalCaseReviewDTO; import io.metersphere.functional.mapper.ExtCaseReviewFunctionalCaseMapper; import io.metersphere.functional.mapper.ExtCaseReviewHistoryMapper; import io.metersphere.functional.request.FunctionalCaseReviewListRequest; +import io.metersphere.sdk.constants.UserRoleScope; import io.metersphere.sdk.util.Translator; import jakarta.annotation.Resource; import org.apache.commons.lang3.StringUtils; @@ -38,7 +39,7 @@ public class FunctionalCaseReviewService { public List getCaseReviewHistory(String caseId) { List list = extCaseReviewHistoryMapper.getHistoryListWidthAbandoned(caseId, null); for (CaseReviewHistoryDTO caseReviewHistoryDTO : list) { - if (StringUtils.equalsIgnoreCase(caseReviewHistoryDTO.getCreateUser(), "system")) { + if (StringUtils.equalsIgnoreCase(caseReviewHistoryDTO.getCreateUser(), UserRoleScope.SYSTEM)) { caseReviewHistoryDTO.setUserName(Translator.get("case_review_history.system")); } if (caseReviewHistoryDTO.getContent() != null) { diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/ReviewFunctionalCaseService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/ReviewFunctionalCaseService.java index e7c92583e5..20a83ca6b0 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/ReviewFunctionalCaseService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/ReviewFunctionalCaseService.java @@ -158,12 +158,15 @@ public class ReviewFunctionalCaseService { unPassCount.set(unPassCount.get() + 1); } }); + //检查是否全部是通过,全是才是PASS,否则是评审中(如果时自动重新提审,会有个system用户,这里需要排出一下) + if (hasReviewedUserMap.get(UserRoleScope.SYSTEM) !=null) { + hasReviewedUserMap.remove(UserRoleScope.SYSTEM); + } if (unPassCount.get() > 0) { functionalCaseStatus = FunctionalCaseReviewStatus.UN_PASS.toString(); } else if (reviewerNum > hasReviewedUserMap.size()) { functionalCaseStatus = FunctionalCaseReviewStatus.UNDER_REVIEWED.toString(); } else { - //检查是否全部是通过,全是才是PASS,否则是评审中 if (passCount.get() == hasReviewedUserMap.size()) { functionalCaseStatus = FunctionalCaseReviewStatus.PASS.toString(); } else { @@ -209,7 +212,7 @@ public class ReviewFunctionalCaseService { public List getCaseReviewHistoryList(String reviewId, String caseId) { List list = extCaseReviewHistoryMapper.getHistoryListWidthAbandoned(caseId, reviewId); for (CaseReviewHistoryDTO caseReviewHistoryDTO : list) { - if (StringUtils.equalsIgnoreCase(caseReviewHistoryDTO.getCreateUser(), "system")) { + if (StringUtils.equalsIgnoreCase(caseReviewHistoryDTO.getCreateUser(), UserRoleScope.SYSTEM)) { caseReviewHistoryDTO.setUserName(Translator.get("case_review_history.system")); } if (caseReviewHistoryDTO.getContent() != null) { diff --git a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/ReviewFunctionalCaseControllerTests.java b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/ReviewFunctionalCaseControllerTests.java index 97af6057f3..17085c9543 100644 --- a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/ReviewFunctionalCaseControllerTests.java +++ b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/ReviewFunctionalCaseControllerTests.java @@ -10,7 +10,10 @@ import io.metersphere.functional.mapper.CaseReviewFunctionalCaseMapper; import io.metersphere.functional.mapper.CaseReviewHistoryMapper; import io.metersphere.functional.mapper.CaseReviewMapper; import io.metersphere.functional.mapper.FunctionalCaseAttachmentMapper; -import io.metersphere.functional.request.*; +import io.metersphere.functional.request.BaseAssociateCaseRequest; +import io.metersphere.functional.request.CaseReviewRequest; +import io.metersphere.functional.request.FunctionalCaseFileRequest; +import io.metersphere.functional.request.ReviewFunctionalCaseRequest; import io.metersphere.functional.service.FunctionalCaseAttachmentService; import io.metersphere.functional.service.ReviewFunctionalCaseService; import io.metersphere.functional.utils.FileBaseUtils; @@ -23,8 +26,10 @@ import io.metersphere.sdk.constants.StorageType; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.file.FileRequest; import io.metersphere.sdk.util.JSON; +import io.metersphere.sdk.util.Translator; import io.metersphere.system.base.BaseTest; import io.metersphere.system.controller.handler.ResultHolder; +import io.metersphere.system.uid.IDGenerator; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -104,10 +109,10 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { caseReviewHistoryExample.createCriteria().andReviewIdEqualTo(reviewId).andCaseIdEqualTo("gyqReviewCaseTest").andAbandonedEqualTo(false); List caseReviewHistories = caseReviewHistoryMapper.selectByExample(caseReviewHistoryExample); Assertions.assertEquals(1, caseReviewHistories.size()); - CaseReviewFunctionalCaseExample caseReviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample(); + CaseReviewFunctionalCaseExample caseReviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample(); caseReviewFunctionalCaseExample.createCriteria().andReviewIdEqualTo(reviewId).andCaseIdEqualTo("gyqReviewCaseTest"); List caseReviewFunctionalCases = caseReviewFunctionalCaseMapper.selectByExample(caseReviewFunctionalCaseExample); - Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCases.get(0).getStatus(),FunctionalCaseReviewStatus.PASS.toString())); + Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCases.get(0).getStatus(), FunctionalCaseReviewStatus.PASS.toString())); //单人评审不通过 reviewFunctionalCaseRequest = new ReviewFunctionalCaseRequest(); reviewFunctionalCaseRequest.setReviewId(reviewId); @@ -125,7 +130,7 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { caseReviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample(); caseReviewFunctionalCaseExample.createCriteria().andReviewIdEqualTo(reviewId).andCaseIdEqualTo("gyqReviewCaseTestOne"); caseReviewFunctionalCases = caseReviewFunctionalCaseMapper.selectByExample(caseReviewFunctionalCaseExample); - Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCases.get(0).getStatus(),FunctionalCaseReviewStatus.UN_PASS.toString())); + Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCases.get(0).getStatus(), FunctionalCaseReviewStatus.UN_PASS.toString())); reviewFunctionalCaseRequest = new ReviewFunctionalCaseRequest(); @@ -144,7 +149,7 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { caseReviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample(); caseReviewFunctionalCaseExample.createCriteria().andReviewIdEqualTo(reviewId).andCaseIdEqualTo("gyqReviewCaseTestOne"); caseReviewFunctionalCases = caseReviewFunctionalCaseMapper.selectByExample(caseReviewFunctionalCaseExample); - Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCases.get(0).getStatus(),FunctionalCaseReviewStatus.RE_REVIEWED.toString())); + Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCases.get(0).getStatus(), FunctionalCaseReviewStatus.RE_REVIEWED.toString())); reviewFunctionalCaseRequest = new ReviewFunctionalCaseRequest(); reviewFunctionalCaseRequest.setReviewId(reviewId); @@ -157,7 +162,7 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { reviewFunctionalCaseService.saveReview(reviewFunctionalCaseRequest, "default-project-member-user-gyq-4"); caseReviewFunctionalCaseExample.createCriteria().andReviewIdEqualTo(reviewId).andCaseIdEqualTo("gyqReviewCaseTestOne"); caseReviewFunctionalCases = caseReviewFunctionalCaseMapper.selectByExample(caseReviewFunctionalCaseExample); - Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCases.get(0).getStatus(),FunctionalCaseReviewStatus.RE_REVIEWED.toString())); + Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCases.get(0).getStatus(), FunctionalCaseReviewStatus.RE_REVIEWED.toString())); reviewFunctionalCaseRequest = new ReviewFunctionalCaseRequest(); reviewFunctionalCaseRequest.setReviewId(reviewId); @@ -170,7 +175,7 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { reviewFunctionalCaseService.saveReview(reviewFunctionalCaseRequest, "admin"); caseReviewFunctionalCaseExample.createCriteria().andReviewIdEqualTo(reviewId).andCaseIdEqualTo("gyqReviewCaseTestOne"); caseReviewFunctionalCases = caseReviewFunctionalCaseMapper.selectByExample(caseReviewFunctionalCaseExample); - Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCases.get(0).getStatus(),FunctionalCaseReviewStatus.RE_REVIEWED.toString())); + Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCases.get(0).getStatus(), FunctionalCaseReviewStatus.RE_REVIEWED.toString())); } @Test @@ -184,6 +189,14 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { reviewers.add("default-project-member-user-gyq"); List caseReviews = addReview("创建用例评审2", caseIds, reviewers, CaseReviewPassRule.MULTIPLE.toString()); String reviewId = caseReviews.get(0).getId(); + CaseReviewHistory caseReviewHistory = new CaseReviewHistory(); + caseReviewHistory.setReviewId(reviewId); + caseReviewHistory.setCaseId("gyqReviewCaseTestTwo"); + caseReviewHistory.setCreateUser("system"); + caseReviewHistory.setStatus("RE_REVIEWED"); + caseReviewHistory.setId(IDGenerator.nextStr()); + caseReviewHistory.setCreateTime(System.currentTimeMillis()); + caseReviewHistoryMapper.insertSelective(caseReviewHistory); ReviewFunctionalCaseRequest reviewFunctionalCaseRequest = new ReviewFunctionalCaseRequest(); reviewFunctionalCaseRequest.setReviewId(reviewId); reviewFunctionalCaseRequest.setCaseId("gyqReviewCaseTestTwo"); @@ -197,12 +210,13 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { CaseReviewHistoryExample caseReviewHistoryExample = new CaseReviewHistoryExample(); caseReviewHistoryExample.createCriteria().andReviewIdEqualTo(reviewId).andCaseIdEqualTo("gyqReviewCaseTestTwo").andAbandonedEqualTo(false); List caseReviewHistories = caseReviewHistoryMapper.selectByExample(caseReviewHistoryExample); - Assertions.assertEquals(1, caseReviewHistories.size()); - CaseReviewFunctionalCaseExample caseReviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample(); + Assertions.assertEquals(2, caseReviewHistories.size()); + CaseReviewFunctionalCaseExample caseReviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample(); caseReviewFunctionalCaseExample.createCriteria().andReviewIdEqualTo(reviewId).andCaseIdEqualTo("gyqReviewCaseTestTwo"); List caseReviewFunctionalCases = caseReviewFunctionalCaseMapper.selectByExample(caseReviewFunctionalCaseExample); - Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCases.get(0).getStatus(),FunctionalCaseReviewStatus.UNDER_REVIEWED.toString())); + Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCases.get(0).getStatus(), FunctionalCaseReviewStatus.UNDER_REVIEWED.toString())); List caseReviews1 = getCaseReviews("创建用例评审2"); + System.out.println(caseReviews1.get(0).getStatus()); Assertions.assertTrue(StringUtils.equals(caseReviews1.get(0).getStatus(), CaseReviewStatus.UNDERWAY.toString())); reviewFunctionalCaseRequest = new ReviewFunctionalCaseRequest(); @@ -218,7 +232,14 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { caseReviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample(); caseReviewFunctionalCaseExample.createCriteria().andReviewIdEqualTo(reviewId).andCaseIdEqualTo("gyqReviewCaseTestTwo"); caseReviewFunctionalCases = caseReviewFunctionalCaseMapper.selectByExample(caseReviewFunctionalCaseExample); - Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCases.get(0).getStatus(),FunctionalCaseReviewStatus.UNDER_REVIEWED.toString())); + Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCases.get(0).getStatus(), FunctionalCaseReviewStatus.UNDER_REVIEWED.toString())); + + try { + reviewFunctionalCaseService.saveReview(reviewFunctionalCaseRequest, "default-project-member-user-gyq-s"); + + } catch (Exception e) { + Assertions.assertTrue(StringUtils.equalsIgnoreCase(e.getMessage(), Translator.get("case_review_user"))); + } } @@ -247,10 +268,10 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { caseReviewHistoryExample.createCriteria().andReviewIdEqualTo(reviewId).andCaseIdEqualTo("gyqReviewCaseTestThree").andAbandonedEqualTo(false); List caseReviewHistories = caseReviewHistoryMapper.selectByExample(caseReviewHistoryExample); Assertions.assertEquals(1, caseReviewHistories.size()); - CaseReviewFunctionalCaseExample caseReviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample(); + CaseReviewFunctionalCaseExample caseReviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample(); caseReviewFunctionalCaseExample.createCriteria().andReviewIdEqualTo(reviewId).andCaseIdEqualTo("gyqReviewCaseTestThree"); List caseReviewFunctionalCases = caseReviewFunctionalCaseMapper.selectByExample(caseReviewFunctionalCaseExample); - Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCases.get(0).getStatus(),FunctionalCaseReviewStatus.PASS.toString())); + Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCases.get(0).getStatus(), FunctionalCaseReviewStatus.PASS.toString())); reviewFunctionalCaseRequest = new ReviewFunctionalCaseRequest(); reviewFunctionalCaseRequest.setReviewId(reviewId); @@ -268,7 +289,7 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { caseReviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample(); caseReviewFunctionalCaseExample.createCriteria().andReviewIdEqualTo(reviewId).andCaseIdEqualTo("gyqReviewCaseTestFour"); caseReviewFunctionalCases = caseReviewFunctionalCaseMapper.selectByExample(caseReviewFunctionalCaseExample); - Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCases.get(0).getStatus(),FunctionalCaseReviewStatus.UN_PASS.toString())); + Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCases.get(0).getStatus(), FunctionalCaseReviewStatus.UN_PASS.toString())); } @@ -347,17 +368,17 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { Assertions.assertTrue(StringUtils.isNotBlank(fileId)); file = getNoNameMockMultipartFile(); doUploadTempFileFalse(file); - functionalCaseAttachmentService.uploadMinioFile("gyqReviewCaseTest","project-review-case-test", List.of(fileId),"admin", CaseFileSourceType.REVIEW_COMMENT.toString()); + functionalCaseAttachmentService.uploadMinioFile("gyqReviewCaseTest", "project-review-case-test", List.of(fileId), "admin", CaseFileSourceType.REVIEW_COMMENT.toString()); FunctionalCaseAttachmentExample functionalCaseAttachmentExample = new FunctionalCaseAttachmentExample(); functionalCaseAttachmentExample.createCriteria().andCaseIdEqualTo("gyqReviewCaseTest").andFileIdEqualTo(fileId).andFileSourceEqualTo(CaseFileSourceType.REVIEW_COMMENT.toString()); List functionalCaseAttachments = functionalCaseAttachmentMapper.selectByExample(functionalCaseAttachmentExample); Assertions.assertTrue(CollectionUtils.isNotEmpty(functionalCaseAttachments)); - functionalCaseAttachmentService.uploadMinioFile("gyqReviewCaseTest","project-review-case-test",new ArrayList<>(),"admin", CaseFileSourceType.REVIEW_COMMENT.toString()); + functionalCaseAttachmentService.uploadMinioFile("gyqReviewCaseTest", "project-review-case-test", new ArrayList<>(), "admin", CaseFileSourceType.REVIEW_COMMENT.toString()); String functionalCaseDir = DefaultRepositoryDir.getFunctionalCaseDir("project-review-case-test", "gyqReviewCaseTest"); - functionalCaseAttachmentService.uploadFileResource(functionalCaseDir,new HashMap<>(),"project-review-case-test", "gyqReviewCaseTest"); + functionalCaseAttachmentService.uploadFileResource(functionalCaseDir, new HashMap<>(), "project-review-case-test", "gyqReviewCaseTest"); Map objectObjectHashMap = new HashMap<>(); - objectObjectHashMap.put(fileId,null); - functionalCaseAttachmentService.uploadFileResource(functionalCaseDir,objectObjectHashMap,"project-review-case-test", "gyqReviewCaseTest"); + objectObjectHashMap.put(fileId, null); + functionalCaseAttachmentService.uploadFileResource(functionalCaseDir, objectObjectHashMap, "project-review-case-test", "gyqReviewCaseTest"); } @@ -397,8 +418,8 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { } - public List getCaseReviewHistoryList(String caseId,String reviewId) throws Exception { - MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get(REVIEW_LIST +"/"+reviewId +"/"+ caseId).header(SessionConstants.HEADER_TOKEN, sessionId) + public List getCaseReviewHistoryList(String caseId, String reviewId) throws Exception { + MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get(REVIEW_LIST + "/" + reviewId + "/" + caseId).header(SessionConstants.HEADER_TOKEN, sessionId) .header(SessionConstants.CSRF_TOKEN, csrfToken) .header(SessionConstants.CURRENT_PROJECT, projectId) .contentType(MediaType.APPLICATION_JSON)) @@ -410,7 +431,7 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { } - private List addReview(String name, List caseIds, List reviewers, String reviewPassRule) throws Exception { + private List addReview(String name, List caseIds, List reviewers, String reviewPassRule) throws Exception { CaseReviewRequest caseReviewRequest = new CaseReviewRequest(); caseReviewRequest.setProjectId(projectId); caseReviewRequest.setName(name); @@ -455,6 +476,7 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { throw new MSException("save file error"); } } + private String uploadFile() throws Exception { String filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/test.JPG")).getPath(); MockMultipartFile file = new MockMultipartFile("file", "file_re-upload.JPG", MediaType.APPLICATION_OCTET_STREAM_VALUE, FileBaseUtils.getFileBytes(filePath));