Last active
March 28, 2016 12:56
-
-
Save DeadAlready/efe9c34983c5758d80fe to your computer and use it in GitHub Desktop.
erbac in the form of a class
This file contains 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
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