fng-audit 0.12.0-beta.220 → 0.12.0-beta.222
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/server/fng-audit.js +73 -70
- package/package.json +2 -2
package/dist/server/fng-audit.js
CHANGED
|
@@ -292,13 +292,15 @@ function auditAdHocEvent(user, description, details) {
|
|
|
292
292
|
copyDets = cloneDeep(details);
|
|
293
293
|
cleanKeys(copyDets); // Make sure mongoose doesn't barf on composite keys by putting quotes round them
|
|
294
294
|
auditRec = { user: user, op: description, dets: copyDets };
|
|
295
|
+
if (!(typeof auditOptions.addPropFunc === 'function')) return [3 /*break*/, 2];
|
|
295
296
|
return [4 /*yield*/, auditOptions.addPropFunc(auditRec, null, null, null, {})];
|
|
296
297
|
case 1:
|
|
297
298
|
xtra = _a.sent();
|
|
298
299
|
if (xtra) {
|
|
299
300
|
auditRec.xtra = xtra;
|
|
300
301
|
}
|
|
301
|
-
|
|
302
|
+
_a.label = 2;
|
|
303
|
+
case 2: return [2 /*return*/, exports.Audit.create(auditRec)];
|
|
302
304
|
}
|
|
303
305
|
});
|
|
304
306
|
});
|
|
@@ -361,9 +363,9 @@ function auditFromObject(doc, orig, updated, options, next) {
|
|
|
361
363
|
.sort("-ver")
|
|
362
364
|
.exec()
|
|
363
365
|
.then(function (prevAudit) { return __awaiter(_this, void 0, void 0, function () {
|
|
364
|
-
var auditRec, invariantAuditRec,
|
|
365
|
-
return __generator(this, function (
|
|
366
|
-
switch (
|
|
366
|
+
var auditRec, invariantAuditRec, xtra;
|
|
367
|
+
return __generator(this, function (_a) {
|
|
368
|
+
switch (_a.label) {
|
|
367
369
|
case 0:
|
|
368
370
|
auditRec = {
|
|
369
371
|
c: c_1,
|
|
@@ -377,13 +379,15 @@ function auditFromObject(doc, orig, updated, options, next) {
|
|
|
377
379
|
if (op_1) {
|
|
378
380
|
auditRec.op = op_1;
|
|
379
381
|
}
|
|
380
|
-
if (!auditOptions.addPropFunc) return [3 /*break*/, 2];
|
|
382
|
+
if (!(typeof auditOptions.addPropFunc === 'function')) return [3 /*break*/, 2];
|
|
381
383
|
invariantAuditRec = __assign({}, auditRec);
|
|
382
|
-
_a = auditRec;
|
|
383
384
|
return [4 /*yield*/, auditOptions.addPropFunc(invariantAuditRec, doc, orig, updated, options)];
|
|
384
385
|
case 1:
|
|
385
|
-
|
|
386
|
-
|
|
386
|
+
xtra = _a.sent();
|
|
387
|
+
if (xtra) {
|
|
388
|
+
auditRec.xtra = xtra;
|
|
389
|
+
}
|
|
390
|
+
_a.label = 2;
|
|
387
391
|
case 2:
|
|
388
392
|
exports.Audit.create(auditRec)
|
|
389
393
|
.then(function () {
|
|
@@ -530,71 +534,70 @@ function plugin(schema, options) {
|
|
|
530
534
|
Document middleware. "this" is the document
|
|
531
535
|
*/
|
|
532
536
|
schema.pre("save", function (next) {
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
537
|
+
function doTheCreate(theAuditRec) {
|
|
538
|
+
exports.Audit.create(theAuditRec)
|
|
539
|
+
.then(function () {
|
|
540
|
+
// nothing to do
|
|
541
|
+
})
|
|
542
|
+
.catch(function (err) {
|
|
543
|
+
console.log("Error creating audit object: ".concat(err.message));
|
|
544
|
+
})
|
|
545
|
+
.finally(function () {
|
|
546
|
+
next();
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
if (this._noAudit || !exports.Audit) {
|
|
550
|
+
next();
|
|
551
|
+
}
|
|
552
|
+
else if (this.isNew) {
|
|
553
|
+
// No point in auditing if we don't have a user, as the document itself does the job
|
|
554
|
+
var user = getPseudoField('user', this) || getPseudoField('_usr', this);
|
|
555
|
+
if (user) {
|
|
556
|
+
var auditRec_1 = {
|
|
557
|
+
c: this.constructor.modelName,
|
|
558
|
+
cId: this._id,
|
|
559
|
+
op: 'create',
|
|
560
|
+
user: user
|
|
561
|
+
};
|
|
562
|
+
if (typeof auditOptions.addPropFunc === "function") {
|
|
563
|
+
auditOptions.addPropFunc(auditRec_1, this, null, null, {})
|
|
564
|
+
.then(function (xtra) {
|
|
554
565
|
if (xtra) {
|
|
555
|
-
|
|
566
|
+
auditRec_1.xtra = xtra;
|
|
556
567
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
// nothing to do
|
|
560
|
-
})
|
|
561
|
-
.catch(function (err) {
|
|
562
|
-
console.log("Error creating audit object: ".concat(err.message));
|
|
563
|
-
})
|
|
564
|
-
.finally(function () {
|
|
565
|
-
next();
|
|
566
|
-
});
|
|
567
|
-
return [3 /*break*/, 4];
|
|
568
|
-
case 3:
|
|
569
|
-
next();
|
|
570
|
-
_a.label = 4;
|
|
571
|
-
case 4: return [3 /*break*/, 6];
|
|
572
|
-
case 5:
|
|
573
|
-
that_1 = this;
|
|
574
|
-
try {
|
|
575
|
-
getHiddenFields(that_1.constructor.collection.collectionName, options);
|
|
576
|
-
that_1.constructor.findOne({ _id: that_1._id })
|
|
577
|
-
.then(function (original) {
|
|
578
|
-
auditFromObject(that_1, original, that_1, options, next);
|
|
579
|
-
})
|
|
580
|
-
.catch(function (err) {
|
|
581
|
-
if (auditOptions.errorHandler) {
|
|
582
|
-
auditOptions.errorHandler(err.message);
|
|
583
|
-
}
|
|
584
|
-
next();
|
|
585
|
-
});
|
|
586
|
-
}
|
|
587
|
-
catch (e) {
|
|
588
|
-
if (auditOptions.errorHandler) {
|
|
589
|
-
auditOptions.errorHandler(e.message);
|
|
590
|
-
}
|
|
591
|
-
next();
|
|
592
|
-
}
|
|
593
|
-
_a.label = 6;
|
|
594
|
-
case 6: return [2 /*return*/];
|
|
568
|
+
doTheCreate(auditRec_1);
|
|
569
|
+
});
|
|
595
570
|
}
|
|
596
|
-
|
|
597
|
-
|
|
571
|
+
else {
|
|
572
|
+
doTheCreate(auditRec_1);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
else {
|
|
576
|
+
next();
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
else {
|
|
580
|
+
var that_1 = this;
|
|
581
|
+
try {
|
|
582
|
+
getHiddenFields(that_1.constructor.collection.collectionName, options);
|
|
583
|
+
that_1.constructor.findOne({ _id: that_1._id })
|
|
584
|
+
.then(function (original) {
|
|
585
|
+
auditFromObject(that_1, original, that_1, options, next);
|
|
586
|
+
})
|
|
587
|
+
.catch(function (err) {
|
|
588
|
+
if (auditOptions.errorHandler) {
|
|
589
|
+
auditOptions.errorHandler(err.message);
|
|
590
|
+
}
|
|
591
|
+
next();
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
catch (e) {
|
|
595
|
+
if (auditOptions.errorHandler) {
|
|
596
|
+
auditOptions.errorHandler(e.message);
|
|
597
|
+
}
|
|
598
|
+
next();
|
|
599
|
+
}
|
|
600
|
+
}
|
|
598
601
|
});
|
|
599
602
|
// prior to mongoose 7, pre("remove") was used to intercept deleted documents. in mongoose 7, remove() no longer
|
|
600
603
|
// exists, and instead, deleteOne() is used both to delete a document that has already been retrieved from the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fng-audit",
|
|
3
|
-
"version": "0.12.0-beta.
|
|
3
|
+
"version": "0.12.0-beta.222",
|
|
4
4
|
"description": "Client part of forms-angular audit plugin",
|
|
5
5
|
"homepage": "https://www.forms-angular.org/#/plugins",
|
|
6
6
|
"files": [
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@types/mocha": "10.0.1",
|
|
27
27
|
"angular": "^1.8.3",
|
|
28
28
|
"chai": "4.3.7",
|
|
29
|
-
"forms-angular": "0.12.0-beta.
|
|
29
|
+
"forms-angular": "0.12.0-beta.222",
|
|
30
30
|
"grunt": "^1.5.3",
|
|
31
31
|
"grunt-angular-templates": "^1.2.0",
|
|
32
32
|
"grunt-contrib-concat": "2.1.0",
|