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

Subject Hooks won't fire if there are no 'conditions' setup in the rule #923

Open
vineetmago opened this issue May 22, 2024 · 1 comment

Comments

@vineetmago
Copy link

vineetmago commented May 22, 2024

I was trying to setup a class based Subject Hook on a rule without conditions but wasn't able to get it working.

The bundled test case uses the following permission spec:
can(Actions.update, Post, { userId: user.id });

if the test case is setup us as the following spec instead, the PostHook wouldn't fire:
can(Actions.update, Post);

Please review the line access.service.ts #99

if (!relevantRules.every((rule) => rule.conditions) || !ability.subjectHook) {

Should it having an AND (&&) condition instead of an OR (||) ? This condition doesn't allow rules without conditions to specify a SubjectHook.

Thanks!

@neilzheng
Copy link

Same problem here. I think this line should be:
if (relevantRules.every((rule) => !rule.conditions) || !ability.subjectHook) {
The logic should be, if no rule has condition, then don't call hook. Now it is, if one rule has no condition, don't call hook.
With the current code, invert rule should not be working.

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