0.0
No commit activity in last 3 years
No release in over 3 years
Exports CanCan rules to the client-side.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 10.0

Runtime

 Project Readme

Cancan::Export

It is the rewrite of a vital parts of CanCan v.1.13.1 classes: Ability and Rule.
All method names writen in a snake case is rewrites of the CanCan ones.

This rewrite is simplified since we don't have ORM objects and real DB relations.
All we have on the client-side is plain old objects,
though as long as each object has _type' or type' property, it can be identified as an object of a specific model.

Usage

ability = new CanCanAbility(gon)
ability.can('read', 'CustomerOrder')
// => true or false
customerOrder = {partner_id: 123}
// or with restmod
customerOrder = CustomerOrder.$build({ partner_id: 123 })
ability.can('edit', customerOrder)
// => true, if a partner can edit only his orders and gon.user.partner_id == 123

With angular

// include CanCan service into the $rootScope,
  MyApp.run(['$rootScope', 'CanCan', function($rootScope, CanCan) {
    angular.extend($rootScope, CanCan);
    ...
  }])
// then, in templates you can authorize parts like
  can('edit', customerOrder)
// and check the permissions in a controller like
  $scope.can('edit', $scope.customerOrder)