Skip to content

Commit ae5731c

Browse files
authored
Merge pull request #126 from devforth/fix-audit-log-record-create
fix: move field-level restrictions for create and edit operations to api call
2 parents 3dfec8a + 728743a commit ae5731c

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

adminforth/index.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -413,15 +413,6 @@ class AdminForth implements IAdminForth {
413413
return { error: err };
414414
}
415415

416-
for (const column of resource.columns) {
417-
const fieldName = column.name;
418-
if (fieldName in record) {
419-
if (!column.showIn?.create || column.backendOnly) {
420-
return { error: `Field "${fieldName}" cannot be modified as it is restricted from creation` };
421-
}
422-
}
423-
}
424-
425416
// execute hook if needed
426417
for (const hook of listify(resource.hooks?.create?.beforeSave)) {
427418
console.log('🪲 Hook beforeSave', hook);
@@ -498,15 +489,6 @@ class AdminForth implements IAdminForth {
498489
delete record[column.name];
499490
}
500491

501-
for (const column of resource.columns) {
502-
const fieldName = column.name;
503-
if (fieldName in record) {
504-
if (!column.showIn?.edit || column.editReadonly || column.backendOnly) {
505-
return { error: `Field "${fieldName}" cannot be modified as it is restricted from editing` };
506-
}
507-
}
508-
}
509-
510492
// execute hook if needed
511493
for (const hook of listify(resource.hooks?.edit?.beforeSave)) {
512494
const resp = await hook({

adminforth/modules/restApi.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,15 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
896896
}
897897
}
898898

899+
for (const column of resource.columns) {
900+
const fieldName = column.name;
901+
if (fieldName in record) {
902+
if (!column.showIn?.create || column.backendOnly) {
903+
return { error: `Field "${fieldName}" cannot be modified as it is restricted from creation`, ok: false };
904+
}
905+
}
906+
}
907+
899908
const response = await this.adminforth.createResourceRecord({ resource, record, adminUser, extra: { body, query, headers, cookies, requestUrl } });
900909
if (response.error) {
901910
return { error: response.error, ok: false };
@@ -939,6 +948,15 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
939948
return { error: allowedError };
940949
}
941950

951+
for (const column of resource.columns) {
952+
const fieldName = column.name;
953+
if (fieldName in record) {
954+
if (!column.showIn?.edit || column.editReadonly || column.backendOnly) {
955+
return { error: `Field "${fieldName}" cannot be modified as it is restricted from editing` };
956+
}
957+
}
958+
}
959+
942960
const { error } = await this.adminforth.updateResourceRecord({ resource, record, adminUser, oldRecord, recordId, extra: { body, query, headers, cookies, requestUrl} });
943961
if (error) {
944962
return { error };

0 commit comments

Comments
 (0)