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

docs(security): update deprecated method from @casl/ability #2597

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions content/security/authorization.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,16 @@ With this in place, we can define the `createForUser()` method on the `CaslAbili
```typescript
type Subjects = InferSubjects<typeof Article | typeof User> | 'all';

export type AppAbility = Ability<[Action, Subjects]>;
type AppAbility = MongoAbility<[Action, Subjects]>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This guide isn't mongo specific so why "MongoAbility"?


@Injectable()
export class CaslAbilityFactory {
createForUser(user: User) {
const { can, cannot, build } = new AbilityBuilder<
Ability<[Action, Subjects]>
>(Ability as AbilityClass<AppAbility>);
const { can, cannot, build } = new AbilityBuilder<AppAbility>(
createMongoAbility,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This guide isn't mongo specific so why "createMongoAbility"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see here: https://github.com/stalniy/casl/blob/master/packages/casl-ability/src/Ability.ts#L9,

If I am honest, the name "Ability" was much better, while "MongoAbility" which is very confusing.

);

if (user.isAdmin) {
if (user) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

can(Action.Manage, 'all'); // read-write access to everything
} else {
can(Action.Read, 'all'); // read-only access to everything
Expand All @@ -253,7 +253,7 @@ export class CaslAbilityFactory {
cannot(Action.Delete, Article, { isPublished: true });

return build({
// Read https://casl.js.org/v5/en/guide/subject-type-detection#use-classes-as-subject-types for details
// Read https://casl.js.org/v6/en/guide/subject-type-detection for details
detectSubjectType: (item) =>
item.constructor as ExtractSubjectType<Subjects>,
});
Expand Down