mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 01:32:18 +02:00
Show menu section if user has access to at least one of its pages (#8978)
This commit is contained in:
parent
380385d045
commit
00ee5fd429
@ -51,14 +51,13 @@ function generateRouterMap (section) {
|
||||
icon: section.icon,
|
||||
docHelp: vueProps.$applyDocHelpMappings(section.docHelp),
|
||||
searchFilters: section.searchFilters,
|
||||
related: section.related
|
||||
related: section.related,
|
||||
section: true
|
||||
},
|
||||
component: shallowRef(RouteView)
|
||||
}
|
||||
|
||||
if (section.children && section.children.length > 0) {
|
||||
map.redirect = '/' + section.children[0].name
|
||||
map.meta.permission = section.children[0].permission
|
||||
map.children = []
|
||||
for (const child of section.children) {
|
||||
if ('show' in child && !child.show()) {
|
||||
|
||||
@ -17,24 +17,39 @@
|
||||
|
||||
import { asyncRouterMap, constantRouterMap } from '@/config/router'
|
||||
|
||||
function hasApi (apis, route) {
|
||||
if (route.meta && route.meta.permission) {
|
||||
for (const permission of route.meta.permission) {
|
||||
if (!apis.includes(permission)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
function hasAccessToRoute (apis, route) {
|
||||
if (!route.meta || !route.meta.permission) {
|
||||
return true
|
||||
}
|
||||
for (const permission of route.meta.permission) {
|
||||
if (!apis.includes(permission)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
function hasAccessToSection (route) {
|
||||
const visibleChildren = route.children.filter(child => !child.hidden)
|
||||
if (visibleChildren.length === 0) {
|
||||
return false
|
||||
}
|
||||
const redirect = '/' + visibleChildren[0].meta.name
|
||||
if (redirect !== route.path) {
|
||||
route.redirect = redirect
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
function filterAsyncRouter (routerMap, apis) {
|
||||
const accessedRouters = routerMap.filter(route => {
|
||||
if (hasApi(apis, route)) {
|
||||
if (hasAccessToRoute(apis, route)) {
|
||||
if (route.children && route.children.length > 0) {
|
||||
route.children = filterAsyncRouter(route.children, apis)
|
||||
}
|
||||
if (route.meta && route.meta.section) {
|
||||
return hasAccessToSection(route)
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user