acl-seq-be-pg
A Sequelize.js backend for node_acl
Last updated a year ago by afsolarte2 .
Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install acl-seq-be-pg 
SYNC missed versions from official npm registry.

ACL Sequelize

Build Status Coverage Status

node_acl implementation for Sequelize Currently working only with Postgres.

Installation

npm install sequelize
npm install pg
npm install acl
npm install acl-sequelize-backend

Setup

var NodeAcl = require('acl');
var Sequelize = require('Sequelize');
var SequelizeBackend = require('acl-sequelize-backend');
var db = new Sequelize('postgres://postgres:myawesomepw@127.0.0.1:5432/myawesomedb');

var aclOptions = {};
var tablePrefix = 'acl_';

var acl = new NodeAcl(new SequelizeBackend(db, tablePrefix, aclOptions));

API

new SequelizeBackend(db, prefix, options)

Arguments

  db        {Function} Sequelize db instance.
  prefix    {String} Prefix for generated tables
  options   {Object} Options provided to the backend

Options can contain these fields:

Note: These are also the defaults if nothing is provided.

var options = {
  meta: 'meta',               // Table name for meta bucket
  parents: 'parents',         // Table name for parents bucket
  permissions: 'permissions', // Table name for permissions bucket
  resources: 'resources',     // Table name for resources bucket
  roles: 'roles',             // Table name for roles bucket
  users: 'users',             // Table name for users bucket
  sync: true,                 // Should tables be automatically created using sequelize sync method
  debug: false                // Enable debug (shows sql on sync if enabled)
};

Migrations

If you want to use migrations to generate tables instead of automatic sync, You can pull them from SequelizeBackend like this:

First, make sure you disable automatic sync when initializing acl:

var acl = new NodeAcl(new SequelizeBackend(db, 'acl_', {
    sync: false
}));

Then generate migration file and add this to it:

// migrations/add_acl.js

var SequelizeBackend = require('acl-sequelize-backend');

module.exports = {
  up: function (queryInterface, Sequelize) {
    var options = { prefix: 'acl_' };
    return SequelizeBackend.migration.up(queryInterface, Sequelize, options);
  },

  down: function (queryInterface, Sequelize) {
    var options = { prefix: 'acl_' };
    return SequelizeBackend.migration.down(queryInterface, Sequelize, options);
  }
};

Both up and down methods accept 3rd parameter options which can contain table names for each bucket

var options = {
  prefix: '',                 // Prefix for table names
  meta: 'meta',               // Table name for meta bucket
  parents: 'parents',         // Table name for parents bucket
  permissions: 'permissions', // Table name for permissions bucket
  resources: 'resources',     // Table name for resources bucket
  roles: 'roles',             // Table name for roles bucket
  users: 'users'              // Table name for users bucket
};

NOTE: Make sure that table names and prefix provided here match with table names and prefix provided to the backend.

It is recommended to just use defaults in order to avoid any issues with naming.

Tests

npm test

Current Tags

  • 0.0.1                                ...           latest (a year ago)

1 Versions

  • 0.0.1                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (2)
Dev Dependencies (7)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |