@@ -35,12 +35,13 @@ export default class ForeignInlineListPlugin extends AdminForthPlugin {
3535 }
3636 // exclude "plugins" key
3737 const resourceCopy = JSON . parse ( JSON . stringify ( { ...resource , plugins : undefined } ) ) ;
38- const { allowedActions } = await interpretResource ( adminUser , resource , { } , ActionCheckSource . DisplayButtons , this . adminforth ) ;
3938
40-
4139 if ( this . options . modifyTableResourceConfig ) {
4240 this . options . modifyTableResourceConfig ( resourceCopy ) ;
4341 }
42+
43+ const { allowedActions } = await interpretResource ( adminUser , resourceCopy , { } , ActionCheckSource . DisplayButtons , this . adminforth ) ;
44+
4445 return {
4546 resource : {
4647 ...resourceCopy ,
@@ -52,7 +53,52 @@ export default class ForeignInlineListPlugin extends AdminForthPlugin {
5253 } ;
5354 }
5455 } ) ;
56+ server . endpoint ( {
57+ method : 'POST' ,
58+ path : `/plugin/${ this . pluginInstanceId } /start_bulk_action` ,
59+ handler : async ( { body, adminUser, tr } ) => {
60+ const { resourceId, actionId, recordIds } = body ;
61+ const resource = this . adminforth . config . resources . find ( ( res ) => res . resourceId == resourceId ) ;
62+ if ( ! resource ) {
63+ return { error : await tr ( `Resource {resourceId} not found` , 'errors' , { resourceId } ) } ;
64+ }
65+
66+ const resourceCopy = JSON . parse ( JSON . stringify ( { ...resource , plugins : undefined } ) ) ;
5567
68+
69+ if ( this . options . modifyTableResourceConfig ) {
70+ this . options . modifyTableResourceConfig ( resourceCopy ) ;
71+ }
72+
73+ const { allowedActions } = await interpretResource (
74+ adminUser ,
75+ resourceCopy ,
76+ { requestBody : body } ,
77+ ActionCheckSource . BulkActionRequest ,
78+ this . adminforth
79+ ) ;
80+
81+ const action = resourceCopy . options . bulkActions . find ( ( act ) => act . id == actionId ) ;
82+ if ( ! action ) {
83+ return { error : await tr ( `Action {actionId} not found` , 'errors' , { actionId } ) } ;
84+ }
85+
86+ if ( action . allowed ) {
87+ const execAllowed = await action . allowed ( { adminUser, resourceCopy, selectedIds : recordIds , allowedActions } ) ;
88+ if ( ! execAllowed ) {
89+ return { error : await tr ( `Action "{actionId}" not allowed` , 'errors' , { actionId : action . label } ) } ;
90+ }
91+ }
92+ const response = await action . action ( { selectedIds : recordIds , adminUser, resourceCopy, tr} ) ;
93+
94+ return {
95+ actionId,
96+ recordIds,
97+ resourceId,
98+ ...response
99+ }
100+ }
101+ } )
56102 }
57103
58104 async modifyResourceConfig ( adminforth : IAdminForth , resourceConfig : AdminForthResource ) {
0 commit comments