Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CanCan like Abilities #2

Open
sebastianhoitz opened this issue Aug 21, 2013 · 0 comments
Open

CanCan like Abilities #2

sebastianhoitz opened this issue Aug 21, 2013 · 0 comments

Comments

@sebastianhoitz
Copy link
Member

Salad should introduce Rails-like CanCan abilities: https://github.com/ryanb/cancan

This should have a separate class that defines what a user can do.
It can get a little hard because we have to do this asynchronous,
but something like this should be possible:

class Abilities
  @initialize: (user) ->

    # register an ability for the user on articles
    @can "article", (done) ->
      user.getForums().all (err, forums) ->
        forumIds = (forum.get("id") for forum in forums)
        conditions =
          forumId: forumIds
        # this registers additional conditions the scope has to contain to secure that the user can only edit "articles", that are in a forum the user has access to.
        done err, conditions

The controllers should be able to implement a cancan mixin, that hooks via @beforeAction filters into the flow of dispatching a request and can limit the scope that way.

Relevant pieces to instrument in the controller are:

  • @findResource
  • `@findParent``
  • @scoped
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants