Browse Source

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

pull/1742/head
ubbcou 8 years ago
committed by 陈帅
parent
commit
fdd6035f94
  1. 8
      src/components/Authorized/CheckPermissions.js
  2. 5
      src/components/Authorized/renderAuthorize.js
  3. 1
      src/utils/authority.js

8
src/components/Authorized/CheckPermissions.js

@ -29,6 +29,14 @@ const checkPermissions = (authority, currentAuthority, target, Exception) => {
if (authority.indexOf(currentAuthority) >= 0) { if (authority.indexOf(currentAuthority) >= 0) {
return target; 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; return Exception;
} }

5
src/components/Authorized/renderAuthorize.js

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

1
src/utils/authority.js

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

Loading…
Cancel
Save