Skip to content

Commit

Permalink
replace deprecated instance of casl abilitybuilder with updated one
Browse files Browse the repository at this point in the history
  • Loading branch information
Junjiequan committed Jul 22, 2024
1 parent 2d0f724 commit 7b1bcc5
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/casl/casl-ability.factory.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {
Ability,
AbilityBuilder,
AbilityClass,
ExtractSubjectType,
InferSubjects,
MongoAbility,
MongoQuery,
createMongoAbility,
} from "@casl/ability";
import { Injectable } from "@nestjs/common";
import { Attachment } from "src/attachments/schemas/attachment.schema";
Expand Down Expand Up @@ -46,15 +47,17 @@ type Subjects =
| typeof ElasticSearchActions
>
| "all";
type PossibleAbilities = [Action, Subjects];
type Conditions = MongoQuery;

export type AppAbility = Ability<[Action, Subjects]>;
export type AppAbility = MongoAbility<PossibleAbilities, Conditions>;

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

// // admin groups
// const stringAdminGroups = process.env.ADMIN_GROUPS || "";
Expand Down

0 comments on commit 7b1bcc5

Please sign in to comment.