Skip to content

Commit d58b92d

Browse files
authored
Merge pull request #573 from devforth/feature/AdminForth/1433/please-normalize-allowed-e.g.-
fix: normalize allowed property in AdminForthActionFront interface an…
2 parents 8a91c38 + b0f988a commit d58b92d

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

adminforth/modules/restApi.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,17 +1079,15 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
10791079
})
10801080
);
10811081

1082-
const allowedCustomActions = [];
1082+
const allowedCustomActions: Array<(typeof resource.options.actions)[number] & { allowed: boolean }> = [];
10831083
if (resource.options.actions) {
10841084
await Promise.all(
10851085
resource.options.actions.map(async (action) => {
10861086
if (typeof action.allowed === 'function') {
10871087
const res = await action.allowed({ adminUser, standardAllowedActions: allowedActions });
1088-
if (res) {
1089-
allowedCustomActions.push(action);
1090-
}
1088+
allowedCustomActions.push({ ...action, allowed: !!res });
10911089
} else {
1092-
allowedCustomActions.push(action);
1090+
allowedCustomActions.push({ ...action, allowed: action.allowed !== false });
10931091
}
10941092
})
10951093
);
@@ -1207,7 +1205,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
12071205
confirm: action.confirm ? translated[`bulkActionConfirm${i}`] : action.confirm,
12081206
})
12091207
),
1210-
actions: allowedCustomActions.map(({ bulkHandler, allowed, action: actionFn, ...rest }) => ({
1208+
actions: allowedCustomActions.map(({ bulkHandler, action: actionFn, ...rest }) => ({
12111209
...rest,
12121210
...(bulkHandler && { bulkHandler: true }),
12131211
})) as AdminForthActionFront[],

adminforth/types/Common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ export type FieldGroup = {
317317
export interface AdminForthActionFront extends Omit<AdminForthActionInput, 'id' | 'bulkHandler' | 'action' | 'allowed'> {
318318
id: string;
319319
bulkHandler?: boolean;
320+
allowed: boolean;
320321
}
321322

322323
export interface AdminForthBulkActionFront extends Omit<AdminForthBulkActionCommon, 'id'> {

0 commit comments

Comments
 (0)