From ee50e7456e921b0b56e1965b2c74e2bf0a52abee Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Tue, 16 May 2023 14:39:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E9=A1=B9=E7=9B=AE=E6=9D=83=E9=99=90=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E7=94=A8=E4=BE=8B=E7=BC=96=E8=BE=91=E9=A1=B5=EF=BC=8C?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E4=BC=9A=E4=B8=8D=E5=81=9C=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1026176 --user=陈建星 【测试跟踪】无项目权限用户打开用例编辑地址url-页面一直重复刷新 https://www.tapd.cn/55049933/s/1371847 --- .../frontend/src/utils/permission.js | 35 +++++++++++++++++++ .../business/case/components/TestCaseEdit.vue | 6 ++++ 2 files changed, 41 insertions(+) diff --git a/framework/sdk-parent/frontend/src/utils/permission.js b/framework/sdk-parent/frontend/src/utils/permission.js index 8f25081fc8..a24ec3b8f9 100644 --- a/framework/sdk-parent/frontend/src/utils/permission.js +++ b/framework/sdk-parent/frontend/src/utils/permission.js @@ -68,6 +68,41 @@ export function hasPermission(permission) { return false; } +export function hasPermissionForProjectId(permission, projectId) { + let user = getCurrentUser(); + if (!user || !user.groups) { + return false; + } + let index = user.groups.findIndex(g => g.id === SUPER_GROUP); + if (index !== -1) { + return true; + } + + user.userGroups.forEach(ug => { + user.groupPermissions.forEach(gp => { + if (gp.group.id === ug.groupId) { + ug.userGroupPermissions = gp.userGroupPermissions; + ug.group = gp.group; + } + }); + }); + + let currentProjectPermissions = user.userGroups.filter(ug => ug.group && ug.group.type === 'PROJECT') + .filter(ug => ug.sourceId === projectId) + .flatMap(ug => ug.userGroupPermissions) + .map(g => g.permissionId) + .reduce((total, current) => { + total.add(current); + return total; + }, new Set); + for (const p of currentProjectPermissions) { + if (p === permission) { + return true; + } + } + return false; +} + export function hasPermissions(...permissions) { for (let p of permissions) { if (hasPermission(p)) { diff --git a/test-track/frontend/src/business/case/components/TestCaseEdit.vue b/test-track/frontend/src/business/case/components/TestCaseEdit.vue index 14d9a3aef0..006b9f532a 100644 --- a/test-track/frontend/src/business/case/components/TestCaseEdit.vue +++ b/test-track/frontend/src/business/case/components/TestCaseEdit.vue @@ -327,6 +327,7 @@ import { import { hasLicense, hasPermission, + hasPermissionForProjectId } from "metersphere-frontend/src/utils/permission"; import { getUUID, @@ -1025,6 +1026,11 @@ export default { this.projectId = this.routeProjectId; if (this.projectId) { // 带了 routeProjectId 校验是否是当前项目 + if (!hasPermissionForProjectId('PROJECT_TRACK_CASE:READ', this.projectId)) { + // 没有该项目权限,跳转到根目录 + this.$router.push({path: "/"}); + return; + } if (getCurrentProjectID() !== this.projectId) { setCurrentProjectID(this.projectId); location.reload();