@adminforth/crud-approve-plugin 1.0.8 → 1.0.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/custom/ListPageDiffView.vue +5 -1
- package/custom/ShowPageDiffView.vue +5 -1
- package/index.ts +55 -52
- package/package.json +1 -1
|
@@ -20,7 +20,11 @@ const diffFile = ref();
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
async function sendApproveRequest(approved) {
|
|
23
|
-
|
|
23
|
+
let code = '123456'
|
|
24
|
+
if (approved) {
|
|
25
|
+
code = await (window).adminforthTwoFaModal.get2FaConfirmationResult?.(undefined, "Approve Action Confirmation");
|
|
26
|
+
}
|
|
27
|
+
|
|
24
28
|
const data = await callAdminForthApi({
|
|
25
29
|
path: `/plugin/crud-approve/update-status`,
|
|
26
30
|
method: 'POST',
|
|
@@ -22,7 +22,11 @@ const newContent = JSON.stringify(props.record[props.meta.resourceColumns.dataCo
|
|
|
22
22
|
const diffFile = ref();
|
|
23
23
|
|
|
24
24
|
async function sendApproveRequest(approved) {
|
|
25
|
-
|
|
25
|
+
let code = '123456'
|
|
26
|
+
if (approved) {
|
|
27
|
+
code = await (window).adminforthTwoFaModal.get2FaConfirmationResult?.(undefined, "Approve Action Confirmation");
|
|
28
|
+
}
|
|
29
|
+
|
|
26
30
|
const data = await callAdminForthApi({
|
|
27
31
|
path: `/plugin/crud-approve/update-status`,
|
|
28
32
|
method: 'POST',
|
package/index.ts
CHANGED
|
@@ -341,7 +341,7 @@ export default class CRUDApprovePlugin extends AdminForthPlugin {
|
|
|
341
341
|
response.status = 400;
|
|
342
342
|
return { error: 'Diff record is not pending' };
|
|
343
343
|
}
|
|
344
|
-
|
|
344
|
+
let beforeSaveResp;
|
|
345
345
|
if (approved === true) {
|
|
346
346
|
const resource = this.adminforth.config.resources.find(
|
|
347
347
|
(res) => res.resourceId == diffRecord[this.options.resourceColumns.resourceIdColumnName]
|
|
@@ -356,67 +356,67 @@ export default class CRUDApprovePlugin extends AdminForthPlugin {
|
|
|
356
356
|
resource, diffRecord[this.options.resourceColumns.recordIdColumnName]
|
|
357
357
|
);
|
|
358
358
|
}
|
|
359
|
-
|
|
359
|
+
beforeSaveResp = await this.callBeforeSaveHooks(
|
|
360
360
|
resource, action as AllowedActionsEnum, diffData['newRecord'],
|
|
361
361
|
adminUser, diffRecord[this.options.resourceColumns.recordIdColumnName],
|
|
362
362
|
diffData['newRecord'], oldRecord, this.adminforth, extra
|
|
363
363
|
);
|
|
364
|
-
if (beforeSaveResp.error) {
|
|
365
|
-
if (beforeSaveResp.error === 'Operation aborted by hook') {
|
|
366
|
-
return beforeSaveResp;
|
|
367
|
-
}
|
|
364
|
+
if (beforeSaveResp.error !== 'Operation aborted by hook') {
|
|
368
365
|
response.status = 500;
|
|
369
366
|
return { error: `Failed to apply approved changes: ${beforeSaveResp.error}` };
|
|
370
367
|
}
|
|
371
368
|
|
|
372
|
-
let recordUpdateResult;
|
|
373
|
-
const connector = this.adminforth.connectors[resource.dataSource];
|
|
374
|
-
if (action === AllowedActionsEnum.create) {
|
|
375
|
-
recordUpdateResult = await this.createRecord(resource, diffData, adminUser);
|
|
376
|
-
} else if (action === AllowedActionsEnum.edit) {
|
|
377
|
-
recordUpdateResult = await this.editRecord(
|
|
378
|
-
resource, diffData, diffRecord[this.options.resourceColumns.recordIdColumnName], connector
|
|
379
|
-
);
|
|
380
|
-
} else if (action === AllowedActionsEnum.delete) {
|
|
381
|
-
recordUpdateResult = await this.deleteRecord(
|
|
382
|
-
resource, diffRecord[this.options.resourceColumns.recordIdColumnName], connector
|
|
383
|
-
);
|
|
384
|
-
}
|
|
385
|
-
if (recordUpdateResult?.error) {
|
|
386
|
-
response.status = 500;
|
|
387
|
-
console.error('Error applying approved changes:', recordUpdateResult);
|
|
388
|
-
return { error: `Failed to apply approved changes: ${recordUpdateResult.error}` };
|
|
389
|
-
}
|
|
390
369
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
const
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
afterSaveResp = await this.callAfterSaveHooks(
|
|
411
|
-
resource, action as AllowedActionsEnum, newRecord, adminUser,
|
|
412
|
-
diffRecord[this.options.resourceColumns.recordIdColumnName],
|
|
413
|
-
{}, diffData['oldRecord'], this.adminforth, { body }
|
|
414
|
-
);
|
|
415
|
-
}
|
|
370
|
+
if (beforeSaveResp.error !== 'Operation aborted by hook') {
|
|
371
|
+
let recordUpdateResult;
|
|
372
|
+
const connector = this.adminforth.connectors[resource.dataSource];
|
|
373
|
+
if (action === AllowedActionsEnum.create) {
|
|
374
|
+
recordUpdateResult = await this.createRecord(resource, diffData, adminUser);
|
|
375
|
+
} else if (action === AllowedActionsEnum.edit) {
|
|
376
|
+
recordUpdateResult = await this.editRecord(
|
|
377
|
+
resource, diffData, diffRecord[this.options.resourceColumns.recordIdColumnName], connector
|
|
378
|
+
);
|
|
379
|
+
} else if (action === AllowedActionsEnum.delete) {
|
|
380
|
+
recordUpdateResult = await this.deleteRecord(
|
|
381
|
+
resource, diffRecord[this.options.resourceColumns.recordIdColumnName], connector
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
if (recordUpdateResult?.error) {
|
|
385
|
+
response.status = 500;
|
|
386
|
+
console.error('Error applying approved changes:', recordUpdateResult);
|
|
387
|
+
return { error: `Failed to apply approved changes: ${recordUpdateResult.error}` };
|
|
388
|
+
}
|
|
416
389
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
390
|
+
let afterSaveResp;
|
|
391
|
+
if (action === AllowedActionsEnum.create) {
|
|
392
|
+
const newRecord = recordUpdateResult.createdRecord;
|
|
393
|
+
afterSaveResp = await this.callAfterSaveHooks(
|
|
394
|
+
resource, action as AllowedActionsEnum, newRecord, adminUser,
|
|
395
|
+
diffRecord[this.options.resourceColumns.recordIdColumnName],
|
|
396
|
+
newRecord, {}, this.adminforth, { body }
|
|
397
|
+
);
|
|
398
|
+
} else if (action === AllowedActionsEnum.edit) {
|
|
399
|
+
const newRecord = diffData['newRecord'];
|
|
400
|
+
const oldRecord = await this.adminforth.connectors[resource.dataSource].getRecordByPrimaryKey(
|
|
401
|
+
resource, diffRecord[this.options.resourceColumns.recordIdColumnName]
|
|
402
|
+
);
|
|
403
|
+
afterSaveResp = await this.callAfterSaveHooks(
|
|
404
|
+
resource, action as AllowedActionsEnum, newRecord, adminUser,
|
|
405
|
+
recordId, newRecord, oldRecord, this.adminforth, { body }
|
|
406
|
+
);
|
|
407
|
+
} else if (action === AllowedActionsEnum.delete) {
|
|
408
|
+
const newRecord = diffData['newRecord'];
|
|
409
|
+
afterSaveResp = await this.callAfterSaveHooks(
|
|
410
|
+
resource, action as AllowedActionsEnum, newRecord, adminUser,
|
|
411
|
+
diffRecord[this.options.resourceColumns.recordIdColumnName],
|
|
412
|
+
{}, diffData['oldRecord'], this.adminforth, { body }
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
if (afterSaveResp?.error) {
|
|
417
|
+
response.status = 500;
|
|
418
|
+
return { error: `Failed to apply approved changes: ${afterSaveResp.error}` };
|
|
419
|
+
}
|
|
420
420
|
}
|
|
421
421
|
}
|
|
422
422
|
const r = await this.adminforth.updateResourceRecord({
|
|
@@ -436,6 +436,9 @@ export default class CRUDApprovePlugin extends AdminForthPlugin {
|
|
|
436
436
|
response.status = 500;
|
|
437
437
|
return { error: `Failed to update diff record status: ${r.error}` };
|
|
438
438
|
}
|
|
439
|
+
if (beforeSaveResp?.error === 'Operation aborted by hook') {
|
|
440
|
+
return beforeSaveResp;
|
|
441
|
+
}
|
|
439
442
|
return { ok: true };
|
|
440
443
|
}
|
|
441
444
|
})
|