提交 fdb593be 编写于 作者: S shiziyuan9527

feat(用例评审): 非用例评审人员不可取消或关联用例

上级 c0dd8586
......@@ -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")
......
......@@ -9,5 +9,6 @@ import java.util.List;
@Getter
@Setter
public class TestReviewCaseBatchRequest extends TestCaseReviewTestCase {
private String reviewId;
private List<String> ids;
}
package io.metersphere.track.request.testreview;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class DeleteRelevanceRequest {
private String id;
private String reviewId;
}
......@@ -275,6 +275,13 @@ public class TestCaseReviewService {
}
public void testReviewRelevance(ReviewRelevanceRequest request) {
String reviewId = request.getReviewId();
List<String> userIds = getTestCaseReviewerIds(reviewId);
String currentId = SessionUtils.getUser().getId();
if (!userIds.contains(currentId)) {
MSException.throwException("非用例评审人员,不能关联用例!");
}
List<String> testCaseIds = request.getTestCaseIds();
if (testCaseIds.isEmpty()) {
......@@ -307,6 +314,13 @@ public class TestCaseReviewService {
testCaseReviewMapper.updateByPrimaryKey(testCaseReview);
}
}
public List<String> getTestCaseReviewerIds(String reviewId) {
TestCaseReviewUsersExample testCaseReviewUsersExample = new TestCaseReviewUsersExample();
testCaseReviewUsersExample.createCriteria().andReviewIdEqualTo(reviewId);
List<TestCaseReviewUsers> 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());
......
......@@ -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<TestReviewCaseDTO> 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<String> 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);
......
......@@ -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'));
});
......
Subproject commit 06d935cd1d22ab36f09763745c2aff8ad3fb08c1
Subproject commit cc38137a69a0f20fadece9c0f9f50a9468c4ace9
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册