@@ -3,13 +3,14 @@ import {
33 AdminForthResourceColumn ,
44 IAdminForthSort , IAdminForthSingleFilter , IAdminForthAndOrFilter ,
55 AdminForthConfig ,
6- IAggregationRule , IGroupByRule , IGroupByDateTrunc ,
6+ IAggregationRule , IGroupByRule , IGroupByDateTrunc
77} from "../types/Back.js" ;
88
9-
9+ import type { AdminUser } from "../types/Common.js"
1010
1111import { suggestIfTypo } from "../modules/utils.js" ;
12- import { AdminForthDataTypes , AdminForthFilterOperators , AdminForthSortDirections } from "../types/Common.js" ;
12+ import { interpretResource } from "../modules/restApi.js" ;
13+ import { ActionCheckSource , AdminForthDataTypes , AdminForthFilterOperators , AdminForthSortDirections , AllowedActionsEnum } from "../types/Common.js" ;
1314import { randomUUID } from "crypto" ;
1415import dayjs from "dayjs" ;
1516import { afLogger } from '../modules/logger.js' ;
@@ -24,11 +25,32 @@ type AdminForthFilterNormalizationResult = {
2425} ;
2526
2627async function publishShowPageUpdate ( resource : AdminForthResource , recordId : string , updates : Record < string , any > ) {
27- await global . adminforth . websocket . publish ( `/showPage/${ resource . resourceId } /${ String ( recordId ) } ` , {
28- resourceId : resource . resourceId ,
29- recordId,
30- updates,
31- } ) ;
28+ await global . adminforth . websocket . publish ( `/showPage/${ resource . resourceId } /${ String ( recordId ) } ` ,
29+ {
30+ resourceId : resource . resourceId ,
31+ recordId,
32+ updates,
33+ } ,
34+ async ( adminUser : AdminUser ) : Promise < boolean > => {
35+ if ( ! adminUser ) {
36+ // anonymous clients should never receive record updates
37+ return false ;
38+ }
39+ try {
40+ const { allowedActions } = await interpretResource (
41+ adminUser ,
42+ resource ,
43+ { requestBody : null , pk : recordId } ,
44+ ActionCheckSource . ShowRequest ,
45+ global . adminforth ,
46+ ) ;
47+ return allowedActions [ AllowedActionsEnum . show ] === true ;
48+ } catch ( e ) {
49+ afLogger . error ( `Error while checking show access for ${ resource . resourceId } record ${ recordId } , assuming update should not be sent: ${ e } ` ) ;
50+ return false ;
51+ }
52+ }
53+ ) ;
3254}
3355
3456
0 commit comments