Possible future of cancan
See original GitHub issueI’d like to suggest possible future of cancan:
- make API a bit simpler (
ability.can('read', Post)
instead ofcan(user, 'read', Post)
) - improve performance of checks via special datastructure (this will prevent event loop blocking in case of big amount of rules)
- provide more sophisticated rule checks based on Mongo QL (can be added with help of sift.js)
- create a mongoose middleware which converts specified rules into Mongo Query and allows fetch records like
Post.accessibleBy(ability)
, whereability
is a configured instance ofAbility
class which in this library is just calledCanCan
- separate
RuleBuilder
andAbility
this will allow to build context dependent DSL
const { RuleBuilder, Ability } = require('cancan')
function defineRulesFor(user) {
const { can, cannot } = new RuleBuilder()
can(['read', 'update'], 'Post');
can('delete', 'Post', { createdBy: user.id });
cannot('update', 'Post', { readonly: true });
can('read', 'Comment');
can('delete', 'Comment', { createdAt: { $gt: Date.now() - 3600 * 1000 } })
return can.rules;
}
const ability = new Ability(defineRulesFor(currentUser))
ability.can('read', Post)
- more tests (also I’d like to use something like
mocha
orjest
for testing) - provide browser version of the library
- add better documentation (similar to what Ruby cancan has, provide examples for Express.js integration, for Angular2/Aurelia/Ionic2/React/Vue integration)
Some of these I did in past, so instead of creating one more cancan project suggest to merge some of my ideas into yours 😃 So, @vadimdemedes what do you think?
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Can You Do the Cancan?
The cancan was also known as the quadrille naturaliste, and would usually be danced by three women and one man. Sometimes there would...
Read more >A Brief History Of The Cancan, France's Famously ...
The cancan first appeared in Paris in the 1830s · The cancan was a commentary on the times · It really became commercial...
Read more >Cancan: The Forgotten History of France's Most Famous ...
The Cancan has not changed much in the hundred years since the 1920s. Outside from advancements in set and costume design, the dance...
Read more >French Icon: The Cancan
When His Royal Highness the Prince of Wales, the future Edward VII, came to Paris to see a cancan show in the 1890s...
Read more >CANCAN - Cachexia
Guided by the hypothesis that cachexia is a tumour-driven metabolic imbalance, the CANCAN team is exploring different pillars of basic research to ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found
Please check https://github.com/stalniy/casl in case if you are interested to see what I came up with
Thanks for putting all these suggestions too. Too bad that it’s not a good fit, in my opinion. Good luck with your project!