From fdd6035f94faaf7c826741c6c73c004ac306ae56 Mon Sep 17 00:00:00 2001 From: ubbcou Date: Tue, 26 Jun 2018 17:48:36 +0800 Subject: [PATCH] Increase the permission judgment: when the user's permission is an array. --- src/components/Authorized/CheckPermissions.js | 8 ++++++++ src/components/Authorized/renderAuthorize.js | 5 ++++- src/utils/authority.js | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/Authorized/CheckPermissions.js b/src/components/Authorized/CheckPermissions.js index a79e2859..df6fdb7f 100644 --- a/src/components/Authorized/CheckPermissions.js +++ b/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; } diff --git a/src/components/Authorized/renderAuthorize.js b/src/components/Authorized/renderAuthorize.js index 8e34c694..16177ede 100644 --- a/src/components/Authorized/renderAuthorize.js +++ b/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 { diff --git a/src/utils/authority.js b/src/utils/authority.js index dc285655..424496b2 100644 --- a/src/utils/authority.js +++ b/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'; } -- GitLab