
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Dignity is a node js module that creates a layer based on user to check his/her roles and permissions
Quick use:
var dignity = require('dignity');
// sequelize
User.find(userId).then(function (result) {
var layer = new dignity.SequelizeLayer(result);
layer.analyzeDignity().then(function () {
layer.is('ironman'); // check if user has role ironman
layer.hasRole('destroyer'); // layer.is === layer.hasRole
layer.can('play-dota') // check if user can play dota
layer.hasPermission('play-dota') // layer.can === layer.hasPermission
});
});
// bookshelf
(new User({
id: 1
}))
.fetch()
.then(function (result) {
var layer = new dignity.BookshelfLayer(result);
layer.analyzeDignity().then(function () {
layer.is('ironman'); // check if user has role ironman
layer.hasRole('destroyer'); // layer.is === layer.hasRole
layer.can('play-dota') // check if user can play dota
layer.hasPermission('play-dota') // layer.can === layer.hasPermission
});
});
To use dignity
properly, you have to follow these conventions:
User
and Role
, the name of the relation in User must be roles
Role
and Permission
, the name of the relation in Role must be permissions
dignity
has a command line tool to make migration file (based on knex)
Steps:
npm install knex -g
knex init
and input your db config in knexfile.js
dignity create-migration
or dignity create-migration > ./migrations/dignity-migration.js
knex migrate:latest
:DgetUser()
get the user.setUser(user)
set user,it will automaticaly run analyzeDignity
, so u can use it like this layer.setUser(user).then(function () { /* do something */ })
.getPermissions()
returns an array of permissions.getRoles()
returns an array of roles.is(String|Array)
check role, example layer.is('ironman')
layer.is(['ironman', 'admin'])
. For array convention, it returns true satisfy if user has one of the given roles.can(String|Array)
check permission, example layer.can('playing')
layer.is(['playing', 'edit post'])
. For array. convention, it returns true satisfy if user has one of the given permissionYou must have sqlite3
installed in your system, npm test
For now dignity
leaves the creation of roles and permissions by yourself since it's responsibility is only to check the dignity
of the given user.
FAQs
A simple layer for creating and checking user roles/permissions
The npm package dignity receives a total of 0 weekly downloads. As such, dignity popularity was classified as not popular.
We found that dignity demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.