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

Pass custom data to assert function #5

Open
epaezrubio opened this issue Feb 25, 2019 · 1 comment
Open

Pass custom data to assert function #5

epaezrubio opened this issue Feb 25, 2019 · 1 comment

Comments

@epaezrubio
Copy link

It would be a nice touch if I was able to use a fourth argument in the assertion function to verify against single instances or other arbitrary custom data. Example, considering the current identity name to be Dezmond:

var ownPost = { 
    owner: "Dezmond"
}

var post = { 
    owner: "Foo"
}

AclService.allow('Manager', 'Post');
AclService.allow('User', 'Post', null, function (role, resource, privilege, data) {
    return role.name === data.owner;
});

AclService.can('Manager', 'Post', null, post) // true
AclService.can('User', 'Post', null, ownPost) // true
AclService.can('User', 'Post', null, post) // false
AclService.can('User', 'Post', null) // true

This would add way more flexibility to how one can use the can or isAllowed functions and, if I'm not wrong, it doesn't break any current interface.

I'd be happy to submit a PR implementing this feature.

Best.

@StyleT
Copy link
Owner

StyleT commented Feb 28, 2019

Hi!
I think you can pass an object as a first parameter and use data from it in the assertion.
The only thing that object should follow AclResourceInterface.

https://github.com/StyleT/js-acl/blob/master/src/index.js#L91

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

2 participants