@hanlindev/cancan
v3.4.0
Published
Authorize with pleasure
Downloads
7
Readme
CanCan
My Changes
This is a fork of the original cancan package. The only change I made was to use the Sequelize.Model's Instance property to implement instanceOf function. This makes the ability config look-up work when using Sequelize.
CanCan provides a simple API for handling authorization of actions.
Permissions are defined for each class using a simple can
function.
Installation
$ npm install cancan --save
User Guide
Read the interactive user guide on Bucket
Quick Look
const cancan = require('cancan');
const can = cancan.can;
// example classes
class AdminUser {}
class User {}
class Product {}
// define permissions
cancan.configure(User, function (user) {
// this user can view
// all instances of Product
this.can('view', Product);
});
cancan.configure(AdminUser, function (user) {
// this user can:
// 1. view all products
// 2. create a new product
this.can('view', Product);
this.can('create', Product);
});
// check access
let product = new Product();
let adminUser = new AdminUser();
let user = new User();
can(adminUser, 'view', product); // true
can(adminUser, 'create', product); // true
can(user, 'view', product); // true
can(user, 'create', product); // false
Tests
$ npm test
License
MIT © Vadym Demedes