first commit
This commit is contained in:
28
src/utils/authorization/loggedUser.js
Normal file
28
src/utils/authorization/loggedUser.js
Normal file
@@ -0,0 +1,28 @@
|
||||
/* global window */
|
||||
import { contains } from 'ramda';
|
||||
|
||||
import normalizeRoles from './normalizeRoles';
|
||||
|
||||
const loggedUser = JSON.parse(window.localStorage.getItem('loggedUser'));
|
||||
|
||||
if (loggedUser) {
|
||||
loggedUser.anyOf = (...profiles) => {
|
||||
const userRole = loggedUser.profiles[0];
|
||||
const userOrgType = userRole.organization.type.key;
|
||||
const roles = normalizeRoles(profiles);
|
||||
|
||||
if (!roles) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const role = roles[userRole.key];
|
||||
|
||||
if (role && contains(userOrgType, role)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
export default loggedUser;
|
||||
Reference in New Issue
Block a user