From 25b37cf0346e272f35f67a34fc87ee2f1c80dbdd Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Tue, 21 Feb 2023 16:01:06 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E5=85=AC=E5=85=B1=E7=94=A8=E4=BE=8B=E6=A0=A1=E9=AA=8C=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1023520 --user=陈建星 【测试跟踪】功能用例-公共用例库-操作-查看-点击下一条-从无权限项目用例切换到有权限项目用例-仍提示无权限 https://www.tapd.cn/55049933/s/1339509 --- .../base/mapper/ext/ExtTestCaseMapper.xml | 2 +- .../controller/TestCaseController.java | 5 ++ .../metersphere/service/TestCaseService.java | 9 +++ test-track/frontend/src/api/testCase.js | 4 ++ .../business/case/components/TestCaseEdit.vue | 72 ++++++++++++------- .../case/components/case/CaseBaseInfo.vue | 3 +- .../components/public/PublicTestCaseList.vue | 11 ++- .../components/public/PublicTestCaseShow.vue | 2 +- 8 files changed, 75 insertions(+), 33 deletions(-) diff --git a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml index d381f60543..8c59e282fb 100644 --- a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml +++ b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml @@ -1412,7 +1412,7 @@ inner join project p on p.id = test_case.project_id and p.workspace_id = #{request.workspaceId} - group by tcn.id, test_case.project_id; + group by tcn.id; diff --git a/test-track/backend/src/main/java/io/metersphere/controller/TestCaseController.java b/test-track/backend/src/main/java/io/metersphere/controller/TestCaseController.java index 6345bce839..c4eed78d0f 100644 --- a/test-track/backend/src/main/java/io/metersphere/controller/TestCaseController.java +++ b/test-track/backend/src/main/java/io/metersphere/controller/TestCaseController.java @@ -179,6 +179,11 @@ public class TestCaseController { return testCaseService.getSimpleCase(testCaseId); } + @GetMapping("/get/edit/simple/{testCaseId}") + public TestCaseWithBLOBs getSimpleCaseForEdit(@PathVariable String testCaseId) { + return testCaseService.getSimpleCaseForEdit(testCaseId); + } + @GetMapping("/project/{testCaseId}") public Project getProjectByTestCaseId(@PathVariable String testCaseId) { trackCheckPermissionService.checkTestCaseOwner(testCaseId); diff --git a/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java b/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java index 70ecc396c8..843d02bc2f 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java @@ -3157,6 +3157,15 @@ public class TestCaseService { } } + public TestCaseWithBLOBs getSimpleCaseForEdit(String testCaseId) { + TestCaseWithBLOBs testCase = testCaseMapper.selectByPrimaryKey(testCaseId); + Project project = baseProjectService.getProjectById(testCase.getProjectId()); + if (!SessionUtils.hasPermission(project.getWorkspaceId(), project.getId(), PermissionConstants.PROJECT_TRACK_CASE_READ_EDIT)) { + MSException.throwException(Translator.get("check_owner_project")); + } + return testCaseMapper.selectByPrimaryKey(testCaseId); + } + public TestCaseWithBLOBs getSimpleCase(String testCaseId) { return testCaseMapper.selectByPrimaryKey(testCaseId); } diff --git a/test-track/frontend/src/api/testCase.js b/test-track/frontend/src/api/testCase.js index e3aa1347c2..fa9813a500 100644 --- a/test-track/frontend/src/api/testCase.js +++ b/test-track/frontend/src/api/testCase.js @@ -26,6 +26,10 @@ export function getSimpleTestCase(id) { return get(BASE_URL + `get/simple/${id}`); } +export function getEditSimpleTestCase(id) { + return get(BASE_URL + `get/edit/simple/${id}`); +} + export function getTestCaseByVersionId(refId, versionId) { return get(BASE_URL + `get/version/${refId}/${versionId}`); } diff --git a/test-track/frontend/src/business/case/components/TestCaseEdit.vue b/test-track/frontend/src/business/case/components/TestCaseEdit.vue index dee639fcef..db6581e7c2 100644 --- a/test-track/frontend/src/business/case/components/TestCaseEdit.vue +++ b/test-track/frontend/src/business/case/components/TestCaseEdit.vue @@ -150,7 +150,7 @@
@@ -191,7 +191,7 @@
-
+
{ + localStorage.setItem('projectChangeFlag', 'true'); this.$router.push('/track/case/all'); }); this.$EventBus.$on("handleSaveCaseWithEvent", this.handleSaveCaseWithEvent); @@ -728,6 +728,11 @@ export default { }, async loadTestCase() { + if (localStorage.getItem('projectChangeFlag')) { + localStorage.removeItem('projectChangeFlag'); + return; + } + let initFuc = this.initEdit; this.loading = true; @@ -758,15 +763,18 @@ export default { }); } - getTestCaseNodesByCaseFilter(this.projectId, {}) - .then(r => { - this.treeNodes = r.data; - this.treeNodes.forEach(node => { - node.name = node.name === '未规划用例' ? this.$t('api_test.unplanned_case') : node.name - buildTree(node, {path: ''}); - this.setNodeModule(); + if (!this.isPublicShow) { + // 公共用例库不展示模块,这里调用接口会有权限校验 + getTestCaseNodesByCaseFilter(this.projectId, {}) + .then(r => { + this.treeNodes = r.data; + this.treeNodes.forEach(node => { + node.name = node.name === '未规划用例' ? this.$t('api_test.unplanned_case') : node.name + buildTree(node, {path: ''}); + this.setNodeModule(); + }); }); - }); + } getTestCaseFollow(this.caseId).then((response) => { this.form.follows = response.data; @@ -802,7 +810,12 @@ export default { this.checkVersionEnable(); }, editPublicCase(type) { - openCaseEdit({caseId: this.caseId, type}, this) + // 这个接口会校验权限 + getEditSimpleTestCase(this.caseId) + .then(() => { + openCaseEdit({caseId: this.caseId, type}, this); + }) + .catch(() => {}); }, copyPublicCase() { this.editPublicCase('copy'); @@ -980,7 +993,7 @@ export default { }, async checkCurrentProject() { if (this.isPublicShow) { - // 如果是用例库查看用例 + // 用例库查看用例 await getSimpleTestCase(this.caseId).then((response) => { let testCase = response.data; this.projectId = testCase.projectId; @@ -993,17 +1006,22 @@ export default { setCurrentProjectID(this.projectId); location.reload(); } - } else { - if (this.caseId) { - await getSimpleTestCase(this.caseId).then((response) => { - let testCase = response.data; - if (getCurrentProjectID() !== testCase.projectId) { - // 如果不是当前项目,先切项目 - setCurrentProjectID(testCase.projectId); - location.reload(); - } - }) - } + } else if (this.caseId) { + // 接口会校验是否有改用例的编辑权限 + await getEditSimpleTestCase(this.caseId).then((response) => { + let testCase = response.data; + if (getCurrentProjectID() !== testCase.projectId) { + // 如果不是当前项目,先切项目 + setCurrentProjectID(testCase.projectId); + location.reload(); + } else { + this.projectId = testCase.projectId; + } + }) + .catch(() => { + // 没有权限则跳转到根路径 + this.$router.push("/"); + }); } } }, diff --git a/test-track/frontend/src/business/case/components/case/CaseBaseInfo.vue b/test-track/frontend/src/business/case/components/case/CaseBaseInfo.vue index b06c9aa08b..d37ee977f4 100644 --- a/test-track/frontend/src/business/case/components/case/CaseBaseInfo.vue +++ b/test-track/frontend/src/business/case/components/case/CaseBaseInfo.vue @@ -47,7 +47,8 @@
-
+ +
{{ $t("test_track.case.module") }} diff --git a/test-track/frontend/src/business/case/components/public/PublicTestCaseList.vue b/test-track/frontend/src/business/case/components/public/PublicTestCaseList.vue index fdc36a0f96..598cb7d83a 100644 --- a/test-track/frontend/src/business/case/components/public/PublicTestCaseList.vue +++ b/test-track/frontend/src/business/case/components/public/PublicTestCaseList.vue @@ -229,8 +229,8 @@ import TestCaseReviewStatusTableItem from "@/business/common/tableItems/TestCase import BatchMove from "@/business/case/components/BatchMove"; import TestCasePreview from "@/business/case/components/TestCasePreview"; import { - deletePublicTestCaseVersion, editTestCaseOrder, getTestCase, - getTestCaseStep, getTestCaseVersions, testCaseBatchDeleteToGc, testCasePublicBatchCopy, + deletePublicTestCaseVersion, editTestCaseOrder, getEditSimpleTestCase, + getTestCaseStep, getTestCaseVersions, testCasePublicBatchCopy, testCasePublicBatchDeleteToGc, testCasePublicList, } from "@/api/testCase"; import ListItemDeleteConfirm from "metersphere-frontend/src/components/ListItemDeleteConfirm"; @@ -448,7 +448,12 @@ export default { this.selectCounts = this.$refs.table.selectDataCounts; }, handleEdit(testCase, type) { - openCaseEdit({caseId: testCase.id, type}, this); + // 这个接口会校验权限 + getEditSimpleTestCase(testCase.id) + .then(() => { + openCaseEdit({caseId: testCase.id, type}, this); + }) + .catch(() => {}); }, handleEditShow(testCase, column) { this.$refs.publicTestCaseShow.open(testCase.id); diff --git a/test-track/frontend/src/business/case/components/public/PublicTestCaseShow.vue b/test-track/frontend/src/business/case/components/public/PublicTestCaseShow.vue index 32b3420266..b9a08b56e8 100644 --- a/test-track/frontend/src/business/case/components/public/PublicTestCaseShow.vue +++ b/test-track/frontend/src/business/case/components/public/PublicTestCaseShow.vue @@ -66,7 +66,7 @@ export default { }, watch: { publicCaseId() { - if (this.publicCaseId) { + if (this.publicCaseId && this.$refs.testCaseEdit) { this.$refs.testCaseEdit.loadTestCase(); } }