3.4.0 • Published 8 years ago

@hanlindev/cancan v3.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 years ago

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.

Build Status Coverage Status

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

3.4.0

8 years ago

3.3.0

8 years ago

3.2.0

8 years ago

3.1.0

8 years ago