@adminforth/crud-approve-plugin 1.0.0 → 1.0.2
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/index.ts +7 -6
- package/package.json +4 -3
package/index.ts
CHANGED
|
@@ -54,7 +54,10 @@ export default class CRUDApprovePlugin extends AdminForthPlugin {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
createApprovalRequest = async (
|
|
57
|
+
createApprovalRequest = async (
|
|
58
|
+
{resource, action, data, user, oldRecord, updates, extra, record}:
|
|
59
|
+
{resource: AdminForthResource, action: AllowedForReviewActionsEnum, data: Object, user: AdminUser, record?: Object, oldRecord?: Object, updates?: Object, extra?: HttpExtra}
|
|
60
|
+
) => {
|
|
58
61
|
if (extra && extra.adminforth_plugin_crud_approve && extra.adminforth_plugin_crud_approve.callingFromApprovalPlugin) {
|
|
59
62
|
return { ok: true, error: 'Approval request creation aborted to avoid infinite loop' };
|
|
60
63
|
}
|
|
@@ -66,7 +69,7 @@ export default class CRUDApprovePlugin extends AdminForthPlugin {
|
|
|
66
69
|
const connector = this.adminforth.connectors[resource.dataSource];
|
|
67
70
|
if (action === AllowedForReviewActionsEnum.create) {
|
|
68
71
|
oldRecord = {};
|
|
69
|
-
newRecord = updates;
|
|
72
|
+
newRecord = updates || record;
|
|
70
73
|
} else if (action === AllowedForReviewActionsEnum.edit) {
|
|
71
74
|
newRecord = await connector.getRecordByPrimaryKey(resource, recordId);
|
|
72
75
|
for (const key in updates) {
|
|
@@ -120,7 +123,7 @@ export default class CRUDApprovePlugin extends AdminForthPlugin {
|
|
|
120
123
|
}
|
|
121
124
|
|
|
122
125
|
const createdAt = dayjs.utc().format();
|
|
123
|
-
const
|
|
126
|
+
const diffRecord = {
|
|
124
127
|
[this.options.resourceColumns.idColumnName]: randomUUID(),
|
|
125
128
|
[this.options.resourceColumns.resourceIdColumnName]: resource.resourceId,
|
|
126
129
|
[this.options.resourceColumns.actionColumnName]: action,
|
|
@@ -132,7 +135,7 @@ export default class CRUDApprovePlugin extends AdminForthPlugin {
|
|
|
132
135
|
[this.options.resourceColumns.extraColumnName]: extra || {},
|
|
133
136
|
}
|
|
134
137
|
const diffResource = this.adminforth.config.resources.find((r) => r.resourceId === this.diffResource.resourceId);
|
|
135
|
-
await this.adminforth.createResourceRecord({ resource: diffResource, record, adminUser: user});
|
|
138
|
+
await this.adminforth.createResourceRecord({ resource: diffResource, record: diffRecord, adminUser: user});
|
|
136
139
|
return { ok: true, error: null };
|
|
137
140
|
}
|
|
138
141
|
|
|
@@ -162,8 +165,6 @@ export default class CRUDApprovePlugin extends AdminForthPlugin {
|
|
|
162
165
|
hooks = resource.hooks.delete.beforeSave;
|
|
163
166
|
}
|
|
164
167
|
|
|
165
|
-
// mark that call is from approval plugin to avoid infinite loops
|
|
166
|
-
console.log('extra before save hooks:', extra);
|
|
167
168
|
if (extra === undefined) {
|
|
168
169
|
extra = {};
|
|
169
170
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminforth/crud-approve-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"description": "Adds manual approval for
|
|
7
|
+
"description": "Adds manual approval for actions which mutates state (standard edit&create/custom actions/custom rest apis). Allows your superadmins to prevent admins from misuse",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"types": "dist/index.d.ts",
|
|
10
10
|
"type": "module",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"license": "ISC",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@adminforth/two-factors-auth": "^2.9.16",
|
|
24
|
-
"
|
|
24
|
+
"dayjs": "^1.11.11",
|
|
25
|
+
"adminforth": "^2.13.0-next.51"
|
|
25
26
|
},
|
|
26
27
|
"peerDependencies": {
|
|
27
28
|
"adminforth": "^2.13.0-next.51"
|