Description
I'm submitting a...
- Regression
- Bug report
- Feature request
- [ X] Documentation issue or request (new chapter/page)
- Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
Warning message - "@deprecated use createMongoAbility function instead and MongoAbility interface. In the next major version PureAbility will be renamed to Ability and this class will be removed"
Expected behavior
Keep official documentation up to date!
Minimal reproduction of the problem with instructions
- Add package @casl/ability@^6.3.3
- Import the Ability class as the official documentation shows -
- Give the warning message - "@deprecated use createMongoAbility function instead and MongoAbility interface. In the next major version PureAbility will be renamed to Ability and this class will be removed"
What is the motivation / use case for changing the behavior?
Being able to keep the official documentation of this exceptional framework that is Nest.js up to date.
I used the same foundation and logic as the example, I just updated the obsolete methods, follow the example:
type Subjects = InferSubjects<typeof Article | typeof User> | 'all';
type AppAbility = MongoAbility<[Action, Subjects]>;
@Injectable()
export class CaslAbilityFactory {
createForUser(user: User) {
const { can, cannot, build } = new AbilityBuilder<AppAbility>(
createMongoAbility,
);
if (user) {
can(Action.Manage, 'all'); // read-write access to everything
} else {
can(Action.Read, 'all'); // read-only access to everything
}
can(Action.Update, Article, { authorId: user.id });
cannot(Action.Delete, Article, { isPublished: true });
return build({
// Read https://casl.js.org/v6/en/guide/subject-type-detection for details
detectSubjectType: (object) =>
object.constructor as ExtractSubjectType<Subjects>,
});
}
}
Changing only the code above and keeping the rest of the documentation, the authorization will already work, if it helps I can create a PR describing every detail of the authorization with CASL and Nest.js with updated methods :)
Att.
Raphael Martinez.