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

expose rbac-a instance #5

Open
azhang opened this issue Mar 16, 2016 · 5 comments
Open

expose rbac-a instance #5

azhang opened this issue Mar 16, 2016 · 5 comments

Comments

@azhang
Copy link
Contributor

azhang commented Mar 16, 2016

It'd be nice to expose an rbac-a instance so that its config can be applied in one place to use both rbac-a and koa-rbac. Alternatively, exposing some methods similar to the .allow, .deny, .check in koa-rbac but return a Boolean so it can be used inline too.

for example, let's say I have a PostGroup, which includes PostA and PostB, all authorized by rbac. When I share a PostGroup, I want to automatically share a Post to that user as well, but only if I have the 'share:post' permission on that Post. Otherwise, just share the PostGroup and the Posts where I have that permission.

I'd use koa-rbac middleware to check for 'share:postgroup', but I'd need to use rbac .check (share:post) somewhere inside the handler as well. I'd prefer it use the same rbac-a instance to ensure the config is identical.

(hope that example makes sense, I realize it's a bit complicated)

@yanickrochon
Copy link
Owner

Sure, I think I understand your example. And this is already implemented, actually. This module already exposes rbac-a, so you can just define your instance and preserve a copy somewhere and re-use it whenever you need it.

const rbac = require('koa-rbac');

const permissions = new rbac.RBAC( /* rbac-a options here */ );

...

app.use(rbac.middleware({
  rbac: permissions,
  ...
});

app.use(function * (next) {
  let allowed = permissions.check(this.user, 'share:postgroup');

  ...
});

Note: I will release a next major version sometime to support the next koa@2. Will update the docs as well. It's on the todo list 😛

@bbqsrc
Copy link

bbqsrc commented Jun 22, 2016

@yanickrochon I may spend a little bit of time porting it to Koa v2 if you don't have time in the next couple of weeks, as I need to use it for a project I'm doing. :)

@yanickrochon
Copy link
Owner

Sure! I will be starting a new project with koa@2 in a few weeks, but I am still in the process of moving, so I don't have time at the moment. If you want, the changes should be trivial. Thanks!

@ValeriyDP
Copy link

Ping.
I just stay in stuck with the problem how to move that to koa 2. Is there some news?

Thanks.

@yanickrochon
Copy link
Owner

I will update RBAC-A (hopefully soon!) and will also update this module to close this issue. I know it has been a while, but this is not dead!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants