Created
July 9, 2017 02:42
-
-
Save OR13/39d6f6d36744dc2da9d28d614143c8c4 to your computer and use it in GitHub Desktop.
AccessControl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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