-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]>; | ||
|
||
@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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This guide isn't mongo specific so why "createMongoAbility"? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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>, | ||
}); | ||
|
There was a problem hiding this comment.
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"?