first commit

This commit is contained in:
Senad Uka
2018-05-07 16:07:00 +02:00
commit 8b4f09f9d5
3368 changed files with 852614 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
/* global window */
import { createFactory } from 'react';
import { contains } from 'ramda';
const checkAuthorization = (user, roles) => {
const userRole = user.profiles[0];
const userOrgType = userRole.organization.type.key;
if (!roles) {
return true;
}
const role = roles[userRole.key];
if (role && contains(userOrgType, role)) {
return true;
}
return false;
};
const authorization = roles => ({
roles,
authorize(WrappedComponent) {
const loggedUser = JSON.parse(window.localStorage.getItem('loggedUser'));
if (!loggedUser) {
return (props) => {
props.router.push('/login');
return null;
};
}
const factory = createFactory(WrappedComponent);
const isAuthorized = checkAuthorization(loggedUser, roles);
if (!isAuthorized) {
return (props) => {
props.router.push('/404');
return null;
};
}
const Component = props => factory(props);
return Component;
},
});
export default authorization;

View File

@@ -0,0 +1,9 @@
import authorization from './authorization';
import normalizeRoles from './normalizeRoles';
const authorize = (...profiles) => {
const roles = normalizeRoles(profiles);
return authorization(roles).authorize;
};
export default authorize;

View File

@@ -0,0 +1,18 @@
import authorization from './authorization';
export { default as authorize } from './authorize';
export { default as loggedUser } from './loggedUser';
export { default as bcbsaScheduler } from './profiles/bcbsaScheduler';
export { default as bcbsiAdmin } from './profiles/bcbsiAdmin';
export { default as bcbsiScheduler } from './profiles/bcbsiScheduler';
export { default as planAdmin } from './profiles/planAdmin';
export { default as planScheduler } from './profiles/planScheduler';
export { default as programsupportSupport } from './profiles/programsupportSupport';
export { default as providerAdmin } from './profiles/providerAdmin';
export { default as providerScheduler } from './profiles/providerScheduler';
export { default as superAdmin } from './profiles/superAdmin';
export { default as support } from './profiles/support';
export { default as techsupportAdmin } from './profiles/techsupportAdmin';
export default authorization;

View 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;

View File

@@ -0,0 +1,40 @@
/* eslint no-console: "off" */
const { assign, keys } = Object;
const normalizeRoles = (profiles) => {
const roleKeys = keys(profiles);
if (roleKeys.length === 0) {
console.warn('[Authorize Warning] You need to specify at least one profile');
return arg => arg;
}
if (roleKeys.length === 1) {
return profiles[roleKeys[0]].authorize;
}
const roles = profiles.reduce((result, profile) => {
const profileRoles = keys(profile.roles).reduce((r, key) => {
const role = r;
if (result[key]) {
role[key] = result[key].concat(profile.roles[key]);
} else {
role[key] = profile.roles[key];
}
return role;
}, {});
return assign(
{},
result,
profileRoles,
);
}, {});
return roles;
};
export default normalizeRoles;

View File

@@ -0,0 +1,7 @@
import authorization from '../authorization';
const bcbsaScheduler = authorization({
SP: ['bcbsa'],
});
export default bcbsaScheduler;

View File

@@ -0,0 +1,7 @@
import authorization from '../authorization';
const bcbsiAdmin = authorization({
BCBSIAD: ['bcbsi'],
});
export default bcbsiAdmin;

View File

@@ -0,0 +1,7 @@
import authorization from '../authorization';
const bcbsiScheduler = authorization({
SP: ['bcbsi'],
});
export default bcbsiScheduler;

View File

@@ -0,0 +1,7 @@
import authorization from '../authorization';
const planAdmin = authorization({
PLANAD: ['plan'],
});
export default planAdmin;

View File

@@ -0,0 +1,7 @@
import authorization from '../authorization';
const planScheduler = authorization({
SP: ['plan'],
});
export default planScheduler;

View File

@@ -0,0 +1,7 @@
import authorization from '../authorization';
const programsupportSupport = authorization({
SPT: ['programsupport'],
});
export default programsupportSupport;

View File

@@ -0,0 +1,7 @@
import authorization from '../authorization';
const providerAdmin = authorization({
AD: ['provider'],
});
export default providerAdmin;

View File

@@ -0,0 +1,7 @@
import authorization from '../authorization';
const providerScheduler = authorization({
SP: ['provider'],
});
export default providerScheduler;

View File

@@ -0,0 +1,7 @@
import authorization from '../authorization';
const superAdmin = authorization({
AD: ['techsupport'],
});
export default superAdmin;

View File

@@ -0,0 +1,7 @@
import authorization from '../authorization';
const support = authorization({
SPT: ['programsupport'],
});
export default support;

View File

@@ -0,0 +1,7 @@
import authorization from '../authorization';
const techsupportAdmin = authorization({
AD: ['techsupport'],
});
export default techsupportAdmin;