@7365admin1/core 3.48.1-staging.191 → 3.48.1-staging.192
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/.changeset/online-form-site-scope.md +15 -0
- package/dist/index.js +35 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +89 -61
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/e2e/harness.mjs +23 -0
- package/test/e2e/online-form-scope.e2e.test.mjs +547 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
"@7365admin1/core": patch
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Scope the online form routes to the estate
|
|
6
|
+
|
|
7
|
+
All six `/api/online-forms` routes carried `requireAuth` and nothing more, so any
|
|
8
|
+
signed-in account on the platform could read, rewrite, move or archive another
|
|
9
|
+
estate's form templates. The controller now takes its verdict from the session:
|
|
10
|
+
a new `requireOnlineFormReach` for the by-id read, update and delete, a site
|
|
11
|
+
check on the add and on the by-site list, both tenancy filters closed on the
|
|
12
|
+
list query, and the update's destination `site` checked as well as the source.
|
|
13
|
+
`createdBy`/`updatedBy` are stamped from the session instead of the caller's
|
|
14
|
+
`user` cookie, and `getOnlineFormsBySiteId` now actually applies the estate
|
|
15
|
+
filter it was given.
|
package/dist/index.js
CHANGED
|
@@ -73090,8 +73090,9 @@ function useOnlineFormRepo() {
|
|
|
73090
73090
|
query2.$or = [{ name: { $regex: search, $options: "i" } }];
|
|
73091
73091
|
cacheOptions.search = search;
|
|
73092
73092
|
}
|
|
73093
|
+
query2.site = site;
|
|
73093
73094
|
cacheOptions.site = site;
|
|
73094
|
-
const cacheKey = (0, import_node_server_utils227.makeCacheKey)(namespace_collection,
|
|
73095
|
+
const cacheKey = (0, import_node_server_utils227.makeCacheKey)(namespace_collection, cacheOptions);
|
|
73095
73096
|
const cachedData = await getCache(cacheKey);
|
|
73096
73097
|
if (cachedData) {
|
|
73097
73098
|
import_node_server_utils227.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
@@ -73147,12 +73148,16 @@ function useOnlineFormController() {
|
|
|
73147
73148
|
deleteOnlineFormById: _deleteOnlineFormById,
|
|
73148
73149
|
getOnlineFormsBySiteId: _getOnlineFormsBySiteId
|
|
73149
73150
|
} = useOnlineFormRepo();
|
|
73151
|
+
async function requireOnlineFormReach(req, id) {
|
|
73152
|
+
const form = await _getOnlineFormById(id);
|
|
73153
|
+
const { canReach } = await siteReachOf(req);
|
|
73154
|
+
if (!await canReach(form)) {
|
|
73155
|
+
throw new import_node_server_utils228.NotFoundError("Document not found.");
|
|
73156
|
+
}
|
|
73157
|
+
return form;
|
|
73158
|
+
}
|
|
73150
73159
|
async function add(req, res, next) {
|
|
73151
|
-
const
|
|
73152
|
-
(acc, [key, value]) => ({ ...acc, [key]: value }),
|
|
73153
|
-
{}
|
|
73154
|
-
);
|
|
73155
|
-
const createdBy = cookies?.["user"].toString() ?? "";
|
|
73160
|
+
const createdBy = callerId(req);
|
|
73156
73161
|
const payload = { ...req.body, createdBy };
|
|
73157
73162
|
const { error } = schemaOnlineForm.validate(payload, {
|
|
73158
73163
|
abortEarly: false
|
|
@@ -73164,6 +73169,7 @@ function useOnlineFormController() {
|
|
|
73164
73169
|
return;
|
|
73165
73170
|
}
|
|
73166
73171
|
try {
|
|
73172
|
+
await requireSiteReach(req, payload.site);
|
|
73167
73173
|
const data = await _add(payload);
|
|
73168
73174
|
res.status(201).json({ message: data });
|
|
73169
73175
|
return;
|
|
@@ -73197,6 +73203,15 @@ function useOnlineFormController() {
|
|
|
73197
73203
|
const org = req.query.org ?? "";
|
|
73198
73204
|
const site = req.query.site ?? "";
|
|
73199
73205
|
try {
|
|
73206
|
+
const { actor } = await siteReachOf(req);
|
|
73207
|
+
if (site) {
|
|
73208
|
+
await requireSiteReach(req, site);
|
|
73209
|
+
} else if (!actor.isSuperAdmin) {
|
|
73210
|
+
throw new import_node_server_utils228.UnauthorizedError("Not authorized.");
|
|
73211
|
+
}
|
|
73212
|
+
if (org && !actor.isSuperAdmin && !actor.orgIds.includes(org)) {
|
|
73213
|
+
throw new import_node_server_utils228.UnauthorizedError("Not authorized.");
|
|
73214
|
+
}
|
|
73200
73215
|
const data = await _getAll({ search, page, limit, status, org, site });
|
|
73201
73216
|
res.json(data);
|
|
73202
73217
|
return;
|
|
@@ -73216,7 +73231,7 @@ function useOnlineFormController() {
|
|
|
73216
73231
|
return;
|
|
73217
73232
|
}
|
|
73218
73233
|
try {
|
|
73219
|
-
const data = await
|
|
73234
|
+
const data = await requireOnlineFormReach(req, _id);
|
|
73220
73235
|
res.json(data);
|
|
73221
73236
|
return;
|
|
73222
73237
|
} catch (error2) {
|
|
@@ -73243,11 +73258,7 @@ function useOnlineFormController() {
|
|
|
73243
73258
|
site: import_joi118.default.string().hex().optional().allow("", null),
|
|
73244
73259
|
updatedBy: import_joi118.default.string().hex().optional().allow("", null)
|
|
73245
73260
|
});
|
|
73246
|
-
const
|
|
73247
|
-
(acc, [key, value]) => ({ ...acc, [key]: value }),
|
|
73248
|
-
{}
|
|
73249
|
-
);
|
|
73250
|
-
const updatedBy = cookies?.["user"].toString() ?? "";
|
|
73261
|
+
const updatedBy = callerId(req);
|
|
73251
73262
|
const _id = req.params.id;
|
|
73252
73263
|
const payload = { ...req.body, updatedBy };
|
|
73253
73264
|
const { error } = validation.validate({ _id, ...payload });
|
|
@@ -73257,6 +73268,16 @@ function useOnlineFormController() {
|
|
|
73257
73268
|
return;
|
|
73258
73269
|
}
|
|
73259
73270
|
try {
|
|
73271
|
+
await requireOnlineFormReach(req, _id);
|
|
73272
|
+
if (payload.site) {
|
|
73273
|
+
await requireSiteReach(req, payload.site);
|
|
73274
|
+
}
|
|
73275
|
+
if (payload.org) {
|
|
73276
|
+
const { actor } = await siteReachOf(req);
|
|
73277
|
+
if (!actor.isSuperAdmin && !actor.orgIds.includes(payload.org)) {
|
|
73278
|
+
throw new import_node_server_utils228.UnauthorizedError("Not authorized.");
|
|
73279
|
+
}
|
|
73280
|
+
}
|
|
73260
73281
|
await _updateOnlineFormById(_id, payload);
|
|
73261
73282
|
res.json({ message: "Successfully updated online form." });
|
|
73262
73283
|
return;
|
|
@@ -73276,6 +73297,7 @@ function useOnlineFormController() {
|
|
|
73276
73297
|
return;
|
|
73277
73298
|
}
|
|
73278
73299
|
try {
|
|
73300
|
+
await requireOnlineFormReach(req, _id);
|
|
73279
73301
|
await _deleteOnlineFormById(_id);
|
|
73280
73302
|
res.json({ message: "Successfully deleted online form." });
|
|
73281
73303
|
return;
|
|
@@ -73297,6 +73319,7 @@ function useOnlineFormController() {
|
|
|
73297
73319
|
return;
|
|
73298
73320
|
}
|
|
73299
73321
|
try {
|
|
73322
|
+
await requireSiteReach(req, _id);
|
|
73300
73323
|
const data = await _getOnlineFormsBySiteId(_id, { ...query2 });
|
|
73301
73324
|
res.json(data);
|
|
73302
73325
|
return;
|