@7365admin1/core 3.48.1-staging.197 → 3.48.1-staging.198
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/patrol-email-site-scope.md +5 -0
- package/dist/index.js +13 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/e2e/harness.mjs +15 -0
- package/test/e2e/patrol-email-scope.e2e.test.mjs +310 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
---
|
|
2
|
+
"@7365admin1/core": patch
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Scope the patrol log email route to its estate. `POST /api/patrol-logs/email` carried `requireAuth` and nothing more and the controller held no authorization identifier, so any signed-in account on the platform could name another client's site and that site's patrol log ids and have the report emailed — to a list of up to 25 addresses of their own choosing, from the platform's sending address. The service's own log-belongs-to-site check is internal consistency, not reach: name the other estate's site and its own logs and the two agree. Reach is now decided from the session, on the site named in the request body, before anything is read, recorded, rendered or sent. `createdBy` — the audit row for who emailed patrol logs out of the system — is taken from the session rather than from the request body.
|
package/dist/index.js
CHANGED
|
@@ -53606,9 +53606,12 @@ var schemaSendPatrolEmail = import_joi77.default.object({
|
|
|
53606
53606
|
"string.pattern.base": '"url" must be a root-relative path, for example "/org/site/patrol-logs/report?ids=..."'
|
|
53607
53607
|
}),
|
|
53608
53608
|
site: import_joi77.default.string().hex().length(24).required(),
|
|
53609
|
+
// Pinned from the session by the controller, never taken from the request.
|
|
53610
|
+
// `name` allows "" because it is denormalised from the account and an account
|
|
53611
|
+
// may hold none - the same shape `schemaPatrolEmailCreatedBy` already stores.
|
|
53609
53612
|
createdBy: import_joi77.default.object({
|
|
53610
53613
|
_id: import_joi77.default.string().hex().length(24).required(),
|
|
53611
|
-
name: import_joi77.default.string().trim().max(200).required()
|
|
53614
|
+
name: import_joi77.default.string().trim().max(200).required().allow("")
|
|
53612
53615
|
}).required()
|
|
53613
53616
|
});
|
|
53614
53617
|
function toObjectId15(value, label) {
|
|
@@ -54049,10 +54052,15 @@ function usePatrolEmailService() {
|
|
|
54049
54052
|
var import_node_server_utils159 = require("@7365admin1/node-server-utils");
|
|
54050
54053
|
function usePatrolEmailController() {
|
|
54051
54054
|
const { send: _send } = usePatrolEmailService();
|
|
54055
|
+
async function requirePatrolEmailReach(req, site) {
|
|
54056
|
+
await requireSiteReach(req, site);
|
|
54057
|
+
}
|
|
54052
54058
|
async function send2(req, res, next) {
|
|
54053
|
-
const
|
|
54054
|
-
|
|
54055
|
-
|
|
54059
|
+
const actor = await resolveInviteActor(callerId(req));
|
|
54060
|
+
const { error, value } = schemaSendPatrolEmail.validate(
|
|
54061
|
+
{ ...req.body, createdBy: { _id: actor.id, name: actor.name } },
|
|
54062
|
+
{ abortEarly: false }
|
|
54063
|
+
);
|
|
54056
54064
|
if (error) {
|
|
54057
54065
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
54058
54066
|
import_node_server_utils159.logger.log({ level: "error", message: messages });
|
|
@@ -54060,6 +54068,7 @@ function usePatrolEmailController() {
|
|
|
54060
54068
|
return;
|
|
54061
54069
|
}
|
|
54062
54070
|
try {
|
|
54071
|
+
await requirePatrolEmailReach(req, value.site);
|
|
54063
54072
|
const cookieHeader = req.headers.cookie;
|
|
54064
54073
|
const data = await _send({
|
|
54065
54074
|
site: value.site,
|
|
@@ -54075,7 +54084,6 @@ function usePatrolEmailController() {
|
|
|
54075
54084
|
res.status(201).json({ message: "success", data });
|
|
54076
54085
|
return;
|
|
54077
54086
|
} catch (err) {
|
|
54078
|
-
console.log("err", err);
|
|
54079
54087
|
import_node_server_utils159.logger.log({ level: "error", message: `${err.message}` });
|
|
54080
54088
|
next(err);
|
|
54081
54089
|
return;
|