@@ -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 ,
@@ -837,8 +804,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
837
804
// remove all columns which are not defined in resources, or defined but backendOnly
838
805
data . data . forEach ( ( item ) => {
839
806
Object . keys ( item ) . forEach ( ( key ) => {
840
- console . log ( visibleColumns ?. [ key ] , key ) ;
841
- if ( ! resource . columns . find ( ( col ) => col . name === key ) || resource . columns . find ( ( col ) => col . name === key && col . backendOnly ) || visibleColumns ?. [ key ] === false ) {
807
+ if ( ! resource . columns . find ( ( col ) => col . name === key ) || resource . columns . find ( ( col ) => col . name === key && col . backendOnly ) ) {
842
808
delete item [ key ] ;
843
809
}
844
810
} )
0 commit comments