@7365admin1/core 3.109.0 → 3.111.0

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@7365admin1/core",
3
3
  "license": "MIT",
4
- "version": "3.109.0",
4
+ "version": "3.111.0",
5
5
  "author": "7365admin1",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -13,7 +13,7 @@
13
13
  "build": "tsup src/index.ts --format cjs,esm --dts && shx cp -r src/public dist && shx cp -r src/utils/handlebars dist",
14
14
  "release": "yarn run build && changeset publish",
15
15
  "lint": "tsc",
16
- "test": "tsup src/config.ts src/utils/building-map.util.ts src/utils/robot-cloud.util.ts src/utils/robot-adapter.util.ts src/utils/png-encoder.util.ts src/services/demo.adapter.ts src/services/ounitech.adapter.ts src/services/open-rmf.adapter.ts src/utils/robot-credentials.util.ts src/utils/rmf-building.util.ts src/utils/door-contract.util.ts src/utils/robot-fault.util.ts src/utils/robot-tracking.util.ts src/utils/robot-apps.util.ts src/utils/robot-permission.util.ts src/utils/robot-network.util.ts src/utils/lift-contract.util.ts src/models/robot-building-map.model.ts src/utils/anpr-revoke.util.ts src/utils/anpr-plate.util.ts src/utils/vehicle-request.util.ts src/utils/camera-view.util.ts src/utils/camera-bulk-import.util.ts src/utils/dashboard-metrics.util.ts src/utils/camera-capability.util.ts src/utils/camera-playback.util.ts src/services/camera-device-http.service.ts src/utils/camera-alert.util.ts src/utils/dahua-protocol.util.ts src/utils/site-name.util.ts src/utils/site-owner-edit.util.ts src/utils/service-provider-invite.util.ts src/utils/notification-category.util.ts src/utils/notification-kind.util.ts src/utils/notification-email.util.ts src/models/notification.model.ts src/utils/hid-card.util.ts src/utils/hid-json.util.ts src/utils/hid-access.util.ts src/models/customer-site.model.ts src/models/site-camera.model.ts src/models/member.model.ts src/models/subscription.model.ts src/utils/session-id.util.ts src/utils/occurrence-query.util.ts src/utils/occurrence-book-create.util.ts src/utils/update-result.util.ts src/utils/hid-amico-authz.util.ts src/utils/promo-code-currency.util.ts src/utils/console-audit.util.ts src/utils/org-suspension.util.ts src/utils/session-revoke.util.ts src/models/hid-amico.model.ts src/models/patrol-email.model.ts src/utils/patrol-email-pdf.util.ts src/utils/visitor-status.util.ts src/utils/self-service-email.util.ts src/utils/hid-secret.util.ts src/models/visitor-invite.model.ts src/models/guard-invite.model.ts src/utils/site-timezone.util.ts src/utils/bulletin-service-apps.util.ts src/models/bulletin-board.model.ts src/utils/vehicle-import.util.ts src/utils/expired-vehicle-sweep.util.ts src/models/vehicle.model.ts src/controllers/chat.controller.ts src/utils/file-owner.util.ts src/utils/console-permission.util.ts src/utils/role-scope.util.ts src/utils/org-default-roles.util.ts src/utils/org-modules.util.ts src/utils/site-modules.util.ts src/utils/resident-app-modules.util.ts src/utils/resident-default-role.util.ts src/utils/invite-role-scope.util.ts src/models/personal-emergency-chain.model.ts src/utils/self-signup-files.util.ts src/models/person.model.ts src/utils/module-gate.util.ts src/utils/member-lookup.util.ts src/utils/notification-access.util.ts src/utils/module-access.util.ts src/services/module-gate.service.ts src/controllers/site.controller.ts src/controllers/organization.controller.ts src/controllers/member.controller.ts src/utils/org-owner-repair.util.ts src/utils/socket-session.util.ts src/utils/people-create-gate.util.ts src/utils/service-app-type.util.ts src/utils/customer-site-list.util.ts src/utils/org-search.util.ts src/utils/invite-origin.util.ts --format esm --out-dir test/.build --no-dts --silent && node --test test/*.test.mjs",
16
+ "test": "tsup src/config.ts src/utils/building-map.util.ts src/utils/robot-cloud.util.ts src/utils/robot-adapter.util.ts src/utils/png-encoder.util.ts src/services/demo.adapter.ts src/services/ounitech.adapter.ts src/services/open-rmf.adapter.ts src/utils/robot-credentials.util.ts src/utils/rmf-building.util.ts src/utils/door-contract.util.ts src/utils/robot-fault.util.ts src/utils/robot-tracking.util.ts src/utils/robot-apps.util.ts src/utils/robot-permission.util.ts src/utils/robot-network.util.ts src/utils/lift-contract.util.ts src/models/robot-building-map.model.ts src/utils/anpr-revoke.util.ts src/utils/anpr-plate.util.ts src/utils/vehicle-request.util.ts src/utils/camera-view.util.ts src/utils/camera-bulk-import.util.ts src/utils/dashboard-metrics.util.ts src/utils/camera-capability.util.ts src/utils/camera-playback.util.ts src/services/camera-device-http.service.ts src/utils/camera-alert.util.ts src/utils/dahua-protocol.util.ts src/utils/site-name.util.ts src/utils/site-owner-edit.util.ts src/utils/service-provider-invite.util.ts src/utils/notification-category.util.ts src/utils/notification-kind.util.ts src/utils/notification-email.util.ts src/models/notification.model.ts src/utils/hid-card.util.ts src/utils/hid-json.util.ts src/utils/hid-access.util.ts src/models/customer-site.model.ts src/models/site-camera.model.ts src/models/member.model.ts src/models/subscription.model.ts src/utils/session-id.util.ts src/utils/occurrence-query.util.ts src/utils/occurrence-book-create.util.ts src/utils/update-result.util.ts src/utils/hid-amico-authz.util.ts src/utils/promo-code-currency.util.ts src/utils/console-audit.util.ts src/utils/org-suspension.util.ts src/utils/session-revoke.util.ts src/models/hid-amico.model.ts src/models/patrol-email.model.ts src/utils/patrol-email-pdf.util.ts src/utils/visitor-status.util.ts src/utils/self-service-email.util.ts src/utils/hid-secret.util.ts src/models/visitor-invite.model.ts src/models/guard-invite.model.ts src/utils/site-timezone.util.ts src/utils/bulletin-service-apps.util.ts src/models/bulletin-board.model.ts src/utils/vehicle-import.util.ts src/utils/expired-vehicle-sweep.util.ts src/models/vehicle.model.ts src/controllers/chat.controller.ts src/utils/file-owner.util.ts src/utils/console-permission.util.ts src/utils/role-scope.util.ts src/utils/org-default-roles.util.ts src/utils/org-modules.util.ts src/utils/site-modules.util.ts src/utils/resident-app-modules.util.ts src/utils/resident-default-role.util.ts src/utils/invite-role-scope.util.ts src/models/personal-emergency-chain.model.ts src/utils/self-signup-files.util.ts src/models/person.model.ts src/utils/module-gate.util.ts src/utils/member-lookup.util.ts src/utils/notification-access.util.ts src/utils/module-access.util.ts src/services/module-gate.service.ts src/controllers/site.controller.ts src/controllers/organization.controller.ts src/controllers/member.controller.ts src/utils/org-owner-repair.util.ts src/utils/socket-session.util.ts src/utils/people-create-gate.util.ts src/utils/service-app-type.util.ts src/utils/customer-site-list.util.ts src/utils/org-search.util.ts src/utils/invite-origin.util.ts src/utils/member-role-assign.util.ts --format esm --out-dir test/.build --no-dts --silent && node --test test/*.test.mjs",
17
17
  "test:camera": "yarn test",
18
18
  "test:e2e": "yarn build && node --test --test-concurrency=1 --test-timeout=600000 \"test/e2e/*.test.mjs\""
19
19
  },
@@ -0,0 +1,173 @@
1
+ // Assign Role end to end, reproducing the owner's report (2026-09-25,
2
+ // production): Security app, Aigle Security / Newton 200 → Members → Assign Role
3
+ // "Security Newton 200" → "No owner role found."
4
+ //
5
+ // The organisation here stores NO "*" role at all — its owner holds an org-less
6
+ // template ("Org Owner", explicit list), exactly like Aigle. Before the fix
7
+ // case 1 answered 400 "No owner role found.".
8
+ //
9
+ // Everything runs against the throwaway harness (in-process MongoDB, loopback
10
+ // Redis/mail). No staging or production system is touched.
11
+ //
12
+ // Run with: yarn test:e2e
13
+
14
+ import { after, before, describe, it } from "node:test";
15
+ import assert from "node:assert/strict";
16
+ import { ObjectId } from "mongodb";
17
+
18
+ import { startHarness } from "./harness.mjs";
19
+
20
+ const PASSWORD = "AssignRole-Passw0rd!";
21
+ const OWNER = "ar-owner@e2e.example.com"; // holds the org-less template, like Aigle's owner
22
+ const GUARD = "ar-guard@e2e.example.com"; // an ordinary member without the grant
23
+ const TARGET = "ar-target@e2e.example.com"; // the site member being re-roled
24
+ const OUTSIDER = "ar-outsider@e2e.example.com"; // admin of another org
25
+ const SOLE = "ar-sole@e2e.example.com"; // the only '*' owner in org B
26
+ const STAFF = "ar-staff@e2e.example.com"; // Seven365 platform staff (console)
27
+
28
+ describe("Assign Role works without a stored owner role, and stays scoped", { concurrency: 1 }, () => {
29
+ let h;
30
+ const id = {};
31
+ const sid = {};
32
+
33
+ before(async () => {
34
+ h = await startHarness();
35
+ Object.assign(id, await seed(h));
36
+ for (const [k, e] of Object.entries({ OWNER, GUARD, OUTSIDER, SOLE, STAFF })) sid[k] = await h.login(e, PASSWORD);
37
+ }, { timeout: 300000 });
38
+
39
+ after(async () => {
40
+ if (h) await h.stop();
41
+ });
42
+
43
+ const url = (member, role, org = id.org, type = "security_agency") =>
44
+ `/members/id/${member}/role/${role}/type/${type}/org/${org}`;
45
+ const roleOf = async (member) =>
46
+ (await h.db.collection("members").findOne({ _id: member }))?.role?.toString();
47
+
48
+ it("1. owner assigns this site's role to a site member — org has no stored owner role", async () => {
49
+ const res = await h.api(url(id.target, id.siteRole), { method: "PUT", sid: sid.OWNER });
50
+ assert.equal(res.status, 200, JSON.stringify(res.body));
51
+ assert.equal(await roleOf(id.target), id.siteRole.toString());
52
+ });
53
+
54
+ it("2. a role of another organisation is refused", async () => {
55
+ const res = await h.api(url(id.target, id.otherOrgRole), { method: "PUT", sid: sid.OWNER });
56
+ assert.equal(res.status, 400);
57
+ assert.match(res.body.message, /different organisation/);
58
+ assert.equal(await roleOf(id.target), id.siteRole.toString());
59
+ });
60
+
61
+ it("3. a role pinned to another site is refused", async () => {
62
+ const res = await h.api(url(id.target, id.otherSiteRole), { method: "PUT", sid: sid.OWNER });
63
+ assert.equal(res.status, 400);
64
+ assert.match(res.body.message, /different site/);
65
+ });
66
+
67
+ it("4. a member without members:assign-member-role is refused", async () => {
68
+ const res = await h.api(url(id.target, id.oldRole), { method: "PUT", sid: sid.GUARD });
69
+ assert.equal(res.status, 401);
70
+ assert.equal(await roleOf(id.target), id.siteRole.toString());
71
+ });
72
+
73
+ it("5. another org's admin is refused", async () => {
74
+ const res = await h.api(url(id.target, id.oldRole), { method: "PUT", sid: sid.OUTSIDER });
75
+ assert.equal(res.status, 401);
76
+ });
77
+
78
+ it("6. the only '*' owner still cannot be demoted", async () => {
79
+ const res = await h.api(url(id.soleMember, id.plainRoleB, id.orgB, "organization"), { method: "PUT", sid: sid.SOLE });
80
+ assert.equal(res.status, 400);
81
+ assert.match(res.body.message, /only owner member/);
82
+ });
83
+
84
+ it("8. console: staff re-role an org-less staff membership via the empty-org URL; a client cannot", async () => {
85
+ const path = `/members/id/${id.staffTarget}/role/${id.staffRole2}/type/admin/org/`;
86
+ const refused = await h.api(path, { method: "PUT", sid: sid.OWNER });
87
+ assert.equal(refused.status, 401);
88
+ const res = await h.api(path, { method: "PUT", sid: sid.STAFF });
89
+ assert.equal(res.status, 200, JSON.stringify(res.body));
90
+ assert.equal(await roleOf(id.staffTarget), id.staffRole2.toString());
91
+ });
92
+
93
+ it("7. the Members list shows the real role name and flags a deleted role", async () => {
94
+ await h.db.collection("members").updateOne({ _id: id.target }, { $set: { role: id.deletedRole } });
95
+ const res = await h.api(`/members?org=${id.org}&siteId=${id.site}&type=security_agency&status=active&page=1`, { sid: sid.OWNER });
96
+ assert.equal(res.status, 200, JSON.stringify(res.body));
97
+ const row = res.body.items.find((m) => String(m._id) === String(id.target));
98
+ assert.equal(row.roleName, "Security");
99
+ assert.equal(row.roleState, "deleted");
100
+ });
101
+
102
+ it("9. the Members list flags another site's role as other-site (with that site's name); an org-wide role stays ok", async () => {
103
+ // The page is cached per query, and these writes bypass the service, so
104
+ // each read asks a distinct page size to get a fresh aggregation.
105
+ let limit = 20;
106
+ const list = async () => {
107
+ const res = await h.api(`/members?org=${id.org}&siteId=${id.site}&type=security_agency&status=active&page=1&limit=${++limit}`, { sid: sid.OWNER });
108
+ assert.equal(res.status, 200, JSON.stringify(res.body));
109
+ return res.body.items.find((m) => String(m._id) === String(id.target));
110
+ };
111
+ await h.db.collection("members").updateOne({ _id: id.target }, { $set: { role: id.otherSiteRole } });
112
+ const other = await list();
113
+ assert.equal(other.roleName, "Security Roles");
114
+ assert.equal(other.roleState, "other-site");
115
+ assert.equal(other.roleSiteName, "The Loft");
116
+
117
+ await h.db.collection("members").updateOne({ _id: id.target }, { $set: { role: id.siteRole } });
118
+ assert.equal((await list()).roleState, "ok"); // this site's own role
119
+
120
+ await h.db.collection("members").updateOne({ _id: id.target }, { $set: { role: id.oldRole } });
121
+ const orgWide = await list();
122
+ assert.equal(orgWide.roleState, "ok"); // org-level role, no site
123
+ assert.equal(orgWide.roleSiteName, undefined);
124
+ });
125
+ });
126
+
127
+ async function seed(h) {
128
+ const now = new Date().toISOString();
129
+ const org = new ObjectId(), orgB = new ObjectId(), site = new ObjectId(), otherSite = new ObjectId();
130
+ const template = new ObjectId(), guardRole = new ObjectId(), oldRole = new ObjectId(), siteRole = new ObjectId();
131
+ const otherSiteRole = new ObjectId(), deletedRole = new ObjectId(), otherOrgRole = new ObjectId();
132
+ const ownerRoleB = new ObjectId(), plainRoleB = new ObjectId();
133
+ const staffRole = new ObjectId(), staffRole2 = new ObjectId();
134
+
135
+ await h.db.collection("organizations").insertMany([
136
+ { _id: org, name: "AR Security", email: "ar-org@e2e.example.com", type: "org", nature: "security_agency", status: "active", createdAt: now },
137
+ { _id: orgB, name: "AR Other", email: "ar-orgb@e2e.example.com", type: "org", nature: "security_agency", status: "active", createdAt: now },
138
+ ]);
139
+ await h.db.collection("sites").insertMany([
140
+ { _id: site, name: "Newton 200", org, orgId: org, status: "active" },
141
+ { _id: otherSite, name: "The Loft", org, orgId: org, status: "active" },
142
+ ]);
143
+ await h.db.collection("roles").insertMany([
144
+ { _id: template, name: "Org Owner", org: "", type: "organization", permissions: ["members:view-members", "members:assign-member-role"], status: "active" },
145
+ { _id: guardRole, name: "Guard", org, type: "security_agency", permissions: ["members:view-members"], status: "active" },
146
+ { _id: oldRole, name: "Old", org, type: "security_agency", permissions: ["members:view-members"], status: "active" },
147
+ { _id: siteRole, name: "Security Newton 200", org, site, type: "security_agency", permissions: ["members:view-members"], status: "active" },
148
+ { _id: otherSiteRole, name: "Security Roles", org, site: otherSite, type: "security_agency", permissions: [], status: "active" },
149
+ { _id: deletedRole, name: "Security", org, type: "security_agency", permissions: [], status: "deleted" },
150
+ { _id: otherOrgRole, name: "Other org role", org: orgB, type: "security_agency", permissions: [], status: "active" },
151
+ { _id: ownerRoleB, name: "owner", org: orgB, type: "organization", permissions: ["*"], status: "active" },
152
+ { _id: plainRoleB, name: "Plain B", org: orgB, type: "organization", permissions: ["members:view-members"], status: "active" },
153
+ { _id: staffRole, name: "Super Admin", type: "admin", default: true, permissions: [], status: "active" },
154
+ { _id: staffRole2, name: "Support", type: "admin", permissions: [], status: "active" },
155
+ ]);
156
+
157
+ const emails = [OWNER, GUARD, TARGET, OUTSIDER, SOLE, STAFF, "ar-staff2@e2e.example.com"];
158
+ const users = await h.db.collection("users").insertMany(emails.map((email) => ({ email, name: email, status: "active", createdAt: now })));
159
+ await h.db.collection("users").updateMany({ email: { $in: emails } }, { $set: { password: await h.hashPassword(PASSWORD) } });
160
+ const [owner, guard, target, outsider, sole, staff, staff2] = emails.map((_, i) => users.insertedIds[i]);
161
+
162
+ const m = await h.db.collection("members").insertMany([
163
+ { user: owner, org, type: "security_agency", role: template, status: "active" },
164
+ { user: guard, org, type: "security_agency", role: guardRole, siteId: site, siteName: "Newton 200", status: "active" },
165
+ { user: target, org, type: "security_agency", role: oldRole, siteId: site, siteName: "Newton 200", status: "active", dateInvited: now },
166
+ { user: outsider, org: orgB, type: "organization", role: plainRoleB, status: "active" },
167
+ { user: sole, org: orgB, type: "organization", role: ownerRoleB, status: "active" },
168
+ { user: staff, type: "admin", role: staffRole, status: "active" },
169
+ { user: staff2, type: "admin", role: staffRole, status: "active" },
170
+ ]);
171
+
172
+ return { org, orgB, site, siteRole, otherSiteRole, deletedRole, otherOrgRole, oldRole, plainRoleB, target: m.insertedIds[2], soleMember: m.insertedIds[4], staffTarget: m.insertedIds[6], staffRole2 };
173
+ }
@@ -334,6 +334,7 @@ function buildApp(nsu, core) {
334
334
  members.get("/user/:id/app/:type", requireAuth, getByUserIdType);
335
335
  members.put("/:id/:status", requireAuth, updateMemberStatus);
336
336
  members.put("/id/:id/role/:role/type/:type/org/:org", requireAuth, updateRoleById);
337
+ members.put("/id/:id/role/:role/type/:type/org", requireAuth, updateRoleById);
337
338
  members.put("/site", requireAuth, updateSiteById);
338
339
  members.put("/:id/onboarding/complete", requireAuth, completeOnboarding);
339
340
  members.get("/user/:id/app/:type/org", requireAuth, getByUserIdTypeOrg);
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Assign Role on the Members screens (owner report 2026-09-25: Aigle Security /
3
+ * Newton 200, "No owner role found."). The pure decisions; the real HTTP path
4
+ * is `test/e2e/assign-role-owner.e2e.test.mjs`.
5
+ */
6
+ import test from "node:test";
7
+ import assert from "node:assert/strict";
8
+ import { readFileSync } from "node:fs";
9
+ import { fileURLToPath } from "node:url";
10
+
11
+ import {
12
+ assignRoleRefusal,
13
+ isOwnerRole,
14
+ roleGrantsAssign,
15
+ } from "./.build/utils/member-role-assign.util.mjs";
16
+
17
+ const ORG = "6a3e323f04d9bfc9b638cfdb";
18
+ const OTHER = "690053d194b3f2e7d74be49b";
19
+ const SITE = "6a3e36be04d9bfc9b638cfe7";
20
+ const OTHER_SITE = "6a3e329104d9bfc9b638cfde";
21
+ const siteMember = { org: ORG, type: "security_agency", siteId: SITE };
22
+
23
+ test("the owner's case: a site role of this org, for this site, is allowed", () => {
24
+ const role = { org: ORG, type: "security_agency", site: SITE, status: "active" };
25
+ assert.equal(assignRoleRefusal(role, siteMember), null);
26
+ });
27
+
28
+ test("an org-wide role of this org is allowed on a site member", () => {
29
+ assert.equal(assignRoleRefusal({ org: ORG, type: "organization", status: "active" }, siteMember), null);
30
+ });
31
+
32
+ test("refusals: other org, template, deleted, other app, other site, missing", () => {
33
+ assert.equal(assignRoleRefusal({ org: OTHER, type: "security_agency", status: "active" }, siteMember), "That role belongs to a different organisation.");
34
+ assert.match(assignRoleRefusal({ org: "", type: "organization", status: "active" }, siteMember), /template/);
35
+ assert.equal(assignRoleRefusal({ org: ORG, type: "security_agency", status: "deleted" }, siteMember), "That role has been deleted.");
36
+ assert.equal(assignRoleRefusal({ org: ORG, type: "cleaning_services", status: "active" }, siteMember), "That role belongs to a different application.");
37
+ assert.equal(assignRoleRefusal({ org: ORG, type: "security_agency", site: OTHER_SITE, status: "active" }, siteMember), "That role belongs to a different site.");
38
+ assert.equal(assignRoleRefusal(null, siteMember), "That role does not exist.");
39
+ });
40
+
41
+ test("an organisation-type membership may hold any of its org's app roles (38 staging rows do)", () => {
42
+ const orgRow = { org: ORG, type: "organization", siteId: "" };
43
+ assert.equal(assignRoleRefusal({ org: ORG, type: "security_agency", status: "active" }, orgRow), null);
44
+ assert.match(assignRoleRefusal({ type: "admin", org: "" }, orgRow), /Seven365 console/);
45
+ });
46
+
47
+ test("roleGrantsAssign follows the client's grantsPermission rule", () => {
48
+ assert.equal(roleGrantsAssign(["members:assign-member-role"]), true);
49
+ assert.equal(roleGrantsAssign(["*"]), true);
50
+ assert.equal(roleGrantsAssign([]), true);
51
+ assert.equal(roleGrantsAssign(undefined), true);
52
+ assert.equal(roleGrantsAssign(["members:view-members"]), false);
53
+ });
54
+
55
+ test("isOwnerRole is exactly a '*' grant", () => {
56
+ assert.equal(isOwnerRole({ permissions: ["*"] }), true);
57
+ assert.equal(isOwnerRole({ permissions: ["members:view-members"] }), false);
58
+ assert.equal(isOwnerRole(null), false);
59
+ });
60
+
61
+ test("wiring: the service no longer demands a stored owner role before any change", () => {
62
+ const svc = readFileSync(fileURLToPath(new URL("../src/services/member.service.ts", import.meta.url)), "utf8");
63
+ assert.doesNotMatch(svc, /No owner role found/);
64
+ assert.doesNotMatch(svc, /No owner members found/);
65
+ assert.match(svc, /assignRoleRefusal\(/);
66
+ const ctl = readFileSync(fileURLToPath(new URL("../src/controllers/member.controller.ts", import.meta.url)), "utf8");
67
+ assert.match(ctl, /requireRoleAssigner\(req, org\)/);
68
+ });