Simple Permissions
Trivial permissions implementation with following features
- Many to many permissions (if you need one to many it is very easy to write some sort of wrapper)
- Crossbrowser/Crossplatform
- tested with ~100% coverage
Dependencies
- Lodash
License
Installation:
bower install simple-permissions
npm install simple-permissions
Tests:
To launch tests you have to run npm install
then npm test
.
If you want to contribute make sure to run grunt githooks
first thing after clone.
It will create pre-commit hook and run tests and jshint before you commit.
Please use git flow - create a feature branch for your feature and send a pull request to dev.
Please don't include dist folder in your commit.
API:
/** * @typedef {{target: String, source: String, permissions: Array}} SimplePermissions */ /** * Create/append permissions in a storage * @param * @param * @param */ {} /** * Reduce/Remove permissions in a storage * @param * @param * @param */ {}
Examples:
//one to many var app = { var permissions = ; return permissions: permissions grant: _ revoke: _ ;}; app;console;//["Admin - Read,Write,Email,Users", "User - Write,Read"] app;console;//["Admin - Read,Write,Email,Users", "User - Read"]
//starting codevar Foo = name: 'Foo' storage: s = Foostorage; ///////////////////// grant example ///////////////////// //basic casevar str = 'whatever';;var entry = ;//s.length === 1;//entry.permissions[0] === str; //works with multiple targetsvar str = 'whatever';;var results = ;//s.length === 4;//_.each(results, function (result) {// result.permissions[0] === str;//}); //works with multiple permission rulesvar str1 = 'anything';var str2 = 'something else';;var result1 = ;var result2 = ;//s.length === 5;//result1.permissions[1] === str1;//result2.permissions[0] === str2; ////////////////////// revoke example ////////////////////// //basic case;//s.length === 4;//_(s).find({target: Foo.name, source: 'Bar'}) === undefined; //works with multiple permission rules;//s.length === 3//_(s).find({target: 'Bar', source: Foo.name}).permissions[0] === 'whatever';//_(s).find({target: 'Bar', source: 'Baz'}) === undefined; // works with multiple targets;//s.length === 0