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
21 changes: 13 additions & 8 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AdminForthPlugin, interpretResource, ActionCheckSource, AllowedActionsEnum } from "adminforth";
import { AdminForthPlugin, interpretResource, ActionCheckSource, AllowedActionsEnum, recordWriteError, stripBackendOnly } from "adminforth";
import type { IAdminForth, IHttpServer, AdminForthResourcePages, AdminForthResourceColumn, AdminForthDataTypes, AdminForthResource } from "adminforth";
import type { PluginOptions } from './types.js';
import { z } from "zod";
Expand Down Expand Up @@ -82,12 +82,6 @@ export default class ListInPlaceEditPlugin extends AdminForthPlugin {
if (column.primaryKey) {
return { error: 'Primary key field cannot be edited' };
}
if (column.backendOnly === true) {
return { error: 'Field is not editable, because it is marked as backendOnly' };
}
if (column.editReadonly === true) {
return { error: 'Field is not editable, because it is marked as editReadonly' };
}
// Create update object with just the single field
const updateRecord = { [field]: value };

Expand All @@ -98,12 +92,15 @@ export default class ListInPlaceEditPlugin extends AdminForthPlugin {
return { error: 'Record not found' };
}

const editMeta = { requestBody: body, newRecord: updateRecord, oldRecord, pk: recordId };
const editCtx = { adminUser, resource, meta: editMeta, source: ActionCheckSource.EditRequest, adminforth: this.adminforth };

// Enforce the resource's edit permission for this specific record
// (mirrors the core /update_record access check, since updateResourceRecord does not check ACL).
const { allowedActions } = await interpretResource(
adminUser,
resource,
{ requestBody: body, newRecord: updateRecord, oldRecord, pk: recordId },
editMeta,
ActionCheckSource.EditRequest,
this.adminforth
);
Expand All @@ -112,6 +109,11 @@ export default class ListInPlaceEditPlugin extends AdminForthPlugin {
return { error: typeof editAllowed === 'string' ? editAllowed : 'You do not have permission to edit this record' };
}

const writeError = await recordWriteError(updateRecord, 'edit', editCtx);
if (writeError) {
return { error: writeError };
}

const result = await this.adminforth.updateResourceRecord({
resource,
recordId,
Expand All @@ -125,6 +127,9 @@ export default class ListInPlaceEditPlugin extends AdminForthPlugin {
}

const updatedRecord = await connector.getRecordByPrimaryKey(resource, recordId as string);
if (updatedRecord) {
await stripBackendOnly(updatedRecord, { ...editCtx, meta: { requestBody: body, pk: recordId }, source: ActionCheckSource.EditLoadRequest });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Romsik788 I see that logic here changes from validation at start of update, to a setting bcakendOnly after hooks executed? But Why? Setting backendOnly field in hook is fine and always was core concept. Please test this plugin on inplace edit for password field for example - I feel liek it will not set password hash because this will totally strip it

@Romsik788 Romsik788 Sep 10, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main idea it's moving some checks to one side (adminforth core). Because it has a lot of the same code in different plugins and we need to maintain it (instead of maintaining one place).

I feel liek it will not set password hash because this will totally strip it

Please look 112 line.

devforth/adminforth#717

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/devforth/adminforth-list-in-place-edit/blob/main/index.ts#L85
Here's good example in this plugin. Now it has a bug with checking of backendOnly. Because backendOnly can be function.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Here is what I see

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
return { record: updatedRecord };
}
});
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"description": "AdminForth List In Place Edit Plugin",
"devDependencies": {
"@types/node": "^22.10.7",
"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 @@ -33,7 +33,7 @@
"zod": "^4.3.6"
},
"peerDependencies": {
"adminforth": "^3.8.2"
"adminforth": "^3.18.0"
},
"release": {
"plugins": [
Expand Down