@@ -319,7 +319,7 @@ export class PolicyUtil {
319
319
/**
320
320
* Checks if the given model has a policy guard for the given operation.
321
321
*/
322
- hasAuthGuard ( model : string , operation : PolicyOperationKind ) : boolean {
322
+ hasAuthGuard ( model : string , operation : PolicyOperationKind ) {
323
323
const guard = this . policy . guard [ lowerCaseFirst ( model ) ] ;
324
324
if ( ! guard ) {
325
325
return false ;
@@ -328,6 +328,21 @@ export class PolicyUtil {
328
328
return typeof provider !== 'boolean' || provider !== true ;
329
329
}
330
330
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
+
331
346
/**
332
347
* Checks model creation policy based on static analysis to the input args.
333
348
*
@@ -731,7 +746,7 @@ export class PolicyUtil {
731
746
preValue ?: any
732
747
) {
733
748
let guard = this . getAuthGuard ( db , model , operation , preValue ) ;
734
- if ( this . isFalse ( guard ) ) {
749
+ if ( this . isFalse ( guard ) && ! this . hasOverrideAuthGuard ( model , operation ) ) {
735
750
throw this . deniedByPolicy (
736
751
model ,
737
752
operation ,
@@ -904,7 +919,7 @@ export class PolicyUtil {
904
919
*/
905
920
tryReject ( db : Record < string , DbOperations > , model : string , operation : PolicyOperationKind ) {
906
921
const guard = this . getAuthGuard ( db , model , operation ) ;
907
- if ( this . isFalse ( guard ) ) {
922
+ if ( this . isFalse ( guard ) && ! this . hasOverrideAuthGuard ( model , operation ) ) {
908
923
throw this . deniedByPolicy ( model , operation , undefined , CrudFailureReason . ACCESS_POLICY_VIOLATION ) ;
909
924
}
910
925
}
0 commit comments