Skip to content

Commit feaee50

Browse files
committed
Fix bulkActions in foreignInlineList
1 parent 13cb448 commit feaee50

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

adminforth/plugins/foreign-inline-list/custom/InlineList.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ const filters = ref([]);
131131
const filtersShow = ref(false);
132132
const columnsMinMax = ref(null);
133133
134+
console.log('listResource', JSON.stringify(listResource.value, null, 2));
135+
134136
const listResourceRefColumn = computed(() => {
135137
if (!listResource.value) {
136138
return null;
@@ -182,7 +184,7 @@ watch([filters], async () => {
182184
183185
async function startBulkAction(actionId) {
184186
const data = await callAdminForthApi({
185-
path: '/start_bulk_action',
187+
path: `/plugin/${props.meta.pluginInstanceId}/start_bulk_action`,
186188
method: 'POST',
187189
body: {
188190
resourceId: listResource.value.resourceId,

adminforth/plugins/foreign-inline-list/index.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)