Socket
Socket
Sign inDemoInstall

empower-role

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

empower-role

Given a role map, a set of roles and a permission can the user access?


Version published
Weekly downloads
9
increased by200%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status Coverage Status

empower-role

Given a role map, a set of roles and a permission can the user access?

Role Map

Maps a set of roles to a set of permission strings and CRUD actions against that set (expressed as HTTP/1.1 methods).

{
  "role-name": {
    "permission-name": [ "get" ],
    "other-permission": [ "post" ],
    "one-more-permission": [ "get", "put", "post", "delete" ]
  },
  "other-role": {
    "permission-name": [ "get", "post"],
    "other-permission": [ "delete" ],
    "permission:action": [ "get" ]
  }
}

Set of user roles

Simply an array of roles to check against.

Permission

A string that represents a system action or request.

Usage

var RoleMap = require('empower-role').Map;
var Role    = require('empower-role').Role;

// Alternatively you can supply JSON via the RoleMap.fromJson function.
var map     = RoleMap()
  .addRole( Role('role-name')
    .addPermission('permission-name'), [ 'get' ])
    .addPermission('other-permission'), [ 'get', 'post' ])
    .addPermission('permission:action', [ 'get', 'put', 'post', 'delete' ])
  )
  .addRole( Role('other-role')
    .addPermission('permission-name'), [ 'get', 'post' ])
    .addPermission('other-permission'), [ 'delete' ])
    .addPermission('permission:action', [ 'get' ])
  )
;

var userRoles = [ 'role-name', 'other-role' ];

var isAllowed1 = map.check(userRoles, 'permission-name', 'get');
var isAllowed2 = map.check(userRoles, 'other-permission', [ 'delete' ]);
var isAllowed3 = map.check(userRoles, 'permission:action!', [ 'put' ]);

// will print "true, true, true"
// the most permissive result is always returned.
console.log(isAllowed1, isAllowed2, isAllowed3);

Keywords

FAQs

Package last updated on 18 Nov 2015

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc