Skip to content

Instantly share code, notes, and snippets.

@DeadAlready
Last active March 28, 2016 12:56
Show Gist options
  • Save DeadAlready/efe9c34983c5758d80fe to your computer and use it in GitHub Desktop.
Save DeadAlready/efe9c34983c5758d80fe to your computer and use it in GitHub Desktop.
erbac in the form of a class
class RBAC {
constructor(roles) {
if(typeof roles !== 'object') {
throw new TypeError('Expected an object as input');
}
this.roles = roles;
}
can(role, operation) {
return this.roles[role] && this.roles[role].can.indexOf(operation) !== -1;
}
}
module.exports = RBAC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment