@@ -14,7 +14,7 @@ import {
1414 type FieldInfo ,
1515 type ModelMeta ,
1616} from '../../../cross' ;
17- import { isPlainObject , simpleTraverse , lowerCaseFirst , upperCaseFirst } from '../../../local-helpers' ;
17+ import { isPlainObject , lowerCaseFirst , simpleTraverse , upperCaseFirst } from '../../../local-helpers' ;
1818import {
1919 AuthUser ,
2020 CrudContract ,
@@ -469,7 +469,7 @@ export class PolicyUtil extends QueryUtils {
469469
470470 if ( operation === 'read' ) {
471471 // merge field-level read override guards
472- const fieldReadOverrideGuard = this . getFieldReadGuards ( db , model , args ) ;
472+ const fieldReadOverrideGuard = this . getCombinedFieldOverrideReadGuards ( db , model , args ) ;
473473 if ( fieldReadOverrideGuard ) {
474474 guard = this . or ( guard , fieldReadOverrideGuard ) ;
475475 }
@@ -610,10 +610,8 @@ export class PolicyUtil extends QueryUtils {
610610 }
611611
612612 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.
617615 const mergedGuard = this . buildReadGuardForFields ( db , model , args . where , { } ) ;
618616 args . where = this . mergeWhereClause ( args . where , mergedGuard ) ;
619617 }
@@ -692,12 +690,10 @@ export class PolicyUtil extends QueryUtils {
692690 const prefixConstraintVariables = ( constraint : unknown , prefix : string ) => {
693691 return simpleTraverse ( constraint , ( { value, update } ) => {
694692 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+ } ) ;
701697 }
702698 } ) ;
703699 } ;
@@ -961,7 +957,8 @@ export class PolicyUtil extends QueryUtils {
961957 return def . fieldLevel ?. update ?. [ field ] ?. overrideEntityChecker ;
962958 }
963959
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 } ) {
965962 const allFields = Object . values ( getFields ( this . modelMeta , model ) ) ;
966963
967964 // all scalar fields by default
0 commit comments