@@ -14,7 +14,7 @@ import {
14
14
type FieldInfo ,
15
15
type ModelMeta ,
16
16
} from '../../../cross' ;
17
- import { isPlainObject , simpleTraverse , lowerCaseFirst , upperCaseFirst } from '../../../local-helpers' ;
17
+ import { isPlainObject , lowerCaseFirst , simpleTraverse , upperCaseFirst } from '../../../local-helpers' ;
18
18
import {
19
19
AuthUser ,
20
20
CrudContract ,
@@ -469,7 +469,7 @@ export class PolicyUtil extends QueryUtils {
469
469
470
470
if ( operation === 'read' ) {
471
471
// merge field-level read override guards
472
- const fieldReadOverrideGuard = this . getFieldReadGuards ( db , model , args ) ;
472
+ const fieldReadOverrideGuard = this . getCombinedFieldOverrideReadGuards ( db , model , args ) ;
473
473
if ( fieldReadOverrideGuard ) {
474
474
guard = this . or ( guard , fieldReadOverrideGuard ) ;
475
475
}
@@ -610,10 +610,8 @@ export class PolicyUtil extends QueryUtils {
610
610
}
611
611
612
612
if ( args . where ) {
613
- // inject into fields:
614
- // to-many: some/none/every
615
- // to-one: direct-conditions/is/isNot
616
- // regular fields
613
+ // visit fields accessed in where clause and merge field-level policies,
614
+ // fields are only allowed in where if they satisfy field-level read policies.
617
615
const mergedGuard = this . buildReadGuardForFields ( db , model , args . where , { } ) ;
618
616
args . where = this . mergeWhereClause ( args . where , mergedGuard ) ;
619
617
}
@@ -692,12 +690,10 @@ export class PolicyUtil extends QueryUtils {
692
690
const prefixConstraintVariables = ( constraint : unknown , prefix : string ) => {
693
691
return simpleTraverse ( constraint , ( { value, update } ) => {
694
692
if ( isVariableConstraint ( value ) ) {
695
- update (
696
- {
697
- ...value ,
698
- name : `${ prefix } ${ value . name } ` ,
699
- }
700
- ) ;
693
+ update ( {
694
+ ...value ,
695
+ name : `${ prefix } ${ value . name } ` ,
696
+ } ) ;
701
697
}
702
698
} ) ;
703
699
} ;
@@ -961,7 +957,8 @@ export class PolicyUtil extends QueryUtils {
961
957
return def . fieldLevel ?. update ?. [ field ] ?. overrideEntityChecker ;
962
958
}
963
959
964
- private getFieldReadGuards ( db : CrudContract , model : string , args : { select ?: any ; include ?: any } ) {
960
+ // visit fields referenced in select/include and return a combined field-level override read guard
961
+ private getCombinedFieldOverrideReadGuards ( db : CrudContract , model : string , args : { select ?: any ; include ?: any } ) {
965
962
const allFields = Object . values ( getFields ( this . modelMeta , model ) ) ;
966
963
967
964
// all scalar fields by default
0 commit comments