Socket
Book a DemoInstallSign in
Socket

simple-permissions

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-permissions

Trivial permissions implementation - takes an array and stores permissions from multiple targets for sources. 100% tested.

5.0.1
latest
Source
npmnpm
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Simple Permissions

Gitter
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 {SimplePermissions[]} storage
 * @param {String|Array} to
 * @param {Object} permissionsMap
 */
function grant(storage, to, permissionsMap) {}

/**
 * Reduce/Remove permissions in a storage
 * @param {SimplePermissions[]} storage
 * @param {String|Array} from
 * @param {Object} permissionsMap
 */
function revoke(storage, from, permissionsMap) {}

Examples:

//one to many

var app = (function () {
	var permissions = [];

	return {
		permissions: permissions,
		grant: _.partial(grant, permissions, 'App'),
		revoke: _.partial(revoke, permissions, 'App')
	};
})();

app.grant({Admin: ['Read', 'Write', 'Email', 'Users'], User: ['Write', 'Read']});
console.log(_.map(app.permissions, function (entry) {
	return entry.source + ' - ' + entry.permissions.join(',')
}));
//["Admin - Read,Write,Email,Users", "User - Write,Read"]

app.revoke({User: ['Write']});
console.log(_.map(app.permissions, function (entry) {
	return entry.source + ' - ' + entry.permissions.join(',')
}));
//["Admin - Read,Write,Email,Users", "User - Read"]
//starting code
var Foo = {
		name: 'Foo',
		storage: []
	},
	s = Foo.storage;

///////////////////
// grant example //
///////////////////

//basic case
var str = 'whatever';
grant(s, Foo.name, {Bar: [str]});
var entry = _(s).find({target: Foo.name, source: 'Bar'});
//s.length === 1;
//entry.permissions[0] === str;

//works with multiple targets
var str = 'whatever';
grant(s, ['Bar', 'Baz', 'Qux'], {Foo: [str]});
var results = [
	_(s).find({target: 'Bar', source: Foo.name}),
	_(s).find({target: 'Baz', source: Foo.name}),
	_(s).find({target: 'Qux', source: Foo.name})
];
//s.length === 4;
//_.each(results, function (result) {
//	result.permissions[0] === str;
//});

//works with multiple permission rules
var str1 = 'anything';
var str2 = 'something else';
grant(s, 'Bar', {Foo: [str1], Baz: [str2]});
var result1 = _(s).find({target: 'Bar', source: Foo.name});
var result2 = _(s).find({target: 'Bar', source: 'Baz'});
//s.length === 5;
//result1.permissions[1] === str1;
//result2.permissions[0] === str2;

////////////////////
// revoke example //
////////////////////

//basic case
revoke(s, 'Foo', {Bar: ['whatever']});
//s.length === 4;
//_(s).find({target: Foo.name, source: 'Bar'}) === undefined;

//works with multiple permission rules
revoke(s, 'Bar', {Foo: ['anything'], Baz: ['something else']});
//s.length === 3
//_(s).find({target: 'Bar', source: Foo.name}).permissions[0] === 'whatever';
//_(s).find({target: 'Bar', source: 'Baz'}) === undefined;


// works with multiple targets
revoke(s, ['Bar', 'Baz', 'Qux'], {Foo: ['whatever']});
//s.length === 0

Analytics

FAQs

Package last updated on 27 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.