BryanMLima commented on code in PR #8978:
URL: https://github.com/apache/cloudstack/pull/8978#discussion_r1580981216


##########
ui/src/store/modules/permission.js:
##########
@@ -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) {

Review Comment:
   Could use optional chaining here, no?
   ```suggestion
     if (!route.meta?.permission) {
   ```



##########
ui/src/store/modules/permission.js:
##########
@@ -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) {

Review Comment:
   Could use optional chaining here, no?
   ```suggestion
         if (route.meta?.section) {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to