mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01: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,
|
icon: section.icon,
|
||||||
docHelp: vueProps.$applyDocHelpMappings(section.docHelp),
|
docHelp: vueProps.$applyDocHelpMappings(section.docHelp),
|
||||||
searchFilters: section.searchFilters,
|
searchFilters: section.searchFilters,
|
||||||
related: section.related
|
related: section.related,
|
||||||
|
section: true
|
||||||
},
|
},
|
||||||
component: shallowRef(RouteView)
|
component: shallowRef(RouteView)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (section.children && section.children.length > 0) {
|
if (section.children && section.children.length > 0) {
|
||||||
map.redirect = '/' + section.children[0].name
|
|
||||||
map.meta.permission = section.children[0].permission
|
|
||||||
map.children = []
|
map.children = []
|
||||||
for (const child of section.children) {
|
for (const child of section.children) {
|
||||||
if ('show' in child && !child.show()) {
|
if ('show' in child && !child.show()) {
|
||||||
|
|||||||
@ -17,24 +17,39 @@
|
|||||||
|
|
||||||
import { asyncRouterMap, constantRouterMap } from '@/config/router'
|
import { asyncRouterMap, constantRouterMap } from '@/config/router'
|
||||||
|
|
||||||
function hasApi (apis, route) {
|
function hasAccessToRoute (apis, route) {
|
||||||
if (route.meta && route.meta.permission) {
|
if (!route.meta || !route.meta.permission) {
|
||||||
for (const permission of route.meta.permission) {
|
|
||||||
if (!apis.includes(permission)) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
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
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
function filterAsyncRouter (routerMap, apis) {
|
function filterAsyncRouter (routerMap, apis) {
|
||||||
const accessedRouters = routerMap.filter(route => {
|
const accessedRouters = routerMap.filter(route => {
|
||||||
if (hasApi(apis, route)) {
|
if (hasAccessToRoute(apis, route)) {
|
||||||
if (route.children && route.children.length > 0) {
|
if (route.children && route.children.length > 0) {
|
||||||
route.children = filterAsyncRouter(route.children, apis)
|
route.children = filterAsyncRouter(route.children, apis)
|
||||||
}
|
}
|
||||||
|
if (route.meta && route.meta.section) {
|
||||||
|
return hasAccessToSection(route)
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user