Skip to content
Simple attribute whitelisting/blacklisting with roles for Sequelize
Branch: master
Clone or download
Latest commit 7121f78 Nov 9, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib sequelize 4 support (#12) Oct 17, 2017
test test for get with role and custom getters May 7, 2015
.gitignore initial work Mar 15, 2015
.jshintrc
.travis.yml sequelize 4 support (#12) Oct 17, 2017
LICENSE
README.md
package.json 1.0.0 Oct 17, 2017

README.md

ssacl: attribute roles

Build Status Test Coverage

Not maintained

Simple attribute whitelisting/blacklisting with roles for Sequelize

A part of ssacl but can be used standalone aswell

Install

npm install --save ssacl-attribute-roles

Usage

var ssaclAttributeRoles = require('ssacl-attribute-roles')
  , sequelize = new Sequelize()
  , User = sequelize.define('user', {});

ssaclAttributeRoles(sequelize);
ssaclAttributeRoles(User);

User = sequelize.define('user', {
  email: {
    type: Sequelize.STRING,
    roles: {
      admin: {get: true},
      self: true
    }
  },
  password: {
    type: Sequelize.STRING,
    roles: false
  },
  rank: {
    type: Sequelize.STRING,
    roles: {
      self: {set: false, get: true}
      admin: true
    }
  }
});

user.get(); // Will never include email or password
user.get({role: 'admin'}); // Will include email but not password
user.get({raw: true}); // Ignores roles, will include all

user.set({rank: 'UBER'}, {role: 'self'||undefined}); // Will be ignored
user.set({rank: 'UBER'}, {role: 'admin'}); // Will be set
You can’t perform that action at this time.