Skip to content

Instantly share code, notes, and snippets.

@OR13
Created July 9, 2017 02:42
Show Gist options
  • Save OR13/39d6f6d36744dc2da9d28d614143c8c4 to your computer and use it in GitHub Desktop.
Save OR13/39d6f6d36744dc2da9d28d614143c8c4 to your computer and use it in GitHub Desktop.
AccessControl
var ac = new AccessControl();
ac.grant('user') // define new or modify existing role. also takes an array.
.createOwn('video') // equivalent to .createOwn('video', ['*'])
.deleteOwn('video')
.readAny('video')
.grant('admin') // switch to another role without breaking the chain
.extend('user') // inherit role capabilities. also takes an array
.updateAny('video', ['title']) // explicitly defined attributes
.deleteAny('video');
var permission = ac.can('user').createOwn('video');
console.log(permission.granted); // —> true
console.log(permission.attributes); // —> ['*'] (all attributes)
permission = ac.can('admin').updateAny('video');
console.log(permission.granted); // —> true
console.log(permission.attributes); // —> ['title']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment