Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 6 additions & 37 deletions index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<boolean> {
if (typeof val === 'function') {
return !!(await val(ctx));
}
return !!val;
}

async function isShownInEdit(column: AdminForthResource['columns'][number], ctx: AccessCheckContext): Promise<boolean> {
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;
Expand Down Expand Up @@ -888,7 +862,7 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
fields: Record<string, any>,
}): Promise<string | null> {
const meta = { requestBody, newRecord: fields, oldRecord, pk: recordId };
const ctx: AccessCheckContext = {
const ctx: ColumnAccessContext = {
adminUser,
resource: this.resourceConfig,
meta,
Expand Down Expand Up @@ -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;
}
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -40,7 +40,7 @@
"zod": "^4.3.6"
},
"peerDependencies": {
"adminforth": "^3.8.2"
"adminforth": "^3.18.0"
},
"release": {
"plugins": [
Expand Down