Add Access Control
Problem
Implementing access control in react-admin components (e.g. showing/hiding datagrid columns of buttons depending on the user permissions) is hard because it's not built-in. It's doable by wrapping components in another component that checks permissions before rendering the actual component. But it's not the same component anymore.
// pseudo code
const DatagridWithAccessControl = ({ children, ...rest }) => {
const authorizedChildren = useAuthorizedChildren(children);
return <Datagrid {...rest}>{authorizedChildren}</Datagrid>;
}
React-admin Enterprise Edition uses this approach to provide alternative components with built-in access control (see https://react-admin-ee.marmelab.com/documentation/ra-rbac). But these components aren't compatible with other overrides (e.g. adding realtime updates, alternative layouts, etc).
Solution
Have react-admin components call an access control hook before rendering, leaving the actual implementation to the authProvider.
// pseudo code
const Datagrid = ({ children, ...rest }) => {
const authorizedChildren = useAuthorizedChildren(children);
// ...continue with authorizedChildren
}
How To Test
Describe the steps required to test the changes
Additional Checks
- [ ] The PR targets
masterfor a bugfix, ornextfor a feature - [ ] The PR includes unit tests (if not possible, describe why)
- [ ] The PR includes one or several stories (if not possible, describe why)
- [ ] The documentation is up to date
Also, please make sure to read the contributing guidelines.