refactor(权限管理): 权限指令修改
This commit is contained in:
parent
4350078392
commit
2f74b4bb56
|
@ -1,31 +1,34 @@
|
|||
<template>
|
||||
<el-menu menu-trigger="click" :default-active="$route.path" router class="setting">
|
||||
<el-submenu index="1" v-roles="['admin']">
|
||||
<el-submenu index="1">
|
||||
<template v-slot:title>
|
||||
<font-awesome-icon class="icon account" :icon="['far', 'address-card']" size="lg"/>
|
||||
<span>{{ $t('commons.system') }}</span>
|
||||
</template>
|
||||
<el-menu-item v-for="menu in systems" :key="menu.index" :index="menu.index" class="setting-item">
|
||||
<el-menu-item v-for="menu in systems" :key="menu.index" v-permission="menu.permissions" :index="menu.index"
|
||||
class="setting-item">
|
||||
{{ $t(menu.title) }}
|
||||
</el-menu-item>
|
||||
</el-submenu>
|
||||
|
||||
<el-submenu index="2" v-roles="['org_admin']" v-if="isCurrentOrganizationAdmin">
|
||||
<el-submenu index="2" v-if="isCurrentOrganizationAdmin">
|
||||
<template v-slot:title>
|
||||
<font-awesome-icon class="icon organization" :icon="['far', 'building']" size="lg"/>
|
||||
<span>{{ $t('commons.organization') }}</span>
|
||||
</template>
|
||||
<el-menu-item v-for="menu in organizations" :key="menu.index" :index="menu.index" class="setting-item">
|
||||
<el-menu-item v-for="menu in organizations" v-permission="menu.permissions" :key="menu.index" :index="menu.index"
|
||||
class="setting-item">
|
||||
{{ $t(menu.title) }}
|
||||
</el-menu-item>
|
||||
</el-submenu>
|
||||
|
||||
<el-submenu index="3" v-roles="['test_manager']" v-if="isCurrentWorkspaceUser">
|
||||
<el-submenu index="3" v-if="isCurrentWorkspaceUser">
|
||||
<template v-slot:title>
|
||||
<font-awesome-icon class="icon workspace" :icon="['far', 'list-alt']" size="lg"/>
|
||||
<span>{{ $t('commons.workspace') }}</span>
|
||||
</template>
|
||||
<el-menu-item v-for="menu in workspaces" :key="menu.index" :index="menu.index" class="setting-item">
|
||||
<el-menu-item v-for="menu in workspaces" v-permission="menu.permissions" :key="menu.index" :index="menu.index"
|
||||
class="setting-item">
|
||||
{{ $t(menu.title) }}
|
||||
</el-menu-item>
|
||||
<el-submenu index="3-1">
|
||||
|
@ -37,12 +40,13 @@
|
|||
</el-submenu>
|
||||
</el-submenu>
|
||||
|
||||
<el-submenu index="4" v-roles="['test_user','test_manager', 'org_admin', 'admin']">
|
||||
<el-submenu index="4">
|
||||
<template v-slot:title>
|
||||
<font-awesome-icon class="icon" :icon="['fa', 'bars']" size="lg"/>
|
||||
<span>{{ $t('commons.project') }}</span>
|
||||
</template>
|
||||
<el-menu-item v-for="menu in project" :key="menu.index" :index="menu.index" class="setting-item">
|
||||
<el-menu-item v-for="menu in project" v-permission="menu.permissions" :key="menu.index" :index="menu.index"
|
||||
class="setting-item">
|
||||
{{ $t(menu.title) }}
|
||||
</el-menu-item>
|
||||
</el-submenu>
|
||||
|
@ -50,18 +54,17 @@
|
|||
<!-- <el-menu-item v-for="menu in project" :key="menu.index" :index="'/setting/project/all'" class="setting-item"-->
|
||||
<!-- v-roles="['test_user','test_manager', 'org_admin', 'admin']">-->
|
||||
<!-- <template v-slot:title>-->
|
||||
<!-- <font-awesome-icon class="icon" :icon="['fa', 'bars']" size="lg"/>-->
|
||||
<!-- <span>{{ $t(menu.title) }}</span>-->
|
||||
<!-- </template>-->
|
||||
<!-- </el-menu-item>-->
|
||||
<!-- <font-awesome-icon class="icon" :icon="['fa', 'bars']" size="lg"/>-->
|
||||
<!-- <span>{{ $t(menu.title) }}</span>-->
|
||||
<!-- </template>-->
|
||||
<!-- </el-menu-item>-->
|
||||
|
||||
<el-submenu index="5">
|
||||
<template v-slot:title>
|
||||
<font-awesome-icon class="icon" :icon="['far', 'user']" size="lg"/>
|
||||
<span>{{ $t('commons.personal_info') }}</span>
|
||||
</template>
|
||||
<el-menu-item v-for="menu in persons" :key="menu.index" :index="menu.index" class="setting-item"
|
||||
v-roles="menu.roles">
|
||||
<el-menu-item v-for="menu in persons" :key="menu.index" :index="menu.index" class="setting-item">
|
||||
{{ $t(menu.title) }}
|
||||
</el-menu-item>
|
||||
</el-submenu>
|
||||
|
@ -71,89 +74,90 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import {checkoutCurrentOrganization, checkoutCurrentWorkspace} from "@/common/js/utils";
|
||||
import Setting from "@/business/components/settings/router";
|
||||
import {LicenseKey} from '@/common/js/constants';
|
||||
import {checkoutCurrentOrganization, checkoutCurrentWorkspace} from "@/common/js/utils";
|
||||
import Setting from "@/business/components/settings/router";
|
||||
import {LicenseKey} from '@/common/js/constants';
|
||||
|
||||
const requireComponent = require.context('@/business/components/xpack/', true, /\.vue$/);
|
||||
const component = requireComponent.keys().length > 0 ? requireComponent("./license/LicenseMessage.vue") : null;
|
||||
const requireComponent = require.context('@/business/components/xpack/', true, /\.vue$/);
|
||||
const component = requireComponent.keys().length > 0 ? requireComponent("./license/LicenseMessage.vue") : null;
|
||||
|
||||
export default {
|
||||
name: "MsSettingMenu",
|
||||
data() {
|
||||
let getMenus = function (group) {
|
||||
let menus = [];
|
||||
Setting.children.forEach(child => {
|
||||
if (child.meta[group] === true) {
|
||||
let menu = {index: Setting.path + "/" + child.path}
|
||||
menu.title = child.meta.title;
|
||||
menu.roles = child.meta.roles;
|
||||
menu.valid = child.meta.valid;
|
||||
menus.push(menu);
|
||||
}
|
||||
})
|
||||
return menus;
|
||||
}
|
||||
return {
|
||||
systems: getMenus('system'),
|
||||
organizations: getMenus('organization'),
|
||||
workspaces: getMenus('workspace'),
|
||||
persons: getMenus('person'),
|
||||
project: getMenus('project'),
|
||||
workspaceTemplate: getMenus('workspaceTemplate'),
|
||||
isCurrentOrganizationAdmin: false,
|
||||
isCurrentWorkspaceUser: false,
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
valid() {
|
||||
Promise.all([component.default.valid(this)]).then(() => {
|
||||
let license = localStorage.getItem(LicenseKey);
|
||||
if (license != "valid") {
|
||||
this.systems.forEach(item => {
|
||||
if (item.valid === true) {
|
||||
this.systems.splice(this.systems.indexOf(item), 1);
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.isCurrentOrganizationAdmin = checkoutCurrentOrganization();
|
||||
this.isCurrentWorkspaceUser = checkoutCurrentWorkspace();
|
||||
if (component != null) {
|
||||
this.valid();
|
||||
}
|
||||
},
|
||||
}
|
||||
export default {
|
||||
name: "MsSettingMenu",
|
||||
data() {
|
||||
let getMenus = function (group) {
|
||||
let menus = [];
|
||||
Setting.children.forEach(child => {
|
||||
if (child.meta[group] === true) {
|
||||
let menu = {index: Setting.path + "/" + child.path};
|
||||
menu.title = child.meta.title;
|
||||
menu.roles = child.meta.roles;
|
||||
menu.permissions = child.meta.permissions;
|
||||
menu.valid = child.meta.valid;
|
||||
menus.push(menu);
|
||||
}
|
||||
});
|
||||
return menus;
|
||||
};
|
||||
return {
|
||||
systems: getMenus('system'),
|
||||
organizations: getMenus('organization'),
|
||||
workspaces: getMenus('workspace'),
|
||||
persons: getMenus('person'),
|
||||
project: getMenus('project'),
|
||||
workspaceTemplate: getMenus('workspaceTemplate'),
|
||||
isCurrentOrganizationAdmin: false,
|
||||
isCurrentWorkspaceUser: false,
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
valid() {
|
||||
Promise.all([component.default.valid(this)]).then(() => {
|
||||
let license = localStorage.getItem(LicenseKey);
|
||||
if (license != "valid") {
|
||||
this.systems.forEach(item => {
|
||||
if (item.valid === true) {
|
||||
this.systems.splice(this.systems.indexOf(item), 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.isCurrentOrganizationAdmin = checkoutCurrentOrganization();
|
||||
this.isCurrentWorkspaceUser = checkoutCurrentWorkspace();
|
||||
if (component != null) {
|
||||
this.valid();
|
||||
}
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
.setting {
|
||||
border-right: 0;
|
||||
}
|
||||
.setting {
|
||||
border-right: 0;
|
||||
}
|
||||
|
||||
.setting .setting-item {
|
||||
height: 40px;
|
||||
line-height: 40px;
|
||||
}
|
||||
.setting .setting-item {
|
||||
height: 40px;
|
||||
line-height: 40px;
|
||||
}
|
||||
|
||||
.icon {
|
||||
width: 24px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.icon {
|
||||
width: 24px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.account {
|
||||
color: #5a78f0;
|
||||
}
|
||||
.account {
|
||||
color: #5a78f0;
|
||||
}
|
||||
|
||||
.organization {
|
||||
color: #b33a5b;
|
||||
}
|
||||
.organization {
|
||||
color: #b33a5b;
|
||||
}
|
||||
|
||||
.workspace {
|
||||
color: #44b349;
|
||||
}
|
||||
.workspace {
|
||||
color: #44b349;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const requireContext = require.context('@/business/components/xpack/', true, /router\.js$/)
|
||||
const requireContext = require.context('@/business/components/xpack/', true, /router\.js$/);
|
||||
|
||||
export default {
|
||||
path: "/setting",
|
||||
|
@ -10,80 +10,84 @@ export default {
|
|||
{
|
||||
path: 'user',
|
||||
component: () => import('@/business/components/settings/system/User'),
|
||||
meta: {system: true, title: 'commons.user'}
|
||||
meta: {system: true, title: 'commons.user', permissions: ['SYSTEM_USER:READ']}
|
||||
},
|
||||
{
|
||||
path: 'organization',
|
||||
component: () => import('@/business/components/settings/system/Organization'),
|
||||
meta: {system: true, title: 'commons.organization'}
|
||||
meta: {system: true, title: 'commons.organization', permissions: ['SYSTEM_ORGANIZATION:READ']}
|
||||
},
|
||||
{
|
||||
path: 'usergroup',
|
||||
component: () => import('@/business/components/settings/system/group/UserGroup'),
|
||||
meta: {system: true, title: '用户组与权限'}
|
||||
meta: {system: true, title: '用户组与权限', permissions: ['SYSTEM_GROUP:READ']}
|
||||
},
|
||||
{
|
||||
path: 'workspace/template/field',
|
||||
component: () => import('@/business/components/settings/workspace/template/CustomFieldList'),
|
||||
meta: {workspaceTemplate: true, title: 'custom_field.name'},
|
||||
meta: {workspaceTemplate: true, title: 'custom_field.name', permissions: ['WORKSPACE_TEMPLATE:READ']},
|
||||
},
|
||||
{
|
||||
path: 'workspace/template/case',
|
||||
component: () => import('@/business/components/settings/workspace/template/TestCaseTemplateList'),
|
||||
meta: {workspaceTemplate: true, title: '用例模板'},
|
||||
meta: {workspaceTemplate: true, title: '用例模板', permissions: ['WORKSPACE_TEMPLATE:READ']},
|
||||
},
|
||||
{
|
||||
path: 'workspace/template/issues',
|
||||
component: () => import('@/business/components/settings/workspace/template/IssuesTemplateList'),
|
||||
meta: {workspaceTemplate: true, title: '缺陷模板'},
|
||||
meta: {workspaceTemplate: true, title: '缺陷模板', permissions: ['WORKSPACE_TEMPLATE:READ']},
|
||||
},
|
||||
{
|
||||
path: 'workspace/template/report',
|
||||
name: 'testCaseReportTemplate',
|
||||
component: () => import('@/business/components/settings/workspace/template/TestCaseReportTemplate'),
|
||||
meta: {workspaceTemplate: true, title: 'test_track.plan_view.report_template'}
|
||||
meta: {
|
||||
workspaceTemplate: true,
|
||||
title: 'test_track.plan_view.report_template',
|
||||
permissions: ['WORKSPACE_TEMPLATE:READ']
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'systemworkspace',
|
||||
component: () => import('@/business/components/settings/system/SystemWorkspace'),
|
||||
meta: {system: true, title: 'commons.workspace'}
|
||||
meta: {system: true, title: 'commons.workspace', permissions: ['SYSTEM_WORKSPACE:READ']}
|
||||
},
|
||||
{
|
||||
path: 'testresourcepool',
|
||||
component: () => import('@/business/components/settings/system/TestResourcePool'),
|
||||
meta: {system: true, title: 'commons.test_resource_pool'}
|
||||
meta: {system: true, title: 'commons.test_resource_pool', permissions: ['SYSTEM_WORKSPACE:READ']}
|
||||
},
|
||||
{
|
||||
path: 'systemparametersetting',
|
||||
component: () => import('@/business/components/settings/system/SystemParameterSetting'),
|
||||
meta: {system: true, title: 'commons.system_parameter_setting'}
|
||||
meta: {system: true, title: 'commons.system_parameter_setting', permissions: ['SYSTEM_SETTING:READ']}
|
||||
},
|
||||
...requireContext.keys().map(key => requireContext(key).system),
|
||||
...requireContext.keys().map(key => requireContext(key).license),
|
||||
{
|
||||
path: 'organizationpmnmember',
|
||||
component: () => import('@/business/components/settings/organization/OrganizationMember'),
|
||||
meta: {organization: true, title: 'commons.member'}
|
||||
meta: {organization: true, title: 'commons.member', permissions: ['ORGANIZATION_USER:READ']}
|
||||
},
|
||||
{
|
||||
path: 'organizationworkspace',
|
||||
component: () => import('@/business/components/settings/organization/OrganizationWorkspace'),
|
||||
meta: {organization: true, title: 'commons.workspace'}
|
||||
meta: {organization: true, title: 'commons.workspace', permissions: ['ORGANIZATION_WORKSPACE:READ']}
|
||||
},
|
||||
{
|
||||
path: 'serviceintegration',
|
||||
component: () => import('@/business/components/settings/organization/ServiceIntegration'),
|
||||
meta: {organization: true, title: 'organization.service_integration'}
|
||||
meta: {organization: true, title: 'organization.service_integration', permissions: ['ORGANIZATION_SERVICE:READ']}
|
||||
},
|
||||
{
|
||||
path: 'messagesettings',
|
||||
component: () => import('@/business/components/settings/organization/MessageSettings'),
|
||||
meta: {organization: true, title: 'organization.message_settings'}
|
||||
meta: {organization: true, title: 'organization.message_settings', permissions: ['ORGANIZATION_MESSAGE:READ']}
|
||||
},
|
||||
{
|
||||
path: 'member',
|
||||
component: () => import('@/business/components/settings/workspace/WorkspaceMember'),
|
||||
meta: {workspace: true, title: 'commons.member'}
|
||||
meta: {workspace: true, title: 'commons.member', permissions: ['WORKSPACE_USER:READ']}
|
||||
},
|
||||
{
|
||||
path: 'personsetting',
|
||||
|
@ -102,12 +106,12 @@ export default {
|
|||
{
|
||||
path: 'project/:type',
|
||||
component: () => import('@/business/components/settings/project/MsProject'),
|
||||
meta: {project: true, title: 'project.manager'}
|
||||
meta: {project: true, title: 'project.manager', permissions: ['PROJECT_MANAGER:READ']}
|
||||
},
|
||||
{
|
||||
path: 'envlist',
|
||||
component: () => import('@/business/components/settings/project/EnvironmentList'),
|
||||
meta: {project: true, title: 'api_test.environment.environment_config'}
|
||||
meta: {project: true, title: 'api_test.environment.environment_config', permissions: ['PROJECT_ENVIRONMENT:READ']}
|
||||
},
|
||||
{
|
||||
path: 'operatingLog',
|
||||
|
@ -116,4 +120,4 @@ export default {
|
|||
}
|
||||
|
||||
]
|
||||
}
|
||||
};
|
||||
|
|
|
@ -55,17 +55,18 @@ export function hasRolePermission(role) {
|
|||
export function hasPermission(permission) {
|
||||
let user = getCurrentUser();
|
||||
|
||||
user.groupPermissions.forEach(gp => {
|
||||
for (let userGroup of user.userGroups) {
|
||||
if (gp.group.id === userGroup.id) {
|
||||
gp.sourceId = userGroup.sourceId;
|
||||
user.userGroups.forEach(ug => {
|
||||
user.groupPermissions.forEach(gp => {
|
||||
if (gp.group.id === ug.groupId) {
|
||||
ug.userGroupPermissions = gp.userGroupPermissions;
|
||||
ug.group = gp.group;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// todo 权限验证
|
||||
let currentProjectPermissions = user.groupPermissions.filter(gp => gp.group.type === 'PROJECT')
|
||||
.filter(gp => gp.group.scopeId === getCurrentProjectID())[0]?.userGroupPermissions
|
||||
let currentProjectPermissions = user.userGroups.filter(ug => ug.group.type === 'PROJECT')
|
||||
.filter(g => g.sourceId === getCurrentProjectID())[0]?.userGroupPermissions
|
||||
.map(g => g.permissionId) || [];
|
||||
|
||||
for (const p of currentProjectPermissions) {
|
||||
|
@ -74,8 +75,8 @@ export function hasPermission(permission) {
|
|||
}
|
||||
}
|
||||
|
||||
let currentWorkspacePermissions = user.groupPermissions.filter(gp => gp.group.type === 'WORKSPACE')
|
||||
.filter(gp => gp.group.scopeId === getCurrentWorkspaceId())[0]?.userGroupPermissions
|
||||
let currentWorkspacePermissions = user.userGroups.filter(ug => ug.group.type === 'WORKSPACE')
|
||||
.filter(g => g.sourceId === getCurrentWorkspaceId())[0]?.userGroupPermissions
|
||||
.map(g => g.permissionId) || [];
|
||||
|
||||
for (const p of currentWorkspacePermissions) {
|
||||
|
@ -84,8 +85,8 @@ export function hasPermission(permission) {
|
|||
}
|
||||
}
|
||||
|
||||
let currentOrganizationPermissions = user.groupPermissions.filter(gp => gp.group.type === 'ORGANIZATION')
|
||||
.filter(gp => gp.group.scopeId === getCurrentOrganizationId())[0]?.userGroupPermissions
|
||||
let currentOrganizationPermissions = user.userGroups.filter(ug => ug.group.type === 'ORGANIZATION')
|
||||
.filter(ug => ug.sourceId === getCurrentOrganizationId())[0]?.userGroupPermissions
|
||||
.map(g => g.permissionId) || [];
|
||||
|
||||
for (const p of currentOrganizationPermissions) {
|
||||
|
@ -94,8 +95,8 @@ export function hasPermission(permission) {
|
|||
}
|
||||
}
|
||||
|
||||
let systemPermissions = user.groupPermissions.filter(gp => gp.group.type === 'SYSTEM')
|
||||
.filter(gp => gp.group.scopeId === 'global')[0]?.userGroupPermissions
|
||||
let systemPermissions = user.userGroups.filter(gp => gp.group.type === 'SYSTEM')
|
||||
.filter(ug => ug.sourceId === 'system')[0]?.userGroupPermissions
|
||||
.map(g => g.permissionId) || [];
|
||||
|
||||
for (const p of systemPermissions) {
|
||||
|
|
Loading…
Reference in New Issue