IO-909 RBAC Shift Editing

This commit is contained in:
Patrick Fic
2021-04-22 09:52:49 -07:00
parent e6c7599813
commit cdf99a16fe
11 changed files with 207 additions and 55 deletions

View File

@@ -5,19 +5,16 @@ import { createStructuredSelector } from "reselect";
import {
selectAuthLevel,
selectBodyshop,
selectCurrentUser,
} from "../../redux/user/user.selectors";
import AlertComponent from "../alert/alert.component";
import rbacDefaults from "./rbac-defaults";
const mapStateToProps = createStructuredSelector({
currentUser: selectCurrentUser,
authLevel: selectAuthLevel,
bodyshop: selectBodyshop,
});
function RbacWrapper({
currentUser,
authLevel,
bodyshop,
requiredAuthLevel,
@@ -33,7 +30,9 @@ function RbacWrapper({
(requiredAuthLevel && requiredAuthLevel <= authLevel) ||
((bodyshop.md_rbac && bodyshop.md_rbac[action]) || rbacDefaults[action]) <=
authLevel ||
(!bodyshop.md_rbac && rbacDefaults[action] <= authLevel)
(bodyshop.md_rbac &&
!bodyshop.md_rbac[action] &&
rbacDefaults[action] <= authLevel)
)
return children;
//return <div>{React.cloneElement(children, restProps)}</div>;
@@ -48,12 +47,28 @@ function RbacWrapper({
);
}
// RbacWrapper.propTypes = {
// currentUser: PropTypes.object.isRequired,
// authLevel: PropTypes.number.isRequired,
// noauth: PropTypes.oneOfType(PropTypes.string, PropTypes.func),
// requiredAuthLevel: PropTypes.number,
// action: PropTypes.string,
// };
export function HasRbacAccess({
authLevel,
bodyshop,
requiredAuthLevel,
action,
}) {
console.log(
"Checking access for action",
action,
bodyshop.md_rbac[action],
authLevel,
bodyshop.md_rbac[action] <= authLevel
);
return (
(requiredAuthLevel && requiredAuthLevel <= authLevel) ||
((bodyshop.md_rbac && bodyshop.md_rbac[action]) || rbacDefaults[action]) <=
authLevel ||
(bodyshop.md_rbac &&
!bodyshop.md_rbac[action] &&
rbacDefaults[action] <= authLevel)
);
}
export default connect(mapStateToProps, null)(RbacWrapper);