@@ -319,7 +319,7 @@ export class PolicyUtil {
319319 /**
320320 * Checks if the given model has a policy guard for the given operation.
321321 */
322- hasAuthGuard ( model : string , operation : PolicyOperationKind ) : boolean {
322+ hasAuthGuard ( model : string , operation : PolicyOperationKind ) {
323323 const guard = this . policy . guard [ lowerCaseFirst ( model ) ] ;
324324 if ( ! guard ) {
325325 return false ;
@@ -328,6 +328,21 @@ export class PolicyUtil {
328328 return typeof provider !== 'boolean' || provider !== true ;
329329 }
330330
331+ /**
332+ * Checks if the given model has any field-level override policy guard for the given operation.
333+ */
334+ hasOverrideAuthGuard ( model : string , operation : PolicyOperationKind ) {
335+ const guard = this . requireGuard ( model ) ;
336+ switch ( operation ) {
337+ case 'read' :
338+ return Object . keys ( guard ) . some ( ( k ) => k . startsWith ( FIELD_LEVEL_OVERRIDE_READ_GUARD_PREFIX ) ) ;
339+ case 'update' :
340+ return Object . keys ( guard ) . some ( ( k ) => k . startsWith ( FIELD_LEVEL_OVERRIDE_UPDATE_GUARD_PREFIX ) ) ;
341+ default :
342+ return false ;
343+ }
344+ }
345+
331346 /**
332347 * Checks model creation policy based on static analysis to the input args.
333348 *
@@ -731,7 +746,7 @@ export class PolicyUtil {
731746 preValue ?: any
732747 ) {
733748 let guard = this . getAuthGuard ( db , model , operation , preValue ) ;
734- if ( this . isFalse ( guard ) ) {
749+ if ( this . isFalse ( guard ) && ! this . hasOverrideAuthGuard ( model , operation ) ) {
735750 throw this . deniedByPolicy (
736751 model ,
737752 operation ,
@@ -904,7 +919,7 @@ export class PolicyUtil {
904919 */
905920 tryReject ( db : Record < string , DbOperations > , model : string , operation : PolicyOperationKind ) {
906921 const guard = this . getAuthGuard ( db , model , operation ) ;
907- if ( this . isFalse ( guard ) ) {
922+ if ( this . isFalse ( guard ) && ! this . hasOverrideAuthGuard ( model , operation ) ) {
908923 throw this . deniedByPolicy ( model , operation , undefined , CrudFailureReason . ACCESS_POLICY_VIOLATION ) ;
909924 }
910925 }
0 commit comments