1.0.0 • Published 4 years ago

permission-util v1.0.0

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

###permission-util

factory()

A set of utilities for working with permissions data.

//Format Each public function provided by this utility operates on an object known as a permission set. This is a hash with one entry "_global" specifying the json of global permissions, as well as one entry for each type. Entries for each type consist of a hash with one entry "_global" specifying a hash of permissions that apply to all producers of that type, combined with one entry for each specified producer, which contains the permissions hash.

The hash of permissions or actions should have keys for each "verb" with values of whether to allow or deny that verb. For instance: {'read': true, 'update': false} Would indicate that the permission allowed reading but disallowed updating. In addition, actions excluded are false by default. The most specific permission takes precedence.

An example permission set is as follows:

    {
    	_global: {'read': true},
    	'type1': {
    		_global: {'read': true, 'activate': true},
    		'1': {'write': true, 'read': true}
    	}
    }

For a given consumer, a permission set such as this would indicate that they have global read permissions, and additionally can "activate" anything of type. Lastly, they are allowed to "write" to the object of id 1 of type type.

Kind: global function

factory~unionHashes()

Unions two permissions hashes.

Kind: inner method of factory

factory~inheritHashes()

Creates a hash representing the child hash after inheriting any permissions from the parent hash.

Kind: inner method of factory

factory~parseType(type) ⇒

Parse constraints used to query permissions.

Kind: inner method of factory
Returns: A hash with type and producer specified as needed.

ParamDescription
typeA string representing the type to query on, or a hash where the singular key is a type and its value is a model or id for the producer to query on. Pass null for any type.

factory~findTypes(permissionSet) ⇒ Array

Generates a set of types included in the permission set.

Kind: inner method of factory
Returns: Array - The array of permission types contained in the permission set.

ParamTypeDescription
permissionSetpermissionSetThe permission set to inspect.

factory~findActions(permissionSet, type)

Find the hash of actions for the given permission set and given type.

Kind: inner method of factory

ParamDescription
permissionSetA permission set, as provided by findPermissions.
typeA string representing the type to query on, or a hash where the singular key is a type and its value is a model or id for the producer to query on. Pass null for any type.

factory~hasAction(permissionSet, type, action) ⇒

Determine if the given permission set "allows" action on the given type.

Kind: inner method of factory
Returns: true if permissionSet allows all actions on type, otherwise false.

ParamDescription
permissionSetA permission set.
typeA string representing the type to query on, or a hash where the singular key is a type and its value is a model or id for the producer to query on. Pass null for global.
actionA string or array of strings representing the action(s) to look for.

factory~hasAnyAction(permissionSet, type, action) ⇒

Determine if the given permission set "allows" action on the given type.

Kind: inner method of factory
Returns: true if permissionSet allows any of the actions on type, otherwise false.

ParamDescription
permissionSetA permission set.
typeA string representing the type to query on, or a hash where the singular key is a type and its value is a model or id for the producer to query on. Pass null for global.
actionA string or array of strings representing the action(s) to look for.

factory~inherit()

Given a parent permission set and child permission set, generate a permission structure which maintains any permissions of the child while adding any permissions of the parent.

Kind: inner method of factory

factory~union()

Union all permission sets provided. This is an OR operation - if a single consumer has permission for something, the resultant set will indicate permission for something.

Kind: inner method of factory