Skip to content

Instantly share code, notes, and snippets.

@lifeart
Last active August 4, 2022 12:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lifeart/7ac06b977dae6035f5d53551920cd3ee to your computer and use it in GitHub Desktop.
Save lifeart/7ac06b977dae6035f5d53551920cd3ee to your computer and use it in GitHub Desktop.
Simple Roles Management
import { get } from 'lodash';
const permissions = {
study: {
see: ['STUDY_MANAGER', 'DATA_ENTRY', 'ADMIN'],
create: ['DATA_ENTRY', 'ADMIN'],
edit: ['STUDY_DIRECTOR', 'DATA_ENTRY', 'ADMIN'],
}
}
export default {
userRoles: ['ADMIN'],
hasAbility(path: string) {
return (
this.userRoles.find((role: string) =>
get(permissions, path).includes(role)
)
);
}
};
// how to use?
// security.hasAbility('study.edit')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment