adminforth 1.2.15 → 1.2.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/modules/restApi.js
CHANGED
|
@@ -618,11 +618,11 @@ export default class AdminForthRestAPI {
|
|
|
618
618
|
if (!action) {
|
|
619
619
|
return { error: `Action '${actionId}' not found` };
|
|
620
620
|
}
|
|
621
|
-
const execAllowed = yield action.allowed({ adminUser, resource, recordIds, allowedActions });
|
|
621
|
+
const execAllowed = yield action.allowed({ adminUser, resource, selectedIds: recordIds, allowedActions });
|
|
622
622
|
if (!execAllowed) {
|
|
623
623
|
return { error: `Action '${actionId}' is not allowed` };
|
|
624
624
|
}
|
|
625
|
-
yield action.action({ selectedIds: recordIds });
|
|
625
|
+
yield action.action({ selectedIds: recordIds, adminUser, resource });
|
|
626
626
|
return {
|
|
627
627
|
actionId,
|
|
628
628
|
recordIds,
|
package/modules/codeInjector.ts
CHANGED
|
@@ -8,11 +8,8 @@ import path from 'path';
|
|
|
8
8
|
import { promisify } from 'util';
|
|
9
9
|
import AdminForth from '../index.js';
|
|
10
10
|
import { ADMIN_FORTH_ABSOLUTE_PATH, getComponentNameFromPath, transformObject, deepMerge } from './utils.js';
|
|
11
|
-
import {
|
|
12
|
-
import { AdminForthComponentDeclaration, ICodeInjector } from '../types/AdminForthConfig.js';
|
|
11
|
+
import { ICodeInjector } from '../types/AdminForthConfig.js';
|
|
13
12
|
import { StylesGenerator } from './styleGenerator.js';
|
|
14
|
-
import { string } from 'zod';
|
|
15
|
-
|
|
16
13
|
|
|
17
14
|
|
|
18
15
|
let TMP_DIR;
|
package/modules/restApi.ts
CHANGED
|
@@ -708,11 +708,11 @@ export default class AdminForthRestAPI {
|
|
|
708
708
|
return { error: `Action '${actionId}' not found` };
|
|
709
709
|
}
|
|
710
710
|
|
|
711
|
-
const execAllowed = await action.allowed({ adminUser, resource, recordIds, allowedActions });
|
|
711
|
+
const execAllowed = await action.allowed({ adminUser, resource, selectedIds: recordIds, allowedActions });
|
|
712
712
|
if (!execAllowed) {
|
|
713
713
|
return { error: `Action '${actionId}' is not allowed` };
|
|
714
714
|
}
|
|
715
|
-
await action.action({selectedIds:recordIds})
|
|
715
|
+
await action.action({selectedIds: recordIds, adminUser, resource});
|
|
716
716
|
|
|
717
717
|
return {
|
|
718
718
|
actionId,
|
package/package.json
CHANGED
|
@@ -767,25 +767,42 @@ export type AdminForthResource = {
|
|
|
767
767
|
/**
|
|
768
768
|
* Custom bulk actions list
|
|
769
769
|
*/
|
|
770
|
-
bulkActions?:
|
|
770
|
+
bulkActions?: {
|
|
771
771
|
id?: string,
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* Label for action button which will be displayed in the list view
|
|
775
|
+
*/
|
|
772
776
|
label: string,
|
|
773
777
|
state: string,
|
|
778
|
+
|
|
779
|
+
/**
|
|
780
|
+
* Icon for action button which will be displayed in the list view
|
|
781
|
+
*/
|
|
774
782
|
icon?: string,
|
|
775
|
-
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* Callback which will be called on backend when user clicks on action button.
|
|
786
|
+
* It should return Promise which will be resolved when action is done.
|
|
787
|
+
*/
|
|
788
|
+
action: ({ resource, selectedIds, adminUser }: { resource: AdminForthResource, selectedIds: Array<any>, adminUser: AdminUser }) => Promise<void>,
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* Confirmation message which will be displayed to user before action is executed.
|
|
792
|
+
*/
|
|
776
793
|
confirm?: string,
|
|
777
794
|
|
|
778
795
|
/**
|
|
779
796
|
* Allowed callback called to check whether action is allowed for user.
|
|
780
797
|
* 1. It called first time when user goes to list view. If callback returns false, action button will be hidden on list view.
|
|
781
798
|
* 2. This same callback called second time when user clicks an action button. If callback returns false, action will not be executed.
|
|
782
|
-
* In second time
|
|
799
|
+
* In second time selectedIds will be passed to callback (because checkbox for items are selected), so you can use this to make additional
|
|
783
800
|
* checks ( for example to check if user has permission for certain records ).
|
|
784
801
|
*
|
|
785
802
|
* Example:
|
|
786
803
|
*
|
|
787
804
|
* ```ts
|
|
788
|
-
* allowed: async ({ resource, adminUser,
|
|
805
|
+
* allowed: async ({ resource, adminUser, selectedIds }) => {
|
|
789
806
|
* if (adminUser.isRoot || adminUser.dbUser.role !== 'superadmin') {
|
|
790
807
|
* return false;
|
|
791
808
|
* }
|
|
@@ -794,12 +811,12 @@ export type AdminForthResource = {
|
|
|
794
811
|
* ```
|
|
795
812
|
*
|
|
796
813
|
*/
|
|
797
|
-
allowed?: ({ resource, adminUser,
|
|
814
|
+
allowed?: ({ resource, adminUser, selectedIds, allowedActions }: {
|
|
798
815
|
|
|
799
816
|
/**
|
|
800
817
|
* recordIds will be passed only once user tries to perform bulk action by clicking on button
|
|
801
818
|
*/
|
|
802
|
-
|
|
819
|
+
selectedIds?: Array<any>,
|
|
803
820
|
resource: AdminForthResource,
|
|
804
821
|
|
|
805
822
|
/**
|
|
@@ -837,7 +854,7 @@ export type AdminForthResource = {
|
|
|
837
854
|
*/
|
|
838
855
|
allowedActions: AllowedActionsResolved,
|
|
839
856
|
}) => Promise<boolean>,
|
|
840
|
-
}
|
|
857
|
+
}[],
|
|
841
858
|
|
|
842
859
|
/**
|
|
843
860
|
* Allowed actions for resource.
|