@@ -52,7 +52,52 @@ export default class ForeignInlineListPlugin extends AdminForthPlugin {
5252 } ;
5353 }
5454 } ) ;
55+ server . endpoint ( {
56+ method : 'POST' ,
57+ path : `/plugin/${ this . pluginInstanceId } /start_bulk_action` ,
58+ handler : async ( { body, adminUser, tr } ) => {
59+ const { resourceId, actionId, recordIds } = body ;
60+ const resource = this . adminforth . config . resources . find ( ( res ) => res . resourceId == resourceId ) ;
61+ if ( ! resource ) {
62+ return { error : await tr ( `Resource {resourceId} not found` , 'errors' , { resourceId } ) } ;
63+ }
5564
65+ const resourceCopy = JSON . parse ( JSON . stringify ( { ...resource , plugins : undefined } ) ) ;
66+
67+ const { allowedActions } = await interpretResource (
68+ adminUser ,
69+ resource ,
70+ { requestBody : body } ,
71+ ActionCheckSource . BulkActionRequest ,
72+ this . adminforth
73+ ) ;
74+
75+ if ( this . options . modifyTableResourceConfig ) {
76+ this . options . modifyTableResourceConfig ( resourceCopy ) ;
77+ }
78+
79+ const action = resourceCopy . options . bulkActions . find ( ( act ) => act . id == actionId ) ;
80+ console . log ( 'action' , JSON . stringify ( resourceCopy . options . bulkActions , null , 2 ) ) ;
81+ if ( ! action ) {
82+ return { error : await tr ( `Action {actionId} not found` , 'errors' , { actionId } ) } ;
83+ }
84+
85+ if ( action . allowed ) {
86+ const execAllowed = await action . allowed ( { adminUser, resource, selectedIds : recordIds , allowedActions } ) ;
87+ if ( ! execAllowed ) {
88+ return { error : await tr ( `Action "{actionId}" not allowed` , 'errors' , { actionId : action . label } ) } ;
89+ }
90+ }
91+ const response = await action . action ( { selectedIds : recordIds , adminUser, resource, tr} ) ;
92+
93+ return {
94+ actionId,
95+ recordIds,
96+ resourceId,
97+ ...response
98+ }
99+ }
100+ } )
56101 }
57102
58103 async modifyResourceConfig ( adminforth : IAdminForth , resourceConfig : AdminForthResource ) {
0 commit comments