fng-audit 0.12.0-beta.364 → 0.12.0-beta.365
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 +77 -13
- package/package.json +2 -2
package/dist/server/fng-audit.js
CHANGED
|
@@ -96,22 +96,38 @@ export function controller(fng, processArgs, options) {
|
|
|
96
96
|
}
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
|
-
|
|
99
|
+
// The record's own findFunc decides who may see its history: without this check anyone who can call the API
|
|
100
|
+
// and knows a record's id could read the history (and, from /version/, the whole record) of one they cannot open
|
|
101
|
+
function guarded(handler) {
|
|
102
|
+
return function (req, res) {
|
|
103
|
+
var resource = fng.getResource(req.params.model);
|
|
104
|
+
if (!resource) {
|
|
105
|
+
return res.status(404).send("No such resource as ".concat(req.params.model));
|
|
106
|
+
}
|
|
107
|
+
recordVisible(fng, resource, req, req.params.id)
|
|
108
|
+
.then(function (visible) {
|
|
109
|
+
if (visible) {
|
|
110
|
+
handler(resource, req, res);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
res.status(404).send("No such record as ".concat(req.params.id, " in ").concat(req.params.model));
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
.catch(function (err) {
|
|
117
|
+
res.status(500).send(err.message);
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
fng.app.get.apply(fng.app, processArgs(fng.options, [':model/:id/history', guarded(function (resource, req, res) {
|
|
100
122
|
getAuditTrail(fng, req.params.model, req.params.id, {}, getCallback(res));
|
|
101
|
-
}]));
|
|
102
|
-
fng.app.get.apply(fng.app, processArgs(fng.options, [':model/:id/changes', function (req, res) {
|
|
123
|
+
})]));
|
|
124
|
+
fng.app.get.apply(fng.app, processArgs(fng.options, [':model/:id/changes', guarded(function (resource, req, res) {
|
|
103
125
|
getAuditTrail(fng, req.params.model, req.params.id, { chg: { $exists: true } }, getCallback(res));
|
|
104
|
-
}]));
|
|
126
|
+
})]));
|
|
105
127
|
// Maybe add fng.app.get('/:model/:id/snapshot/:date'...);
|
|
106
|
-
fng.app.get.apply(fng.app, processArgs(fng.options, [':model/:id/version/:version', function (req, res) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
getVersion(resource.model, req.params.id, req.params.version, true, "bail", getCallback(res));
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
res.status(404).send("No such resource as ".concat(req.params.model));
|
|
113
|
-
}
|
|
114
|
-
}]));
|
|
128
|
+
fng.app.get.apply(fng.app, processArgs(fng.options, [':model/:id/version/:version', guarded(function (resource, req, res) {
|
|
129
|
+
getVersion(resource.model, req.params.id, req.params.version, true, "bail", getCallback(res));
|
|
130
|
+
})]));
|
|
115
131
|
var retVal = {};
|
|
116
132
|
if (options.userRef) {
|
|
117
133
|
retVal.dependencyChecks = (_a = {},
|
|
@@ -127,6 +143,53 @@ export function controller(fng, processArgs, options) {
|
|
|
127
143
|
}
|
|
128
144
|
return retVal;
|
|
129
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Whether the user making the request may see the record's history, by the resource's findFunc (the same test the
|
|
148
|
+
* record's own GET route applies). A resource with no findFunc is open to everyone who gets past the plugin's
|
|
149
|
+
* authentication, as it is for the record itself. Otherwise the record must match the findFunc. A record that has
|
|
150
|
+
* been deleted can't be tested, so it falls back to the audit resource's own findFunc: the history is visible if the
|
|
151
|
+
* user could see one of the record's audit rows.
|
|
152
|
+
*/
|
|
153
|
+
export function recordVisible(fng, resource, req, id) {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
155
|
+
var findFuncQuery, auditResource, auditQuery;
|
|
156
|
+
var _a;
|
|
157
|
+
return __generator(this, function (_b) {
|
|
158
|
+
switch (_b.label) {
|
|
159
|
+
case 0:
|
|
160
|
+
if (!Mongoose.isValidObjectId(id)) {
|
|
161
|
+
return [2 /*return*/, false];
|
|
162
|
+
}
|
|
163
|
+
return [4 /*yield*/, fng.doFindFuncPromise(req, resource)];
|
|
164
|
+
case 1:
|
|
165
|
+
findFuncQuery = _b.sent();
|
|
166
|
+
if (!findFuncQuery) {
|
|
167
|
+
return [2 /*return*/, true];
|
|
168
|
+
}
|
|
169
|
+
return [4 /*yield*/, resource.model.exists({ $and: [{ _id: id }, findFuncQuery] })];
|
|
170
|
+
case 2:
|
|
171
|
+
if (_b.sent()) {
|
|
172
|
+
return [2 /*return*/, true];
|
|
173
|
+
}
|
|
174
|
+
return [4 /*yield*/, resource.model.exists({ _id: id })];
|
|
175
|
+
case 3:
|
|
176
|
+
if (_b.sent()) {
|
|
177
|
+
// it exists, and the user may not see it
|
|
178
|
+
return [2 /*return*/, false];
|
|
179
|
+
}
|
|
180
|
+
auditResource = fng.getResource('audit');
|
|
181
|
+
if (!((_a = auditResource === null || auditResource === void 0 ? void 0 : auditResource.options) === null || _a === void 0 ? void 0 : _a.findFunc)) {
|
|
182
|
+
return [2 /*return*/, false];
|
|
183
|
+
}
|
|
184
|
+
return [4 /*yield*/, fng.doFindFuncPromise(req, auditResource)];
|
|
185
|
+
case 4:
|
|
186
|
+
auditQuery = _b.sent();
|
|
187
|
+
return [4 /*yield*/, Audit.exists({ $and: [{ c: resource.model.modelName, cId: id }, auditQuery || {}] })];
|
|
188
|
+
case 5: return [2 /*return*/, !!(_b.sent())];
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
}
|
|
130
193
|
function extractPossiblyNestedPath(tree, obj) {
|
|
131
194
|
tree.forEach(function (branch) {
|
|
132
195
|
if (obj) {
|
|
@@ -927,6 +990,7 @@ export default {
|
|
|
927
990
|
controller: controller,
|
|
928
991
|
clean: clean,
|
|
929
992
|
getAuditTrail: getAuditTrail,
|
|
993
|
+
recordVisible: recordVisible,
|
|
930
994
|
getVersion: getVersion,
|
|
931
995
|
getSnapshot: getSnapshot,
|
|
932
996
|
auditAdHocEvent: auditAdHocEvent,
|
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.365",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Client part of forms-angular audit plugin",
|
|
6
6
|
"homepage": "https://www.forms-angular.org/#/plugins",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@types/mocha": "^10.0.7",
|
|
29
29
|
"angular": "npm:@brickhouse-tech/angular-lts@^1.10.4",
|
|
30
30
|
"chai": "=4.3.10",
|
|
31
|
-
"forms-angular": "0.12.0-beta.
|
|
31
|
+
"forms-angular": "0.12.0-beta.365",
|
|
32
32
|
"grunt": "^1.6.1",
|
|
33
33
|
"grunt-angular-templates": "^1.2.0",
|
|
34
34
|
"grunt-contrib-concat": "^2.1.0",
|