FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: refuse columns hidden from the create page and project the response by Romsik788 · Pull Request #3 · devforth/adminforth-inline-create · GitHub

Repository navigation

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

Filter by extension

Filter by extension .json  (1) .ts  (1) All 2 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
34 changes: 18 additions & 16 deletions index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActionCheckSource, AdminForthPlugin, interpretResource } from "adminforth";
import { ActionCheckSource, AdminForthPlugin, interpretResource, 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 @@ -96,12 +96,17 @@ export default class InlineCreatePlugin extends AdminForthPlugin {
return { error: 'User does not have permission to create records for this resource' };
}

for (const column of resource.columns) {
if (column.backendOnly) {
if (record[column.name] !== undefined) {
return { error: `Column "${column.name}" is backend-only and cannot be set by the user` };
}
};
const ctx = {
adminUser,
resource,
meta: { requestBody: body },
source: ActionCheckSource.CreateRequest,
adminforth: this.adminforth,
};

const writeError = await recordWriteError(record, 'create', ctx);
if (writeError) {
return { error: writeError };
}

const cleanRecord = resource.columns.reduce((acc, field) => {
Expand All @@ -121,15 +126,12 @@ export default class InlineCreatePlugin extends AdminForthPlugin {
return { error: result.error };
}

const createdRecord = result.createdRecord;

//filter createdRecord to only include columns that are not backendOnly
const safe = {};
for (const col of resource.columns) {
if (col.backendOnly) continue;
if (col.showIn?.list === false && col.showIn?.show === false) continue;
safe[col.name] = result.createdRecord[col.name];
}
const pkColumn = resource.columns.find((col) => col.primaryKey);
const safe = await stripBackendOnly(result.createdRecord, {
...ctx,
meta: { requestBody: body, pk: result.createdRecord[pkColumn.name] },
source: ActionCheckSource.ListRequest,
});
return { record: safe };
}
});
Expand Down
4 changes: 2 additions & 2 deletions package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
"license": "MIT",
"description": "Inline create plugin for adminforth",
"peerDependencies": {
"adminforth": "^3.8.2"
"adminforth": "^3.18.0"
},
"dependencies": {
"zod": "^4.3.6"
},
"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 Down

Back | FazBrowse Home | New Git URL