@@ -29,11 +29,10 @@ export async function interpretResource(
29
29
meta : any ,
30
30
source : ActionCheckSource ,
31
31
adminforth : IAdminForth
32
- ) : Promise < { allowedActions : AllowedActionsResolved ; visibleColumns : Record < string , boolean > } > {
32
+ ) : Promise < { allowedActions : AllowedActionsResolved } > {
33
33
if ( process . env . HEAVY_DEBUG ) {
34
34
console . log ( '🪲Interpreting resource' , resource . resourceId , source , 'adminUser' , adminUser ) ;
35
35
}
36
-
37
36
const allowedActions = { } as AllowedActionsResolved ;
38
37
39
38
// we need to compute only allowed actions for this source:
@@ -62,6 +61,8 @@ export async function interpretResource(
62
61
allowedActions [ key ] = false ;
63
62
return ;
64
63
}
64
+
65
+ // if callable then call
65
66
if ( typeof value === 'function' ) {
66
67
allowedActions [ key ] = await value ( { adminUser, resource, meta, source, adminforth } ) ;
67
68
} else {
@@ -70,41 +71,7 @@ export async function interpretResource(
70
71
} )
71
72
) ;
72
73
73
- const resolveAllowed = async ( val : any ) : Promise < boolean > => {
74
- if ( typeof val === 'boolean' ) return val ;
75
- if ( typeof val === 'function' ) {
76
- const r = val ( { adminUser, resource, meta, source, adminforth } ) ;
77
- return r instanceof Promise ? await r : ! ! r ;
78
- }
79
- return true ;
80
- } ;
81
-
82
- const page : 'list' | 'show' | 'edit' = ( {
83
- [ ActionCheckSource . ListRequest ] : 'list' ,
84
- [ ActionCheckSource . ShowRequest ] : 'show' ,
85
- [ ActionCheckSource . EditLoadRequest ] : 'edit' ,
86
- } as const ) [ source ] ?? 'show' ;
87
-
88
- const isColumnVisible = async ( col : any ) : Promise < boolean > => {
89
- const si = col . showIn ;
90
- if ( ! si ) return true ;
91
-
92
- if ( Array . isArray ( si ) ) {
93
- return si . includes ( 'all' ) || si . includes ( page ) ;
94
- }
95
-
96
- if ( si [ page ] !== undefined ) return await resolveAllowed ( si [ page ] ) ;
97
- if ( si . all !== undefined ) return await resolveAllowed ( si . all ) ;
98
- return true ;
99
- } ;
100
-
101
- const visibleColumnsEntries = await Promise . all (
102
- resource . columns . map ( async ( col ) => [ col . name , await isColumnVisible ( col ) ] as const )
103
- ) ;
104
-
105
- const visibleColumns = Object . fromEntries ( visibleColumnsEntries ) as Record < string , boolean > ;
106
-
107
- return { allowedActions, visibleColumns } ;
74
+ return { allowedActions } ;
108
75
}
109
76
110
77
export default class AdminForthRestAPI implements IAdminForthRestAPI {
@@ -635,7 +602,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
635
602
meta . pk = body . filters . find ( ( f ) => f . field === resource . columns . find ( ( col ) => col . primaryKey ) . name ) ?. value ;
636
603
}
637
604
638
- const { allowedActions, visibleColumns } = await interpretResource (
605
+ const { allowedActions } = await interpretResource (
639
606
adminUser ,
640
607
resource ,
641
608
meta ,
@@ -838,12 +805,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
838
805
// remove all columns which are not defined in resources, or defined but backendOnly
839
806
data . data . forEach ( ( item ) => {
840
807
Object . keys ( item ) . forEach ( ( key ) => {
841
- const isPk = pkField && key === pkField ;
842
- const isUnknown = ! resource . columns . find ( ( col ) => col . name === key ) ;
843
- const isBackendOnly = resource . columns . find ( ( col ) => col . name === key && col . backendOnly ) ;
844
- const isHiddenByACL = visibleColumns ?. [ key ] === false ;
845
-
846
- if ( isUnknown || isBackendOnly || ( isHiddenByACL && ! isPk ) ) {
808
+ if ( ! resource . columns . find ( ( col ) => col . name === key ) || resource . columns . find ( ( col ) => col . name === key && col . backendOnly ) ) {
847
809
delete item [ key ] ;
848
810
}
849
811
} )
0 commit comments