question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possible future of cancan

See original GitHub issue

I’d like to suggest possible future of cancan:

  • make API a bit simpler (ability.can('read', Post) instead of can(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), where ability is a configured instance of Ability class which in this library is just called CanCan
  • separate RuleBuilder and Ability 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 or jest 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:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
stalniycommented, Aug 3, 2017

Please check https://github.com/stalniy/casl in case if you are interested to see what I came up with

0reactions
vadimdemedescommented, Jul 10, 2017

Thanks for putting all these suggestions too. Too bad that it’s not a good fit, in my opinion. Good luck with your project!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found