Don't even render components if the user doesn't have permission

This commit is contained in:
Dane Everitt 2020-08-22 19:01:29 -07:00
parent 54f9c5f187
commit 9ae3c17913
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
4 changed files with 43 additions and 14 deletions

View file

@ -0,0 +1,27 @@
import React from 'react';
import Can from '@/components/elements/Can';
import NotFound from '@/components/screens/NotFound';
import ScreenBlock from '@/components/screens/ScreenBlock';
const requireServerPermission = (Component: React.ComponentType<any>, permissions: string | string[]) => {
return class extends React.Component<any, any> {
render () {
return (
<Can
action={permissions}
renderOnError={
<ScreenBlock
image={'/assets/svgs/server_error.svg'}
title={'Access Denied'}
message={'You do not have permission to access this page.'}
/>
}
>
<Component/>
</Can>
);
}
};
};
export default requireServerPermission;