-
Notifications
You must be signed in to change notification settings - Fork 22
Feature/admin forth/1433/please normalize allowed e.g. #568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6fa89c6
67b4d9b
c0d55a1
1d85ec4
65a2103
a3fe2ef
f8a2b47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,9 +23,9 @@ import { afLogger } from "./logger.js"; | |
| import { ADMINFORTH_VERSION, listify, md5hash, getLoginPromptHTML, hookResponseError } from './utils.js'; | ||
|
|
||
| import AdminForthAuth from "../auth.js"; | ||
| import { ActionCheckSource, AdminForthConfigMenuItem, AdminForthDataTypes, AdminForthFilterOperators, AdminForthResourceColumnInputCommon, AdminForthResourceFrontend, AdminForthResourcePages, | ||
| import { ActionCheckSource, AdminForthActionFront, AdminForthConfigMenuItem, AdminForthDataTypes, AdminForthFilterOperators, AdminForthResourceColumnInputCommon, AdminForthResourceFrontend, AdminForthResourcePages, | ||
| AdminForthSortDirections, | ||
| AdminUser, AllowedActionsEnum, AllowedActionsResolved, | ||
| AdminUser, AllowedActionsEnum, AllowedActionsResolved, | ||
| AnnouncementBadgeResponse, | ||
| GetBaseConfigResponse, | ||
| ShowInResolved} from "../types/Common.js"; | ||
|
|
@@ -1079,6 +1079,22 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI { | |
| }) | ||
| ); | ||
|
|
||
| const allowedCustomActions = []; | ||
| if (resource.options.actions) { | ||
| await Promise.all( | ||
| resource.options.actions.map(async (action) => { | ||
| if (typeof action.allowed === 'function') { | ||
| const res = await action.allowed({ adminUser, standardAllowedActions: allowedActions }); | ||
| if (res) { | ||
| allowedCustomActions.push(action); | ||
| } | ||
| } else { | ||
| allowedCustomActions.push(action); | ||
| } | ||
|
Comment on lines
+1086
to
+1093
|
||
| }) | ||
| ); | ||
|
Comment on lines
+1082
to
+1095
|
||
| } | ||
|
|
||
| // translate | ||
| const translateRoutines: Record<string, Promise<string>> = {}; | ||
| translateRoutines.resLabel = tr(resource.label, `resource.${resource.resourceId}`); | ||
|
|
@@ -1191,12 +1207,10 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI { | |
| confirm: action.confirm ? translated[`bulkActionConfirm${i}`] : action.confirm, | ||
| }) | ||
| ), | ||
| actions: resource.options.actions?.map((action) => ({ | ||
| ...action, | ||
| id: action.id!, | ||
| hasBulkHandler: !!action.bulkHandler, | ||
| bulkHandler: undefined, | ||
| })), | ||
| actions: allowedCustomActions.map(({ bulkHandler, allowed, action: actionFn, ...rest }) => ({ | ||
| ...rest, | ||
| ...(bulkHandler && { bulkHandler: true }), | ||
| })) as AdminForthActionFront[], | ||
| allowedActions, | ||
| } | ||
| } | ||
|
|
@@ -2096,7 +2110,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI { | |
| if (!action) { | ||
| return { error: await tr(`Action {actionId} not found`, 'errors', { actionId }) }; | ||
| } | ||
| if (action.allowed) { | ||
| if (typeof action.allowed === 'function') { | ||
| const execAllowed = await action.allowed({ adminUser, standardAllowedActions: allowedActions }); | ||
| if (!execAllowed) { | ||
| return { error: await tr(`Action "{actionId}" not allowed`, 'errors', { actionId: action.name }) }; | ||
|
|
@@ -2148,7 +2162,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI { | |
| if (!action.bulkHandler) { | ||
| return { error: await tr(`Action "{actionId}" has no bulkHandler`, 'errors', { actionId }) }; | ||
| } | ||
| if (action.allowed) { | ||
| if (typeof action.allowed === 'function') { | ||
| const execAllowed = await action.allowed({ adminUser, standardAllowedActions: allowedActions }); | ||
| if (!execAllowed) { | ||
| return { error: await tr(`Action "{actionId}" not allowed`, 'errors', { actionId: action.name }) }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allowedboolean normalization is only applied duringvalidateConfig(), but plugins can mutateresource.options.actionslater duringmodifyResourceConfig()(after validation). That means booleanallowedvalues introduced by plugins won't be normalized here; consider normalizing again after plugin activation (or ensure runtime checks handle booleanallowedconsistently).