@@ -24,7 +24,7 @@ import { Logger } from '../logger';
24
24
import { createDeferredPromise , createFluentPromise } from '../promise' ;
25
25
import { PrismaProxyHandler } from '../proxy' ;
26
26
import { QueryUtils } from '../query-utils' ;
27
- import type { AdditionalCheckerFunc , CheckerConstraint } from '../types' ;
27
+ import type { EntityCheckerFunc , PermissionCheckerConstraint } from '../types' ;
28
28
import { clone , formatObject , isUnsafeMutate , prismaClientValidationError } from '../utils' ;
29
29
import { ConstraintSolver } from './constraint-solver' ;
30
30
import { PolicyUtil } from './policy-utils' ;
@@ -1182,15 +1182,15 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
1182
1182
1183
1183
args . data = this . validateUpdateInputSchema ( this . model , args . data ) ;
1184
1184
1185
- const additionalChecker = this . policyUtils . getAdditionalChecker ( this . model , 'update' ) ;
1185
+ const entityChecker = this . policyUtils . getEntityChecker ( this . model , 'update' ) ;
1186
1186
1187
1187
const canProceedWithoutTransaction =
1188
1188
// no post-update rules
1189
1189
! this . policyUtils . hasAuthGuard ( this . model , 'postUpdate' ) &&
1190
1190
// no Zod schema
1191
1191
! this . policyUtils . getZodSchema ( this . model ) &&
1192
- // no additional checker
1193
- ! additionalChecker ;
1192
+ // no entity checker
1193
+ ! entityChecker ;
1194
1194
1195
1195
if ( canProceedWithoutTransaction ) {
1196
1196
// proceed without a transaction
@@ -1212,9 +1212,9 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
1212
1212
}
1213
1213
1214
1214
// merge selection required for running additional checker
1215
- const additionalCheckerSelector = this . policyUtils . getAdditionalCheckerSelector ( this . model , 'update' ) ;
1216
- if ( additionalCheckerSelector ) {
1217
- select = deepmerge ( select , additionalCheckerSelector ) ;
1215
+ const entityChecker = this . policyUtils . getEntityChecker ( this . model , 'update' ) ;
1216
+ if ( entityChecker ?. selector ) {
1217
+ select = deepmerge ( select , entityChecker . selector ) ;
1218
1218
}
1219
1219
1220
1220
const currentSetQuery = { select, where : args . where } ;
@@ -1225,9 +1225,9 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
1225
1225
}
1226
1226
let candidates = await tx [ this . model ] . findMany ( currentSetQuery ) ;
1227
1227
1228
- if ( additionalChecker ) {
1228
+ if ( entityChecker ) {
1229
1229
// filter candidates with additional checker and build an id filter
1230
- const r = this . buildIdFilterWithAdditionalChecker ( candidates , additionalChecker ) ;
1230
+ const r = this . buildIdFilterWithEntityChecker ( candidates , entityChecker . func ) ;
1231
1231
candidates = r . filteredCandidates ;
1232
1232
1233
1233
// merge id filter into update's where clause
@@ -1383,19 +1383,15 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
1383
1383
args = clone ( args ) ;
1384
1384
this . policyUtils . injectAuthGuardAsWhere ( this . prisma , args , this . model , 'delete' ) ;
1385
1385
1386
- const additionalChecker = this . policyUtils . getAdditionalChecker ( this . model , 'delete' ) ;
1387
- if ( additionalChecker ) {
1386
+ const entityChecker = this . policyUtils . getEntityChecker ( this . model , 'delete' ) ;
1387
+ if ( entityChecker ) {
1388
1388
// additional checker exists, need to run deletion inside a transaction
1389
1389
return this . queryUtils . transaction ( this . prisma , async ( tx ) => {
1390
1390
// find the delete candidates, selecting id fields and fields needed for
1391
1391
// running the additional checker
1392
1392
let candidateSelect = this . policyUtils . makeIdSelection ( this . model ) ;
1393
- const additionalCheckerSelector = this . policyUtils . getAdditionalCheckerSelector (
1394
- this . model ,
1395
- 'delete'
1396
- ) ;
1397
- if ( additionalCheckerSelector ) {
1398
- candidateSelect = deepmerge ( candidateSelect , additionalCheckerSelector ) ;
1393
+ if ( entityChecker . selector ) {
1394
+ candidateSelect = deepmerge ( candidateSelect , entityChecker . selector ) ;
1399
1395
}
1400
1396
1401
1397
if ( this . shouldLogQuery ) {
@@ -1409,7 +1405,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
1409
1405
const candidates = await tx [ this . model ] . findMany ( { where : args . where , select : candidateSelect } ) ;
1410
1406
1411
1407
// build a ID filter based on id values filtered by the additional checker
1412
- const { idFilter } = this . buildIdFilterWithAdditionalChecker ( candidates , additionalChecker ) ;
1408
+ const { idFilter } = this . buildIdFilterWithEntityChecker ( candidates , entityChecker . func ) ;
1413
1409
1414
1410
// merge the ID filter into the where clause
1415
1411
args . where = args . where ? { AND : [ args . where , idFilter ] } : idFilter ;
@@ -1560,7 +1556,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
1560
1556
if ( args . where ) {
1561
1557
// combine runtime filters with generated constraints
1562
1558
1563
- const extraConstraints : CheckerConstraint [ ] = [ ] ;
1559
+ const extraConstraints : PermissionCheckerConstraint [ ] = [ ] ;
1564
1560
for ( const [ field , value ] of Object . entries ( args . where ) ) {
1565
1561
if ( value === undefined ) {
1566
1562
continue ;
@@ -1690,8 +1686,8 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
1690
1686
}
1691
1687
}
1692
1688
1693
- private buildIdFilterWithAdditionalChecker ( candidates : any [ ] , additionalChecker : AdditionalCheckerFunc ) {
1694
- const filteredCandidates = candidates . filter ( ( value ) => additionalChecker ( { user : this . context ?. user } , value ) ) ;
1689
+ private buildIdFilterWithEntityChecker ( candidates : any [ ] , entityChecker : EntityCheckerFunc ) {
1690
+ const filteredCandidates = candidates . filter ( ( value ) => entityChecker ( value , { user : this . context ?. user } ) ) ;
1695
1691
const idFields = this . policyUtils . getIdFields ( this . model ) ;
1696
1692
let idFilter : any ;
1697
1693
if ( idFields . length === 1 ) {
0 commit comments