Skip to content

Roles and Permissions plugin for the Sevr CMS Framework

License

Notifications You must be signed in to change notification settings

bpowers1215/sevr-perm

 
 

Repository files navigation

sevr-perm

Build Status


Add role-based permissions to Sevr collections at the query operation level.

Install

npm install --save sevr-perm

Usage

const perm = require('sevr-perm')

sevr.attach(ich-perm, config)

Configuration

The config object should have a single property, roles. Each property in the roles object represents a user role. A user role must define operation permissions for each collection:

{
	roles: {
		contributor: {
			posts: ['create', 'read'],
			authors: 'read'
		}
	}
}

The user role, contributor, has 'create' and 'read' permissions to the posts collection, but only had 'read' permissions on the authors collection.

When multiple permisions are defined for a collection, each permission should be an element in an array. When only a single permission is needed, a string will suffice.

Shorthand

Addionally, you can also the shorthand notation:

{
	roles: {
		contributor: {
			posts: ['c', 'r'], // 'create' and 'read' permissions
			authors: 'r', // 'read' permission
			tags: '*' // all permissions
		}
	}
}

'u' and 'd' can also be used for 'update' and 'delete', respectively.

Default permissions

A default set of permissions can also be defined for any collections that aren't explicitly defined using '_'.

{
	roles: {
		contributor: {
			posts: ['c', 'r'],
			'_': 'r' // all other collections will have read-only permissions
		}
	}
}

Default role

Like permissions, a default user role can also be defined using '_'.

{
	roles: {
		contributor: {
			posts: ['c', 'r']
		},

		// default user role will have read-only
		// access to all collections
		'_': {
			'_': 'r'
		}
	}
}

Tests

npm test

License

This project is licensed under the MIT license.

About

Roles and Permissions plugin for the Sevr CMS Framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%