Skip to content

Instantly share code, notes, and snippets.

@lifeart lifeart/ability.ts
Last active Jan 17, 2020

Embed
What would you like to do?
Simple Roles Management
import { get } from '@ember/object';
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.filter((role: string) =>
get(permissions, path).includes(role)
).length > 0
);
}
};
// 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
You can’t perform that action at this time.