Sfoglia il codice sorgente

Increase the permission judgment: when the user's permission is an array.

ubbcou 7 anni fa
parent
commit
fdd6035f94

+ 8 - 0
src/components/Authorized/CheckPermissions.js

@@ -29,6 +29,14 @@ const checkPermissions = (authority, currentAuthority, target, Exception) => {
     if (authority.indexOf(currentAuthority) >= 0) {
       return target;
     }
+    if (Array.isArray(currentAuthority)) {
+      for (let i = 0; i < currentAuthority.length; i += 1) {
+        const element = currentAuthority[i];
+        if (authority.indexOf(element) >= 0) {
+          return target;
+        }
+      }
+    }
     return Exception;
   }
 

+ 4 - 1
src/components/Authorized/renderAuthorize.js

@@ -10,7 +10,10 @@ const renderAuthorize = Authorized => {
       if (currentAuthority.constructor.name === 'Function') {
         CURRENT = currentAuthority();
       }
-      if (currentAuthority.constructor.name === 'String') {
+      if (
+        currentAuthority.constructor.name === 'String' ||
+        currentAuthority.constructor.name === 'Array'
+      ) {
         CURRENT = currentAuthority;
       }
     } else {

+ 1 - 0
src/utils/authority.js

@@ -1,5 +1,6 @@
 // use localStorage to store the authority info, which might be sent from server in actual project.
 export function getAuthority() {
+  // return localStorage.getItem('antd-pro-authority') || ['admin', 'user'];
   return localStorage.getItem('antd-pro-authority') || 'admin';
 }