@adminforth/inline-create 1.1.9 → 1.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +13 -1
- package/index.ts +16 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { AdminForthPlugin } from "adminforth";
|
|
10
|
+
import { ActionCheckSource, AdminForthPlugin, interpretResource } from "adminforth";
|
|
11
11
|
export default class InlineCreatePlugin extends AdminForthPlugin {
|
|
12
12
|
constructor(options) {
|
|
13
13
|
super(options, import.meta.url);
|
|
@@ -69,6 +69,18 @@ export default class InlineCreatePlugin extends AdminForthPlugin {
|
|
|
69
69
|
return { error: 'Resource ID mismatch' };
|
|
70
70
|
}
|
|
71
71
|
const resource = this.adminforth.config.resources.find(r => r.resourceId === resourceId);
|
|
72
|
+
const { allowedActions } = yield interpretResource(adminUser, resource, {}, ActionCheckSource.DisplayButtons, this.adminforth);
|
|
73
|
+
if (!allowedActions.create) {
|
|
74
|
+
return { error: 'User does not have permission to create records for this resource' };
|
|
75
|
+
}
|
|
76
|
+
for (const column of resource.columns) {
|
|
77
|
+
if (column.backendOnly) {
|
|
78
|
+
if (record[column.name] !== undefined) {
|
|
79
|
+
return { error: `Column "${column.name}" is backend-only and cannot be set by the user` };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
;
|
|
83
|
+
}
|
|
72
84
|
const cleanRecord = resource.columns.reduce((acc, field) => {
|
|
73
85
|
if (record[field.name] !== undefined && record[field.name] !== null) {
|
|
74
86
|
acc[field.name] = record[field.name];
|
package/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AdminForthPlugin } from "adminforth";
|
|
1
|
+
import { ActionCheckSource, AdminForthPlugin, interpretResource } from "adminforth";
|
|
2
2
|
import type { IAdminForth, IHttpServer, AdminForthResourcePages, AdminForthResourceColumn, AdminForthDataTypes, AdminForthResource } from "adminforth";
|
|
3
3
|
import type { PluginOptions } from './types.js';
|
|
4
4
|
|
|
@@ -72,8 +72,22 @@ export default class InlineCreatePlugin extends AdminForthPlugin {
|
|
|
72
72
|
if ( this.resourceConfig.resourceId !== resourceId) {
|
|
73
73
|
return { error: 'Resource ID mismatch' };
|
|
74
74
|
}
|
|
75
|
+
|
|
75
76
|
const resource = this.adminforth.config.resources.find(r => r.resourceId === resourceId);
|
|
76
|
-
|
|
77
|
+
|
|
78
|
+
const { allowedActions } = await interpretResource(adminUser, resource, {}, ActionCheckSource.DisplayButtons, this.adminforth);
|
|
79
|
+
if (!allowedActions.create) {
|
|
80
|
+
return { error: 'User does not have permission to create records for this resource' };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
for (const column of resource.columns) {
|
|
84
|
+
if (column.backendOnly) {
|
|
85
|
+
if (record[column.name] !== undefined) {
|
|
86
|
+
return { error: `Column "${column.name}" is backend-only and cannot be set by the user` };
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
77
91
|
const cleanRecord = resource.columns.reduce((acc, field) => {
|
|
78
92
|
if (record[field.name] !== undefined && record[field.name] !== null) {
|
|
79
93
|
acc[field.name] = record[field.name];
|