@@ -2095,7 +2095,7 @@ export class SecurityPlugin implements Plugin {
20952095 const readPermissionEvaluator = ( ) => this . permissionEvaluator ;
20962096 const readQl = ( ) => this . ql ;
20972097 const readTenancyPosture = ( ) => this . tenancyPosture ;
2098- const host : Pick < SecurityServiceHost , 'acceptedDefaultPermissionSets' | 'canExport' | 'canReadObject' | 'checkAuthoredRowWrite' | 'checkControlledByParentWrite' | 'declareEveryone' | 'delegatedAdminGate' | 'describePositionGrants' | 'explainAccessForCaller' | 'getEffectiveObjectPermissions' | 'getMetadataReadableFields' | 'getObjectSecurityMeta' | 'getQueryableFields' | 'getReadFilter' | 'getReadableFields' | 'getWritableFields' | 'logger' | 'ownershipFloorAlternates' | 'permissionEvaluator' | 'ql' | 'resolvePermissionSetsForContext' | 'tenancyPosture' > = {
2098+ const host : Pick < SecurityServiceHost , 'acceptedDefaultPermissionSets' | 'canExport' | 'canReadObject' | 'checkAuthoredRowWrite' | 'checkControlledByParentWrite' | 'declareEveryone' | 'delegatedAdminGate' | 'describePositionGrants' | 'explainAccessForCaller' | 'getEffectiveObjectPermissions' | 'getMetadataReadableFields' | 'getObjectSecurityMeta' | 'getQueryableFields' | 'getReadFilter' | 'getReadableFields' | 'getRecordFieldAccess' | ' getWritableFields' | 'logger' | 'ownershipFloorAlternates' | 'permissionEvaluator' | 'ql' | 'resolvePermissionSetsForContext' | 'tenancyPosture' > = {
20992099 acceptedDefaultPermissionSets : this . acceptedDefaultPermissionSets ,
21002100 canExport : ( ...a ) => this . canExport ( ...a ) ,
21012101 canReadObject : ( ...a ) => this . canReadObject ( ...a ) ,
@@ -2111,6 +2111,7 @@ export class SecurityPlugin implements Plugin {
21112111 getQueryableFields : ( ...a ) => this . getQueryableFields ( ...a ) ,
21122112 getReadFilter : ( ...a ) => this . getReadFilter ( ...a ) ,
21132113 getReadableFields : ( ...a ) => this . getReadableFields ( ...a ) ,
2114+ getRecordFieldAccess : ( ...a ) => this . getRecordFieldAccess ( ...a ) ,
21142115 getWritableFields : ( ...a ) => this . getWritableFields ( ...a ) ,
21152116 get logger ( ) { return readLogger ( ) ; } ,
21162117 ownershipFloorAlternates : this . ownershipFloorAlternates ,
@@ -2969,6 +2970,62 @@ export class SecurityPlugin implements Plugin {
29692970 return mask . allFields . filter ( ( f ) => ! nonEditable . has ( f ) ) ;
29702971 }
29712972
2973+ /**
2974+ * [#26594 / ruling of record 6457467702] Query surface: the field projection
2975+ * of ONE record — which fields the caller may read on `object`, and which it
2976+ * may write on the stored row `recordId`. The record-scoped twin of
2977+ * {@link getReadableFields} and {@link getWritableFields}, for the one reader
2978+ * that holds a row: a record's edit form.
2979+ *
2980+ * One judge. `editable` is the step 2.5 write gate's own verdict
2981+ * ({@link computeForbiddenFieldWrites}) on an update by id of that row
2982+ * naming every field, over the same sets, posture and delegator
2983+ * intersection the gate takes ({@link resolveProjectionFieldMask}), with the
2984+ * row read as the CALLER reads it — the reader the gate's own pre-image is
2985+ * read by ({@link getCallerPreImage} → {@link readRowById}). So a
2986+ * row-conditioned entry (`FieldPermissionSchema.when`) locks a field only on
2987+ * the rows its condition names, and a field is in `editable` iff a by-id
2988+ * update of that row naming it passes step 2.5. No second evaluator of
2989+ * `when` exists for this answer to drift from.
2990+ *
2991+ * `readable` is {@link getReadableFields}' answer from the same mask: reads
2992+ * are judged row-blind.
2993+ *
2994+ * Never wider than the read path: `null` for a row that is absent or that the
2995+ * caller cannot read — the same no-row read, deliberately indistinguishable
2996+ * — and a read the middleware refuses outright (no read grant) rejects as it
2997+ * does there. `undefined` when the schema cannot be resolved, as on the
2998+ * object-wide projections. A system context reads every field.
2999+ */
3000+ async getRecordFieldAccess (
3001+ object : string ,
3002+ recordId : string ,
3003+ context ?: any ,
3004+ ) : Promise < { object : string ; recordId : string ; readable : string [ ] ; editable : string [ ] } | null | undefined > {
3005+ const objectName = String ( object ?? '' ) ;
3006+ const id = String ( recordId ?? '' ) ;
3007+ const mask = await this . resolveProjectionFieldMask ( objectName , context , { fallbackOnEmptySets : false } ) ;
3008+ if ( mask . kind === 'answer' && mask . fields === undefined ) return undefined ;
3009+ if ( ! id ) return null ;
3010+ const row = await this . readRowById ( objectName , id , context ) ;
3011+ if ( ! row ) return null ;
3012+ // The read half from the SAME mask, through the read projection's own body.
3013+ const readable = await computeReadableFields . call (
3014+ { resolveProjectionFieldMask : async ( ) => mask } ,
3015+ objectName , context , { fallbackOnEmptySets : false } ,
3016+ ) ;
3017+ if ( mask . kind === 'answer' ) {
3018+ return { object : objectName , recordId : id , readable : readable ?? [ ] , editable : mask . fields ?? [ ] } ;
3019+ }
3020+ const forbidden = new Set ( await mask . readRowForbiddenWrites ( row ) ) ;
3021+ return {
3022+ object : objectName ,
3023+ recordId : id ,
3024+ readable : readable ?? [ ] ,
3025+ editable : mask . allFields . filter ( ( f ) => ! forbidden . has ( f ) ) ,
3026+ } ;
3027+ }
3028+
29723029 /**
29733030 * [#20935] Query surface: the field names the caller may QUERY ON in
29743031 * `object` — filter, sort, group or aggregate by — the query-side twin of
@@ -3023,14 +3080,17 @@ export class SecurityPlugin implements Plugin {
30233080 readPartialMaskRules : ( ) => Record < string , FieldMaskingRule > ;
30243081 /** [#20935] The middleware's query-guard map for these sets (computeQueryGuardFieldPerms). */
30253082 readQueryGuardPerms : ( ) => Record < string , { readable : boolean ; editable : boolean } > ;
3083+ /** [#26594] The write gate's verdict on an update of `row` naming every field (computeForbiddenFieldWrites). */
3084+ readRowForbiddenWrites : ( row : Record < string , unknown > ) => Promise < string [ ] > ;
30263085 }
30273086 > {
30283087 // [#25223 cut 9] The body moved to `security-plugin-field-readers.ts` (see `FieldReadersHost`).
30293088 const readMetadata = ( ) => this . metadata ;
30303089 const readPermissionEvaluator = ( ) => this . permissionEvaluator ;
30313090 const readQl = ( ) => this . ql ;
30323091 const readTenancyPosture = ( ) => this . tenancyPosture ;
3033- const host : Pick < FieldReadersHost , 'computeQueryGuardFieldPerms' | 'computeReadPartialMaskRules' | 'foldFieldRequiredPermissions' | 'getObjectFieldNames' | 'metadata' | 'permissionEvaluator' | 'ql' | 'resolveCallerPosture' | 'resolveFallbackPermissionSets' | 'resolvePermissionSetsForContext' | 'tenancyPosture' > = {
3092+ const host : Pick < FieldReadersHost , 'computeForbiddenFieldWrites' | 'computeQueryGuardFieldPerms' | 'computeReadPartialMaskRules' | 'foldFieldRequiredPermissions' | 'getObjectFieldNames' | 'metadata' | 'permissionEvaluator' | 'ql' | 'resolveCallerPosture' | 'resolveFallbackPermissionSets' | 'resolvePermissionSetsForContext' | 'tenancyPosture' > = {
3093+ computeForbiddenFieldWrites : ( ...a ) => this . computeForbiddenFieldWrites ( ...a ) ,
30343094 computeQueryGuardFieldPerms : ( ...a ) => this . computeQueryGuardFieldPerms ( ...a ) ,
30353095 computeReadPartialMaskRules : ( ...a ) => this . computeReadPartialMaskRules ( ...a ) ,
30363096 foldFieldRequiredPermissions : ( ...a ) => this . foldFieldRequiredPermissions ( ...a ) ,
0 commit comments