diff --git a/backend/src/main/java/io/metersphere/track/controller/TestReviewTestCaseController.java b/backend/src/main/java/io/metersphere/track/controller/TestReviewTestCaseController.java index 4d377af5c9..4a25b740a0 100644 --- a/backend/src/main/java/io/metersphere/track/controller/TestReviewTestCaseController.java +++ b/backend/src/main/java/io/metersphere/track/controller/TestReviewTestCaseController.java @@ -8,6 +8,7 @@ import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.Pager; import io.metersphere.track.dto.TestReviewCaseDTO; import io.metersphere.track.request.testplancase.TestReviewCaseBatchRequest; +import io.metersphere.track.request.testreview.DeleteRelevanceRequest; import io.metersphere.track.request.testreview.QueryCaseReviewRequest; import io.metersphere.track.service.TestReviewTestCaseService; import org.apache.shiro.authz.annotation.Logical; @@ -30,10 +31,10 @@ public class TestReviewTestCaseController { return PageUtils.setPageInfo(page, testReviewTestCaseService.list(request)); } - @PostMapping("/delete/{id}") + @PostMapping("/delete") @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) - public int deleteTestCase(@PathVariable String id) { - return testReviewTestCaseService.deleteTestCase(id); + public int deleteTestCase(@RequestBody DeleteRelevanceRequest request) { + return testReviewTestCaseService.deleteTestCase(request); } @PostMapping("/batch/delete") diff --git a/backend/src/main/java/io/metersphere/track/request/testplancase/TestReviewCaseBatchRequest.java b/backend/src/main/java/io/metersphere/track/request/testplancase/TestReviewCaseBatchRequest.java index 676c970859..b97bf25bf0 100644 --- a/backend/src/main/java/io/metersphere/track/request/testplancase/TestReviewCaseBatchRequest.java +++ b/backend/src/main/java/io/metersphere/track/request/testplancase/TestReviewCaseBatchRequest.java @@ -9,5 +9,6 @@ import java.util.List; @Getter @Setter public class TestReviewCaseBatchRequest extends TestCaseReviewTestCase { + private String reviewId; private List ids; } diff --git a/backend/src/main/java/io/metersphere/track/request/testreview/DeleteRelevanceRequest.java b/backend/src/main/java/io/metersphere/track/request/testreview/DeleteRelevanceRequest.java new file mode 100644 index 0000000000..92e7129699 --- /dev/null +++ b/backend/src/main/java/io/metersphere/track/request/testreview/DeleteRelevanceRequest.java @@ -0,0 +1,11 @@ +package io.metersphere.track.request.testreview; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class DeleteRelevanceRequest { + private String id; + private String reviewId; +} diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java index f69b5ab1c5..afa6f8ed78 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java @@ -275,6 +275,13 @@ public class TestCaseReviewService { } public void testReviewRelevance(ReviewRelevanceRequest request) { + String reviewId = request.getReviewId(); + List userIds = getTestCaseReviewerIds(reviewId); + String currentId = SessionUtils.getUser().getId(); + if (!userIds.contains(currentId)) { + MSException.throwException("非用例评审人员,不能关联用例!"); + } + List testCaseIds = request.getTestCaseIds(); if (testCaseIds.isEmpty()) { @@ -307,6 +314,13 @@ public class TestCaseReviewService { testCaseReviewMapper.updateByPrimaryKey(testCaseReview); } } + + public List getTestCaseReviewerIds(String reviewId) { + TestCaseReviewUsersExample testCaseReviewUsersExample = new TestCaseReviewUsersExample(); + testCaseReviewUsersExample.createCriteria().andReviewIdEqualTo(reviewId); + List testCaseReviewUsers = testCaseReviewUsersMapper.selectByExample(testCaseReviewUsersExample); + return testCaseReviewUsers.stream().map(TestCaseReviewUsers::getUserId).collect(Collectors.toList()); + } public TestCaseReview getTestReview(String reviewId) { return Optional.ofNullable(testCaseReviewMapper.selectByPrimaryKey(reviewId)).orElse(new TestCaseReview()); diff --git a/backend/src/main/java/io/metersphere/track/service/TestReviewTestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestReviewTestCaseService.java index 45180c5b06..1a88233cad 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestReviewTestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestReviewTestCaseService.java @@ -12,6 +12,7 @@ import io.metersphere.controller.request.member.QueryMemberRequest; import io.metersphere.service.UserService; import io.metersphere.track.dto.TestReviewCaseDTO; import io.metersphere.track.request.testplancase.TestReviewCaseBatchRequest; +import io.metersphere.track.request.testreview.DeleteRelevanceRequest; import io.metersphere.track.request.testreview.QueryCaseReviewRequest; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -35,6 +36,8 @@ public class TestReviewTestCaseService { TestCaseReviewUsersMapper testCaseReviewUsersMapper; @Resource TestCaseReviewMapper testCaseReviewMapper; + @Resource + TestCaseReviewService testCaseReviewService; public List list(QueryCaseReviewRequest request) { request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); @@ -71,11 +74,21 @@ public class TestReviewTestCaseService { return name; } - public int deleteTestCase(String id) { - return testCaseReviewTestCaseMapper.deleteByPrimaryKey(id); + public int deleteTestCase(DeleteRelevanceRequest request) { + checkReviewer(request.getReviewId()); + return testCaseReviewTestCaseMapper.deleteByPrimaryKey(request.getId()); + } + + private void checkReviewer(String reviewId) { + List userIds = testCaseReviewService.getTestCaseReviewerIds(reviewId); + String currentId = SessionUtils.getUser().getId(); + if (!userIds.contains(currentId)) { + MSException.throwException("非用例评审人员,不能解除用例关联!"); + } } public void deleteTestCaseBath(TestReviewCaseBatchRequest request) { + checkReviewer(request.getReviewId()); TestCaseReviewTestCaseExample example = new TestCaseReviewTestCaseExample(); example.createCriteria().andIdIn(request.getIds()); testCaseReviewTestCaseMapper.deleteByExample(example); diff --git a/frontend/src/business/components/track/review/view/components/TestReviewTestCaseList.vue b/frontend/src/business/components/track/review/view/components/TestReviewTestCaseList.vue index 26c349e047..8f6438fea1 100644 --- a/frontend/src/business/components/track/review/view/components/TestReviewTestCaseList.vue +++ b/frontend/src/business/components/track/review/view/components/TestReviewTestCaseList.vue @@ -322,7 +322,7 @@ export default { callback: (action) => { if (action === 'confirm') { let ids = Array.from(this.selectRows).map(row => row.id); - this.$post('/test/review/case/batch/delete', {ids: ids}, () => { + this.$post('/test/review/case/batch/delete', {ids: ids, reviewId: this.reviewId}, () => { this.selectRows.clear(); this.$emit("refresh"); this.$success(this.$t('test_track.cancel_relevance_success')); @@ -333,7 +333,7 @@ export default { }, _handleDelete(testCase) { let testCaseId = testCase.id; - this.$post('/test/review/case/delete/' + testCaseId, {}, () => { + this.$post('/test/review/case/delete', {id: testCaseId, reviewId: testCase.reviewId}, () => { this.$emit("refresh"); this.$success(this.$t('test_track.cancel_relevance_success')); }); diff --git a/frontend/src/business/components/xpack b/frontend/src/business/components/xpack index 06d935cd1d..cc38137a69 160000 --- a/frontend/src/business/components/xpack +++ b/frontend/src/business/components/xpack @@ -1 +1 @@ -Subproject commit 06d935cd1d22ab36f09763745c2aff8ad3fb08c1 +Subproject commit cc38137a69a0f20fadece9c0f9f50a9468c4ace9