0.01
No release in over 3 years
Low commit activity in last 3 years
Implements CanCanCan's rule-based record fetching using neo4j gem.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.3
>= 0.11.3
>= 10.1
>= 3.2
>= 0.48.1

Runtime

 Project Readme

CanCanCan-ActiveGraph

This is the adapter for the CanCanCan authorization library to automatically generate Cypher queries from ability rules. It returns QueryProxy object for resources.

Adds support for neo4j >= 9.0 and cancancan <= 2.1.4

Ruby Versions Supported

Ruby >= 2.0.0

Usage

In your Gemfile, insert the following line:

gem 'cancancan-activegraph'

Given Article has has_one relation with Author. To give access to all articles which are authored by current users, we can use can rule like following,

can :read, Article, author: { id: user.id }

To define length of relationship, we can use rel_legth on realtionship conditions like bellow. Here all the one and two level deep friends of the user will be accessible.

can :read, User, friends: { rel_length: {min: 1, max: 2}, id: user.id }

To check existance or non existance of relationship, we can specify true or false on relationship like bellow. Here all the users who don't have friends will be returned.

can :read, User, friends: false

To use scope with a rule, you can do folowing.

can :read, User, User.where(active: true)

You can use simple rules like can :read, User with rule like above, but can not use rules with another scope and hash conditions. The order of rules also matter.

Check on specs for more usage.