Skip to content

Commit 27bb3bf

Browse files
committed
chore: expand injectForRead to include isList
1 parent 6879548 commit 27bb3bf

File tree

3 files changed

+5
-21
lines changed

3 files changed

+5
-21
lines changed

packages/runtime/src/enhancements/node/policy/handler.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,13 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
133133
private async doFind(args: any, actionName: FindOperations, handleRejection: () => any, isList: boolean = false) {
134134
const origArgs = args;
135135
const _args = this.policyUtils.safeClone(args);
136-
if (!this.policyUtils.injectForRead(this.prisma, this.model, _args)) {
136+
if (!this.policyUtils.injectForReadOrList(this.prisma, this.model, _args, isList)) {
137137
if (this.shouldLogQuery) {
138138
this.logger.info(`[policy] \`${actionName}\` ${this.model}: unconditionally denied`);
139139
}
140140
return handleRejection();
141141
}
142142

143-
if (isList && !this.policyUtils.injectForList(this.prisma, this.model, _args)) {
144-
if (this.shouldLogQuery) {
145-
this.logger.info(`[policy] \`${actionName}\` ${this.model}: unconditionally denied`);
146-
}
147-
148-
return handleRejection();
149-
}
150-
151143
this.policyUtils.injectReadCheckSelect(this.model, _args);
152144

153145
if (this.shouldLogQuery) {
@@ -1617,7 +1609,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
16171609
// "update" has an extra layer of "after"
16181610
const payload = key === 'update' ? args[key].after : args[key];
16191611
const toInject = { where: payload };
1620-
this.policyUtils.injectForRead(this.prisma, this.model, toInject);
1612+
this.policyUtils.injectForReadOrList(this.prisma, this.model, toInject, false);
16211613
if (key === 'update') {
16221614
// "update" has an extra layer of "after"
16231615
args[key].after = toInject.where;

packages/runtime/src/enhancements/node/policy/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ export async function policyProcessIncludeRelationPayload(
7575
context: EnhancementContext | undefined
7676
) {
7777
const utils = new PolicyUtil(prisma, options, context);
78-
await utils.injectForRead(prisma, model, payload);
78+
await utils.injectForReadOrList(prisma, model, payload, false);
7979
await utils.injectReadCheckSelect(model, payload);
8080
}

packages/runtime/src/enhancements/node/policy/policy-utils.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ export class PolicyUtil extends QueryUtils {
604604
/**
605605
* Injects auth guard for read operations.
606606
*/
607-
injectForRead(db: CrudContract, model: string, args: any) {
607+
injectForReadOrList(db: CrudContract, model: string, args: any, isList: boolean) {
608608
// make select and include visible to the injection
609609
const injected: any = { select: args.select, include: args.include };
610610
if (!this.injectAuthGuardAsWhere(db, injected, model, 'read')) {
@@ -652,14 +652,6 @@ export class PolicyUtil extends QueryUtils {
652652
return true;
653653
}
654654

655-
/**
656-
* Injects auth guard for read operations.
657-
*/
658-
injectForList(_db: CrudContract, _model: string, _args: any) {
659-
// make select and include visible to the injection
660-
return true;
661-
}
662-
663655
//#endregion
664656

665657
//#region Checker
@@ -1148,7 +1140,7 @@ export class PolicyUtil extends QueryUtils {
11481140
CrudFailureReason.RESULT_NOT_READABLE
11491141
);
11501142

1151-
const injectResult = this.injectForRead(db, model, readArgs);
1143+
const injectResult = this.injectForReadOrList(db, model, readArgs, false);
11521144
if (!injectResult) {
11531145
return { error, result: undefined };
11541146
}

0 commit comments

Comments
 (0)