Unexpected ability checking behavior
See original GitHub issueDescribe the bug Result of ability checking not obviously depends on ability definition
To Reproduce Steps to reproduce the behavior:
- Ability configuration (rules, detectSubjectType, etc)
class Lot {
constructor(
public id: number,
public isPublished: boolean,
public userId: number,
) {}
}
class User {
constructor(public id: number) {}
}
enum Action {
Manage = 'manage',
Create = 'create',
Read = 'read',
Update = 'update',
Delete = 'delete',
}
type Subjects = typeof Lot | Lot | 'Lot';
export type LotAbility = Ability<[Action, Subjects]>;
export class LotAbilityFactory {
createForUser(user: User) {
const { can, build, rules } = new AbilityBuilder<LotAbility>(
Ability as AbilityClass<LotAbility>,
);
can(Action.Read, 'Lot');
can(Action.Update, Lot);
console.log('rules', rules);
return build();
}
}
- How do you check abilities
const user = new User(1);
const lot = new Lot(2, false, user.id);
const lotAbility = new LotAbilityFactory().createForUser(user);
lotAbility.can(Action.Update, lot); // false
Expected behavior
Obviously that lot
is a instance of Lot
and it’s should be matched with can(Action.Update, Lot)
and return true
Interactive example (optional, but highly desirable) My example and Rewritten example
CASL Version
“@casl/ability”: “5.2.1”,
Environment:
node -v
v15.5.1
ts-node -v
v9.1.1
“typescript”: “4.0.5”
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Teaching Expected and Unexpected Behaviors
One of the key components of talking about expected and unexpected behavior is encouraging students to consider how their behaviors make others ......
Read more >Expected And Unexpected Behaviors Teaching Resources | TPT
Expected and Unexpected Behavior ... This is a great tool to review behavioral expectations with students in primary grades. Use it before ...
Read more >Obsessive-Compulsive Disorder: When Unwanted Thoughts ...
People with OCD may feel the urge to check things repeatedly or perform routines for more than an hour each day as a...
Read more >OCD - 8 Simple Steps to Stop Compulsively Checking
Delay your compulsion to check. This is called gradual exposure. Allow yourself time to monitor your “What If” thoughts and to create a...
Read more >Obsessive-Compulsive Disorder (OCD) - HelpGuide.org
The sudden development of intense OCD symptoms can also be a sign of pediatric ... For example, if your compulsive behavior involves checking...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I found out it while was testing, but it’s unobviously. Anyway documentation is confusing and should be fixed asap.
PR to nestjs - https://github.com/nestjs/docs.nestjs.com/pull/1687