Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

Own condition fn #2

Closed
psi-4ward opened this issue Jan 24, 2018 · 4 comments
Closed

Own condition fn #2

psi-4ward opened this issue Jan 24, 2018 · 4 comments

Comments

@psi-4ward
Copy link

Hey, your lib looks not bad but we need own condition functions

function checkOwner(context) {
  // ... own specifc logic
  return allowed;
}

ac.grant('user')
  .condition(checkOwner)
  .execute('update')
  .on('posts');

ac.can(user.roles)
  .context({user, post, org})
  .execute('update')
  .on('posts');

In a prefect world, the checkOwner function can be async to allow additional database lookups without the need to bind this logic on the context creation.

@koladilip
Copy link
Contributor

Thanks for your interest, we will look into it soon.

@koladilip
Copy link
Contributor

@psi-4ward sorry for the delay, I have added support for own condition function. Please pull from NPM v3.2.0
See the example: https://github.com/tensult/role-acl#conditions-examples

@koladilip
Copy link
Contributor

Promised based condition evaluation will not be supported at moment, I will look into it later.

@mxs42
Copy link

mxs42 commented Aug 4, 2018

Sorry for commenting closed issue but I also thought about this (async condition function) and came to the point that you don't really need it. Sure, more options are always nice but in my opinion all data that you need to make decision should be in context already. Load all data from database / do other async stuff on upper level, ACL shouldn't really do any IO.

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

No branches or pull requests

3 participants