fix(测试跟踪): 没有项目权限访问用例编辑页,页面会不停刷新
--bug=1026176 --user=陈建星 【测试跟踪】无项目权限用户打开用例编辑地址url-页面一直重复刷新 https://www.tapd.cn/55049933/s/1371847
This commit is contained in:
parent
31dc592f7c
commit
ee50e7456e
|
@ -68,6 +68,41 @@ export function hasPermission(permission) {
|
||||||
return false;
|
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) {
|
export function hasPermissions(...permissions) {
|
||||||
for (let p of permissions) {
|
for (let p of permissions) {
|
||||||
if (hasPermission(p)) {
|
if (hasPermission(p)) {
|
||||||
|
|
|
@ -327,6 +327,7 @@ import {
|
||||||
import {
|
import {
|
||||||
hasLicense,
|
hasLicense,
|
||||||
hasPermission,
|
hasPermission,
|
||||||
|
hasPermissionForProjectId
|
||||||
} from "metersphere-frontend/src/utils/permission";
|
} from "metersphere-frontend/src/utils/permission";
|
||||||
import {
|
import {
|
||||||
getUUID,
|
getUUID,
|
||||||
|
@ -1025,6 +1026,11 @@ export default {
|
||||||
this.projectId = this.routeProjectId;
|
this.projectId = this.routeProjectId;
|
||||||
if (this.projectId) {
|
if (this.projectId) {
|
||||||
// 带了 routeProjectId 校验是否是当前项目
|
// 带了 routeProjectId 校验是否是当前项目
|
||||||
|
if (!hasPermissionForProjectId('PROJECT_TRACK_CASE:READ', this.projectId)) {
|
||||||
|
// 没有该项目权限,跳转到根目录
|
||||||
|
this.$router.push({path: "/"});
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (getCurrentProjectID() !== this.projectId) {
|
if (getCurrentProjectID() !== this.projectId) {
|
||||||
setCurrentProjectID(this.projectId);
|
setCurrentProjectID(this.projectId);
|
||||||
location.reload();
|
location.reload();
|
||||||
|
|
Loading…
Reference in New Issue