@7365admin1/core 3.48.1-staging.185 → 3.48.1-staging.186
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/bulletin-board-site-scope.md +19 -0
- package/dist/index.js +21 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +106 -81
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/e2e/bulletin-board-scope.e2e.test.mjs +442 -0
- package/test/e2e/harness.mjs +20 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
"@7365admin1/core": patch
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Scope the bulletin-board routes to the caller's own estate.
|
|
6
|
+
|
|
7
|
+
All five `/api/bulletin-boards` routes carried `requireAuth` and nothing more,
|
|
8
|
+
and the controller held no authorization identifier of any kind, so any
|
|
9
|
+
signed-in account in any organisation could publish an announcement into another
|
|
10
|
+
client's estate — which also fans out as a notification to every recipient group
|
|
11
|
+
at that site — read that board, and read, rewrite or delete any single bulletin
|
|
12
|
+
reached by id alone.
|
|
13
|
+
|
|
14
|
+
`add` and `getAll` now authorise the site named in the request with
|
|
15
|
+
`requireSiteReach`; `site` is optional on the add schema, so the org-wide case is
|
|
16
|
+
asked about separately rather than an absent site leaving the write unscoped. The
|
|
17
|
+
three by-id handlers take the verdict off the STORED row with a new module-named
|
|
18
|
+
`requireBulletinReach`, which answers "not yours" and "does not exist"
|
|
19
|
+
identically so bulletin ids cannot be enumerated.
|
package/dist/index.js
CHANGED
|
@@ -57728,6 +57728,15 @@ function useBulletinBoardController() {
|
|
|
57728
57728
|
deleteBulletinBoardById: _deleteBulletinBoardById
|
|
57729
57729
|
} = useBulletinBoardService();
|
|
57730
57730
|
const { getAll: _getAll, getBulletinBoardById: _getBulletinBoardById } = useBulletinBoardRepo();
|
|
57731
|
+
const scopeOf = (row) => ({ site: row?.site, org: row?.orgId });
|
|
57732
|
+
async function requireBulletinReach(req, id) {
|
|
57733
|
+
const bulletin = await _getBulletinBoardById(id);
|
|
57734
|
+
const { canReach } = await siteReachOf(req);
|
|
57735
|
+
if (!await canReach(scopeOf(bulletin))) {
|
|
57736
|
+
throw new import_node_server_utils174.NotFoundError("Bulletin board not found.");
|
|
57737
|
+
}
|
|
57738
|
+
return bulletin;
|
|
57739
|
+
}
|
|
57731
57740
|
async function add(req, res, next) {
|
|
57732
57741
|
const { error, value } = schemaBulletinBoard.validate(req.body, {
|
|
57733
57742
|
abortEarly: false
|
|
@@ -57739,6 +57748,14 @@ function useBulletinBoardController() {
|
|
|
57739
57748
|
return;
|
|
57740
57749
|
}
|
|
57741
57750
|
try {
|
|
57751
|
+
if (value.site) {
|
|
57752
|
+
await requireSiteReach(req, value.site);
|
|
57753
|
+
} else {
|
|
57754
|
+
const { canReach } = await siteReachOf(req);
|
|
57755
|
+
if (!await canReach(scopeOf(value))) {
|
|
57756
|
+
throw new import_node_server_utils174.UnauthorizedError("Not authorized.");
|
|
57757
|
+
}
|
|
57758
|
+
}
|
|
57742
57759
|
const data = await _add(value);
|
|
57743
57760
|
res.status(201).json(data);
|
|
57744
57761
|
return;
|
|
@@ -57811,6 +57828,7 @@ function useBulletinBoardController() {
|
|
|
57811
57828
|
[sort ? sort : "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
|
|
57812
57829
|
};
|
|
57813
57830
|
try {
|
|
57831
|
+
await requireSiteReach(req, site);
|
|
57814
57832
|
const data = await _getAll({
|
|
57815
57833
|
search,
|
|
57816
57834
|
page,
|
|
@@ -57841,7 +57859,7 @@ function useBulletinBoardController() {
|
|
|
57841
57859
|
return;
|
|
57842
57860
|
}
|
|
57843
57861
|
const { _id } = value;
|
|
57844
|
-
const data = await
|
|
57862
|
+
const data = await requireBulletinReach(req, _id);
|
|
57845
57863
|
res.status(200).json(data);
|
|
57846
57864
|
return;
|
|
57847
57865
|
} catch (error) {
|
|
@@ -57863,6 +57881,7 @@ function useBulletinBoardController() {
|
|
|
57863
57881
|
return;
|
|
57864
57882
|
}
|
|
57865
57883
|
try {
|
|
57884
|
+
await requireBulletinReach(req, _id);
|
|
57866
57885
|
const result = await _updateBulletinBoardById(_id, req.body);
|
|
57867
57886
|
res.status(200).json({ message: result });
|
|
57868
57887
|
return;
|
|
@@ -57884,6 +57903,7 @@ function useBulletinBoardController() {
|
|
|
57884
57903
|
}
|
|
57885
57904
|
const { _id } = value;
|
|
57886
57905
|
try {
|
|
57906
|
+
await requireBulletinReach(req, _id);
|
|
57887
57907
|
await _deleteBulletinBoardById(_id);
|
|
57888
57908
|
res.status(200).json({ message: "Successfully deleted bulletin board." });
|
|
57889
57909
|
return;
|