From 441e9cbe1eb9d6b1c4efdac7b0f74a4ceefb21da Mon Sep 17 00:00:00 2001 From: Roman Malenko Date: Wed, 9 Sep 2026 18:14:00 +0300 Subject: [PATCH] fix: use core's column access helpers and require adminforth 3.18 --- index.ts | 43 ++++++------------------------------------- package.json | 4 ++-- 2 files changed, 8 insertions(+), 39 deletions(-) diff --git a/index.ts b/index.ts index db0764c..0bf7952 100644 --- a/index.ts +++ b/index.ts @@ -1,5 +1,5 @@ -import { AdminForthFilterOperators, AdminForthPlugin, Filters, interpretResource, ActionCheckSource, AllowedActionsEnum } from "adminforth"; -import type { IAdminForth, IHttpServer, AdminForthComponentDeclaration, AdminForthResource, AdminUser } from "adminforth"; +import { AdminForthFilterOperators, AdminForthPlugin, Filters, interpretResource, ActionCheckSource, AllowedActionsEnum, columnWriteError } from "adminforth"; +import type { IAdminForth, IHttpServer, AdminForthComponentDeclaration, AdminForthResource, AdminUser, ColumnAccessContext } from "adminforth"; import { suggestIfTypo, filtersTools } from "adminforth"; import type { PluginOptions } from './types.js'; import Handlebars from 'handlebars'; @@ -59,32 +59,6 @@ const getFilteredIdsBodySchema = z.object({ filters: z.any(), }).passthrough(); -type AccessCheckContext = { - adminUser: AdminUser; - resource: AdminForthResource; - meta: any; - source: ActionCheckSource; - adminforth: IAdminForth; -}; - -async function resolveBoolOrFn(val: any, ctx: AccessCheckContext): Promise { - if (typeof val === 'function') { - return !!(await val(ctx)); - } - return !!val; -} - -async function isShownInEdit(column: AdminForthResource['columns'][number], ctx: AccessCheckContext): Promise { - const showIn = (column.showIn as any) || {}; - if (showIn.edit !== undefined) { - return await resolveBoolOrFn(showIn.edit, ctx); - } - if (showIn.all !== undefined) { - return await resolveBoolOrFn(showIn.all, ctx); - } - return true; -} - function valueIsUnchanged(newValue: any, oldValue: any): boolean { if (newValue === oldValue) { return true; @@ -888,7 +862,7 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin { fields: Record, }): Promise { const meta = { requestBody, newRecord: fields, oldRecord, pk: recordId }; - const ctx: AccessCheckContext = { + const ctx: ColumnAccessContext = { adminUser, resource: this.resourceConfig, meta, @@ -924,14 +898,9 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin { if (column.primaryKey) { return `Field "${fieldName}" cannot be modified as it is a primary key`; } - if (await resolveBoolOrFn(column.backendOnly, ctx)) { - return `Field "${fieldName}" cannot be modified as it is restricted from editing (backendOnly is true).`; - } - if (column.editReadonly) { - return `Field "${fieldName}" cannot be modified as it is restricted from editing (editReadonly is true).`; - } - if (!(await isShownInEdit(column, ctx)) && !column.allowModifyWhenNotShowInEdit) { - return `Field "${fieldName}" cannot be modified as it is restricted from editing (showIn.edit is false). If you need to allow updating this hidden field, set column.allowModifyWhenNotShowInEdit = true.`; + const writeError = await columnWriteError(column, 'edit', ctx); + if (writeError) { + return writeError; } } diff --git a/package.json b/package.json index b2a302c..0c28738 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "description": "Bulk AI workflow plugin for AdminForth for batch field generation and image processing", "devDependencies": { "@types/node": "latest", - "adminforth": "^3.8.2", + "adminforth": "^3.18.0", "semantic-release": "^24.2.1", "semantic-release-slack-bot": "^4.0.2", "typescript": "^5.7.3" @@ -40,7 +40,7 @@ "zod": "^4.3.6" }, "peerDependencies": { - "adminforth": "^3.8.2" + "adminforth": "^3.18.0" }, "release": { "plugins": [