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

This commit is contained in:
shiziyuan9527 2020-09-24 15:15:38 +08:00
parent c0dd85866b
commit fdb593be58
7 changed files with 48 additions and 8 deletions

View File

@ -8,6 +8,7 @@ import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager; import io.metersphere.commons.utils.Pager;
import io.metersphere.track.dto.TestReviewCaseDTO; import io.metersphere.track.dto.TestReviewCaseDTO;
import io.metersphere.track.request.testplancase.TestReviewCaseBatchRequest; 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.request.testreview.QueryCaseReviewRequest;
import io.metersphere.track.service.TestReviewTestCaseService; import io.metersphere.track.service.TestReviewTestCaseService;
import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.Logical;
@ -30,10 +31,10 @@ public class TestReviewTestCaseController {
return PageUtils.setPageInfo(page, testReviewTestCaseService.list(request)); return PageUtils.setPageInfo(page, testReviewTestCaseService.list(request));
} }
@PostMapping("/delete/{id}") @PostMapping("/delete")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public int deleteTestCase(@PathVariable String id) { public int deleteTestCase(@RequestBody DeleteRelevanceRequest request) {
return testReviewTestCaseService.deleteTestCase(id); return testReviewTestCaseService.deleteTestCase(request);
} }
@PostMapping("/batch/delete") @PostMapping("/batch/delete")

View File

@ -9,5 +9,6 @@ import java.util.List;
@Getter @Getter
@Setter @Setter
public class TestReviewCaseBatchRequest extends TestCaseReviewTestCase { public class TestReviewCaseBatchRequest extends TestCaseReviewTestCase {
private String reviewId;
private List<String> ids; private List<String> ids;
} }

View File

@ -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;
}

View File

@ -275,6 +275,13 @@ public class TestCaseReviewService {
} }
public void testReviewRelevance(ReviewRelevanceRequest request) { 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(); List<String> testCaseIds = request.getTestCaseIds();
if (testCaseIds.isEmpty()) { if (testCaseIds.isEmpty()) {
@ -308,6 +315,13 @@ public class TestCaseReviewService {
} }
} }
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) { public TestCaseReview getTestReview(String reviewId) {
return Optional.ofNullable(testCaseReviewMapper.selectByPrimaryKey(reviewId)).orElse(new TestCaseReview()); return Optional.ofNullable(testCaseReviewMapper.selectByPrimaryKey(reviewId)).orElse(new TestCaseReview());
} }

View File

@ -12,6 +12,7 @@ import io.metersphere.controller.request.member.QueryMemberRequest;
import io.metersphere.service.UserService; import io.metersphere.service.UserService;
import io.metersphere.track.dto.TestReviewCaseDTO; import io.metersphere.track.dto.TestReviewCaseDTO;
import io.metersphere.track.request.testplancase.TestReviewCaseBatchRequest; 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.request.testreview.QueryCaseReviewRequest;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -35,6 +36,8 @@ public class TestReviewTestCaseService {
TestCaseReviewUsersMapper testCaseReviewUsersMapper; TestCaseReviewUsersMapper testCaseReviewUsersMapper;
@Resource @Resource
TestCaseReviewMapper testCaseReviewMapper; TestCaseReviewMapper testCaseReviewMapper;
@Resource
TestCaseReviewService testCaseReviewService;
public List<TestReviewCaseDTO> list(QueryCaseReviewRequest request) { public List<TestReviewCaseDTO> list(QueryCaseReviewRequest request) {
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
@ -71,11 +74,21 @@ public class TestReviewTestCaseService {
return name; return name;
} }
public int deleteTestCase(String id) { public int deleteTestCase(DeleteRelevanceRequest request) {
return testCaseReviewTestCaseMapper.deleteByPrimaryKey(id); 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) { public void deleteTestCaseBath(TestReviewCaseBatchRequest request) {
checkReviewer(request.getReviewId());
TestCaseReviewTestCaseExample example = new TestCaseReviewTestCaseExample(); TestCaseReviewTestCaseExample example = new TestCaseReviewTestCaseExample();
example.createCriteria().andIdIn(request.getIds()); example.createCriteria().andIdIn(request.getIds());
testCaseReviewTestCaseMapper.deleteByExample(example); testCaseReviewTestCaseMapper.deleteByExample(example);

View File

@ -322,7 +322,7 @@ export default {
callback: (action) => { callback: (action) => {
if (action === 'confirm') { if (action === 'confirm') {
let ids = Array.from(this.selectRows).map(row => row.id); 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.selectRows.clear();
this.$emit("refresh"); this.$emit("refresh");
this.$success(this.$t('test_track.cancel_relevance_success')); this.$success(this.$t('test_track.cancel_relevance_success'));
@ -333,7 +333,7 @@ export default {
}, },
_handleDelete(testCase) { _handleDelete(testCase) {
let testCaseId = testCase.id; 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.$emit("refresh");
this.$success(this.$t('test_track.cancel_relevance_success')); this.$success(this.$t('test_track.cancel_relevance_success'));
}); });

@ -1 +1 @@
Subproject commit 06d935cd1d22ab36f09763745c2aff8ad3fb08c1 Subproject commit cc38137a69a0f20fadece9c0f9f50a9468c4ace9