@7365admin1/core 3.99.1-staging.384 → 3.99.1-staging.386
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/hid-sip-account-list-site-scope.md +23 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +47 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/e2e/site-delete-owner-only.e2e.test.mjs +148 -0
- package/test/site-owner-edit.test.mjs +18 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
"@7365admin1/core": minor
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Scope the HID SIP account list to the site alone.
|
|
6
|
+
|
|
7
|
+
`GET /sites/:siteId/intercom/sip-accounts` required an `orgId` query parameter
|
|
8
|
+
and filtered the accounts by it. That organisation never decided access — the
|
|
9
|
+
handler's `authorizeSite` resolves the caller's right to the site from their
|
|
10
|
+
own memberships — so all `orgId` did was narrow the rows, and it did so wrongly
|
|
11
|
+
in two places:
|
|
12
|
+
|
|
13
|
+
- a screen mounted without an organisation in scope could not call the endpoint
|
|
14
|
+
at all, leaving the intercom contact dialog with an empty name picker;
|
|
15
|
+
- on a customer site, accounts provisioned by a managing agent carry that
|
|
16
|
+
agent's `orgId`, so the site's own operators could not see them — although
|
|
17
|
+
the door station behind the contact list rings those people regardless.
|
|
18
|
+
|
|
19
|
+
`listSipAccounts` now takes only `siteId`, both in the service and the
|
|
20
|
+
repository, and the controller no longer validates the query. An older client
|
|
21
|
+
that still sends `orgId` is ignored rather than refused, so the endpoint stays
|
|
22
|
+
backward compatible. `ensureSipAccount` is unchanged: it provisions an account
|
|
23
|
+
and still records the organisation it was created under.
|
package/dist/index.d.ts
CHANGED
|
@@ -17140,7 +17140,7 @@ declare function useHidAmicoRepo(): {
|
|
|
17140
17140
|
pageRange: string;
|
|
17141
17141
|
}>;
|
|
17142
17142
|
getSipAccount: (orgIdValue: string | ObjectId, siteValue: string | ObjectId, userValue: string | ObjectId) => Promise<mongodb.WithId<bson.Document> | null>;
|
|
17143
|
-
listSipAccounts: (
|
|
17143
|
+
listSipAccounts: (siteValue: string | ObjectId) => Promise<{
|
|
17144
17144
|
_id: string;
|
|
17145
17145
|
userId: string;
|
|
17146
17146
|
name: string;
|
|
@@ -17870,7 +17870,7 @@ declare function useHidAmicoService(): {
|
|
|
17870
17870
|
status: "active" | "failed" | "disabled" | "provisioning" | undefined;
|
|
17871
17871
|
provisionedAt: string | Date;
|
|
17872
17872
|
}>;
|
|
17873
|
-
listSipAccounts: (
|
|
17873
|
+
listSipAccounts: (siteId: string) => Promise<{
|
|
17874
17874
|
_id: string;
|
|
17875
17875
|
userId: string;
|
|
17876
17876
|
name: string;
|
package/dist/index.js
CHANGED
|
@@ -39134,17 +39134,49 @@ function siteOwnerOnlyMessage(ownerName) {
|
|
|
39134
39134
|
async function requireSiteOwnerEdit(actor, staff, siteId) {
|
|
39135
39135
|
if (staff)
|
|
39136
39136
|
return;
|
|
39137
|
+
const ownerOrg = await ownerOfSite(siteId);
|
|
39138
|
+
if (mayEditSiteDetails({ staff, actorOrgIds: actor.orgIds, ownerOrg }))
|
|
39139
|
+
return;
|
|
39140
|
+
throw new import_node_server_utils113.AppError(siteOwnerOnlyMessage(await ownerOrgName(ownerOrg)), 403);
|
|
39141
|
+
}
|
|
39142
|
+
async function ownerOfSite(siteId) {
|
|
39137
39143
|
const id = String(siteId?.toString?.() ?? "");
|
|
39138
39144
|
const db2 = import_node_server_utils113.useAtlas.getDb();
|
|
39139
39145
|
const site = db2 && import_mongodb79.ObjectId.isValid(id) ? await db2.collection("sites").findOne({ _id: new import_mongodb79.ObjectId(id) }, { projection: { orgId: 1, org: 1 } }) : null;
|
|
39140
|
-
|
|
39141
|
-
|
|
39146
|
+
return site?.orgId ?? site?.org;
|
|
39147
|
+
}
|
|
39148
|
+
async function ownerOrgName(ownerOrg) {
|
|
39149
|
+
if (!ownerOrg || !import_mongodb79.ObjectId.isValid(String(ownerOrg)))
|
|
39150
|
+
return void 0;
|
|
39151
|
+
const owner = await import_node_server_utils113.useAtlas.getDb()?.collection("organizations").findOne({ _id: new import_mongodb79.ObjectId(String(ownerOrg)) }, { projection: { name: 1 } });
|
|
39152
|
+
return owner?.name;
|
|
39153
|
+
}
|
|
39154
|
+
var DELETE_SITE_PERMISSION = "sites:delete-site";
|
|
39155
|
+
var NO_SITE_DELETE_PERMISSION = "You do not have permission to delete this site.";
|
|
39156
|
+
function siteDeleteOwnerOnlyMessage(ownerName) {
|
|
39157
|
+
const name = String(ownerName ?? "").trim() || "another organisation";
|
|
39158
|
+
return `This site belongs to ${name}. Only they can delete it. You can remove it from your Sites list instead.`;
|
|
39159
|
+
}
|
|
39160
|
+
function mayDeleteSite(permissions) {
|
|
39161
|
+
return permissions.includes("*") || permissions.includes(DELETE_SITE_PERMISSION);
|
|
39162
|
+
}
|
|
39163
|
+
async function requireSiteOwnerDelete(actor, staff, siteId) {
|
|
39164
|
+
if (staff)
|
|
39142
39165
|
return;
|
|
39143
|
-
const owner =
|
|
39144
|
-
|
|
39145
|
-
|
|
39146
|
-
|
|
39147
|
-
|
|
39166
|
+
const owner = String(await ownerOfSite(siteId) ?? "");
|
|
39167
|
+
if (owner && import_mongodb79.ObjectId.isValid(owner) && import_mongodb79.ObjectId.isValid(actor.id)) {
|
|
39168
|
+
const member = await import_node_server_utils113.useAtlas.getDb()?.collection("members").findOne(
|
|
39169
|
+
{ user: new import_mongodb79.ObjectId(actor.id), org: new import_mongodb79.ObjectId(owner), type: "organization", status: "active" },
|
|
39170
|
+
{ projection: { role: 1 } }
|
|
39171
|
+
);
|
|
39172
|
+
if (member) {
|
|
39173
|
+
const permissions = member.role ? await getUserPermissions({ user: actor.id, org: owner, role: member.role }) : [];
|
|
39174
|
+
if (mayDeleteSite(permissions))
|
|
39175
|
+
return;
|
|
39176
|
+
throw new import_node_server_utils113.AppError(NO_SITE_DELETE_PERMISSION, 403);
|
|
39177
|
+
}
|
|
39178
|
+
}
|
|
39179
|
+
throw new import_node_server_utils113.AppError(siteDeleteOwnerOnlyMessage(await ownerOrgName(owner)), 403);
|
|
39148
39180
|
}
|
|
39149
39181
|
|
|
39150
39182
|
// src/controllers/site.controller.ts
|
|
@@ -39455,7 +39487,8 @@ function useSiteController() {
|
|
|
39455
39487
|
return;
|
|
39456
39488
|
}
|
|
39457
39489
|
try {
|
|
39458
|
-
await requireSiteWrite(req, _id);
|
|
39490
|
+
const actor = await requireSiteWrite(req, _id);
|
|
39491
|
+
await requireSiteOwnerDelete(actor, staffMayBypass(actor), _id);
|
|
39459
39492
|
await _deleteSite(_id);
|
|
39460
39493
|
res.json({ message: "Successfully deleted site." });
|
|
39461
39494
|
return;
|
|
@@ -49371,10 +49404,9 @@ function useHidAmicoRepo() {
|
|
|
49371
49404
|
}
|
|
49372
49405
|
return labels;
|
|
49373
49406
|
}
|
|
49374
|
-
async function listSipAccounts(
|
|
49407
|
+
async function listSipAccounts(siteValue) {
|
|
49375
49408
|
const siteId = toId4(siteValue, "site ID");
|
|
49376
49409
|
const accounts = await sipAccounts().find({
|
|
49377
|
-
orgId: toId4(orgIdValue, "organization ID"),
|
|
49378
49410
|
site: siteId,
|
|
49379
49411
|
status: { $ne: "disabled" }
|
|
49380
49412
|
}, {
|
|
@@ -55399,9 +55431,8 @@ function useHidAmicoService() {
|
|
|
55399
55431
|
}
|
|
55400
55432
|
return sipAccountResponse(account);
|
|
55401
55433
|
}
|
|
55402
|
-
async function listSipAccounts(
|
|
55403
|
-
|
|
55404
|
-
return repo.listSipAccounts(orgId, siteId);
|
|
55434
|
+
async function listSipAccounts(siteId) {
|
|
55435
|
+
return repo.listSipAccounts(siteId);
|
|
55405
55436
|
}
|
|
55406
55437
|
return {
|
|
55407
55438
|
authorizeReader,
|
|
@@ -101873,15 +101904,14 @@ function useHidAmicoController() {
|
|
|
101873
101904
|
}
|
|
101874
101905
|
async function listSipAccounts(req, res, next) {
|
|
101875
101906
|
const params = schemaHidAmicoSiteIdParams.validate(req.params);
|
|
101876
|
-
|
|
101877
|
-
|
|
101878
|
-
next(new import_node_server_utils316.BadRequestError(params.error?.message || query2.error?.message));
|
|
101907
|
+
if (params.error) {
|
|
101908
|
+
next(new import_node_server_utils316.BadRequestError(params.error.message));
|
|
101879
101909
|
return;
|
|
101880
101910
|
}
|
|
101881
101911
|
try {
|
|
101882
101912
|
await authorizeSite(req, params.value.siteId);
|
|
101883
101913
|
res.json({
|
|
101884
|
-
data: await service.listSipAccounts(
|
|
101914
|
+
data: await service.listSipAccounts(params.value.siteId)
|
|
101885
101915
|
});
|
|
101886
101916
|
} catch (error) {
|
|
101887
101917
|
next(error);
|