@7365admin1/core 3.102.1 → 3.103.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.102.1",
4
+ "version": "3.103.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/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/service-provider-invite.util.ts src/utils/notification-category.util.ts src/utils/notification-kind.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 --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/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/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 --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
  },
@@ -183,11 +183,8 @@ describe(
183
183
  // ---- adversarial: can the scope be widened from the request? ----------
184
184
 
185
185
  record("8. `search` cannot reach a client she is not in", async () => {
186
- // `search` becomes a `$text` stage, which is ANDed with the scope rather
187
- // than replacing it. The seed builds the text index this needs; note
188
- // that the shipped `createIndex()` does NOT build one, so `search=` is a
189
- // 500 on staging and production today - pre-existing, reported, not
190
- // touched here.
186
+ // `search` becomes a substring match on name/e-mail, ANDed with the
187
+ // scope rather than replacing it.
191
188
  const res = await h.api(
192
189
  `/organizations?page=1&limit=50&search=${encodeURIComponent("Estates")}`,
193
190
  { sid: mallorySid },
@@ -205,6 +202,48 @@ describe(
205
202
  assert.deepEqual(ids(res.body), [id.orgB.toString()]);
206
203
  });
207
204
 
205
+ record("8c. part of a name, in any case, finds the client (Client details picker)", async () => {
206
+ for (const term of ["estat", "ORG B", " b estates "]) {
207
+ const res = await h.api(
208
+ `/organizations?page=1&limit=50&search=${encodeURIComponent(term)}`,
209
+ { sid: staffSid },
210
+ );
211
+ assert.equal(res.status, 200, JSON.stringify(res.body));
212
+ assert.deepEqual(ids(res.body), [id.orgB.toString()], term);
213
+ }
214
+ });
215
+
216
+ record("8d. the e-mail is searched, and a partial search still cannot leave the scope", async () => {
217
+ const staff = await h.api(
218
+ `/organizations?page=1&limit=50&search=${encodeURIComponent("pl-orgc@")}`,
219
+ { sid: staffSid },
220
+ );
221
+ assert.deepEqual(ids(staff.body), [id.orgC.toString()]);
222
+ const res = await h.api(
223
+ `/organizations?page=1&limit=50&search=${encodeURIComponent("estat")}`,
224
+ { sid: mallorySid },
225
+ );
226
+ assert.equal(res.status, 200, JSON.stringify(res.body));
227
+ assert.deepEqual(ids(res.body), []);
228
+ });
229
+
230
+ record("8e. regex characters are literal, not a pattern that lists everyone", async () => {
231
+ const res = await h.api(
232
+ `/organizations?page=1&limit=50&search=${encodeURIComponent(".*")}`,
233
+ { sid: staffSid },
234
+ );
235
+ assert.equal(res.status, 200, JSON.stringify(res.body));
236
+ assert.deepEqual(ids(res.body), []);
237
+ });
238
+
239
+ record("8f. the Client List search (v2 subscriptions) treats `(` literally, not as a 500", async () => {
240
+ const res = await h.api(
241
+ `/organizations/v2/orgs/subscriptions?page=1&limit=50&search=${encodeURIComponent("Org (B")}`,
242
+ { sid: staffSid },
243
+ );
244
+ assert.equal(res.status, 200, JSON.stringify(res.body));
245
+ });
246
+
208
247
  record("9. nor can `nature`", async () => {
209
248
  const res = await h.api(
210
249
  "/organizations?page=1&limit=50&nature=property_management_agency",
@@ -0,0 +1,215 @@
1
+ // Owner decision (Harris, 2026-09-25): only the OWNING client organisation may
2
+ // change a site's core details - name, address, category, timezone, property
3
+ // details and the Site Information page. A service provider that serves the
4
+ // site can read them and can still remove the site from its OWN Sites list.
5
+ //
6
+ // Everything runs against the throwaway in-process harness (in-memory MongoDB,
7
+ // loopback Redis and mail). Nothing outside this process is touched.
8
+ //
9
+ // Run with: yarn build && node --test test/e2e/site-edit-owner-only.e2e.test.mjs
10
+
11
+ import { after, before, describe, it } from "node:test";
12
+ import assert from "node:assert/strict";
13
+ import { ObjectId } from "mongodb";
14
+
15
+ import { startHarness } from "./harness.mjs";
16
+
17
+ const PASSWORD = "OwnerOnly-Passw0rd!";
18
+ const MANAGER = "oo-manager@e2e.example.com"; // owning client's admin
19
+ const AGENCY = "oo-agency@e2e.example.com"; // provider org admin, serves the site
20
+ const STAFF = "oo-sevenadmin@e2e.example.com";
21
+ const REFUSAL = "This site belongs to OO Client. Only they can change its details.";
22
+
23
+ describe("only the owning client edits a site's details", { concurrency: 1 }, () => {
24
+ let h;
25
+ const id = {};
26
+ const result = [];
27
+ const sid = {};
28
+
29
+ const record = (name, fn) =>
30
+ it(name, async () => {
31
+ try {
32
+ await fn();
33
+ result.push(["PASS", name]);
34
+ } catch (error) {
35
+ result.push(["FAIL", name]);
36
+ throw error;
37
+ }
38
+ });
39
+
40
+ const site = () => h.db.collection("sites").findOne({ _id: id.site });
41
+
42
+ before(async () => {
43
+ h = await startHarness();
44
+ Object.assign(id, await seed(h));
45
+ }, { timeout: 300000 });
46
+
47
+ after(async () => {
48
+ if (h) await h.stop();
49
+ console.log("\n--- site edit owner-only: per-case result ---");
50
+ for (const [verdict, name] of result) console.log(`${verdict} ${name}`);
51
+ });
52
+
53
+ record("0. baseline", async () => {
54
+ sid.manager = await h.login(MANAGER, PASSWORD);
55
+ sid.agency = await h.login(AGENCY, PASSWORD);
56
+ sid.staff = await h.login(STAFF, PASSWORD);
57
+ assert.equal((await site()).name, "OO Tower");
58
+ });
59
+
60
+ record("1. the provider cannot rename the client's site through its engagement row", async () => {
61
+ const res = await h.api(`/customer-sites/${id.served}`, {
62
+ method: "PUT",
63
+ sid: sid.agency,
64
+ body: {
65
+ name: "Renamed by provider",
66
+ address: { line1: "1 Fake St", city: "SG", postalCode: "000000", country: "Singapore" },
67
+ },
68
+ });
69
+ assert.equal(res.status, 403, JSON.stringify(res.body));
70
+ assert.equal(res.body?.message, REFUSAL);
71
+ assert.equal((await site()).name, "OO Tower", "site untouched");
72
+ const row = await h.db.collection("customer.sites").findOne({ _id: new ObjectId(id.served) });
73
+ assert.equal(row.name, "OO Tower", "row untouched");
74
+ });
75
+
76
+ record("2. nor rewrite its Site Information page", async () => {
77
+ const res = await h.api(`/sites/information/id/${id.site}`, {
78
+ method: "PATCH",
79
+ sid: sid.agency,
80
+ body: { description: "provider text" },
81
+ });
82
+ assert.equal(res.status, 403, JSON.stringify(res.body));
83
+ assert.equal(res.body?.message, REFUSAL);
84
+ assert.notEqual((await site()).siteInformation?.description, "provider text");
85
+ });
86
+
87
+ record("3. nor its address or timezone through PATCH /sites/id/:id", async () => {
88
+ for (const body of [
89
+ { address: { line1: "2 Fake St", city: "SG", postalCode: "000000", country: "Singapore" } },
90
+ { timezone: "Asia/Kuala_Lumpur" },
91
+ ]) {
92
+ const res = await h.api(`/sites/id/${id.site}`, { method: "PATCH", sid: sid.agency, body });
93
+ assert.equal(res.status, 403, JSON.stringify(res.body));
94
+ }
95
+ assert.equal((await site()).timezone, "Asia/Singapore");
96
+ });
97
+
98
+ record("4. CONTROL: the provider's operational settings on that route still save", async () => {
99
+ const res = await h.api(`/sites/id/${id.site}`, {
100
+ method: "PATCH",
101
+ sid: sid.agency,
102
+ body: { deliveryCompanyList: ["OO Courier"] },
103
+ });
104
+ assert.equal(res.status, 200, JSON.stringify(res.body));
105
+ assert.deepEqual((await site()).deliveryCompanyList, ["OO Courier"]);
106
+ });
107
+
108
+ record("5. the site read tells each side whether it may edit", async () => {
109
+ const provider = await h.api(`/sites/${id.site}`, { sid: sid.agency });
110
+ assert.equal(provider.status, 200, JSON.stringify(provider.body));
111
+ assert.equal(provider.body.detailsEditable, false);
112
+ assert.equal(provider.body.ownerOrgName, "OO Client");
113
+
114
+ const owner = await h.api(`/sites/${id.site}`, { sid: sid.manager });
115
+ assert.equal(owner.body.detailsEditable, true);
116
+ });
117
+
118
+ record("6. the owner CAN rename and re-address it", async () => {
119
+ const res = await h.api(`/customer-sites/${id.own}`, {
120
+ method: "PUT",
121
+ sid: sid.manager,
122
+ body: {
123
+ name: "OO Tower II",
124
+ address: { line1: "3 Real St", city: "SG", postalCode: "123456", country: "Singapore" },
125
+ },
126
+ });
127
+ assert.equal(res.status, 200, JSON.stringify(res.body));
128
+ assert.equal((await site()).name, "OO Tower II");
129
+ });
130
+
131
+ record("7. and edit its Site Information page and timezone", async () => {
132
+ const info = await h.api(`/sites/information/id/${id.site}`, {
133
+ method: "PATCH",
134
+ sid: sid.manager,
135
+ body: { description: "owner text" },
136
+ });
137
+ assert.equal(info.status, 200, JSON.stringify(info.body));
138
+ const tz = await h.api(`/sites/id/${id.site}`, {
139
+ method: "PATCH",
140
+ sid: sid.manager,
141
+ body: { timezone: "Asia/Kuala_Lumpur" },
142
+ });
143
+ assert.equal(tz.status, 200, JSON.stringify(tz.body));
144
+ assert.equal((await site()).timezone, "Asia/Kuala_Lumpur");
145
+ });
146
+
147
+ record("8. Seven365 Super Admin CAN edit it, even through the provider's row", async () => {
148
+ const res = await h.api(`/customer-sites/${id.served}`, {
149
+ method: "PUT",
150
+ sid: sid.staff,
151
+ body: { name: "OO Tower III" },
152
+ });
153
+ assert.equal(res.status, 200, JSON.stringify(res.body));
154
+ assert.equal((await site()).name, "OO Tower III");
155
+ const s = await h.api(`/sites/${id.site}`, { sid: sid.staff });
156
+ assert.equal(s.body.detailsEditable, true);
157
+ });
158
+
159
+ record("9. the provider CAN still remove the site from its own Sites list", async () => {
160
+ const res = await h.api(`/customer-sites/${id.served}`, { method: "DELETE", sid: sid.agency });
161
+ assert.equal(res.status, 200, JSON.stringify(res.body));
162
+ const row = await h.db.collection("customer.sites").findOne({ _id: new ObjectId(id.served) });
163
+ assert.equal(row.status, "deleted");
164
+ assert.equal((await site()).status, "active", "the client's site itself is untouched");
165
+ const own = await h.db.collection("customer.sites").findOne({ _id: new ObjectId(id.own) });
166
+ assert.equal(own.status, "active", "the client's own row is untouched");
167
+ });
168
+ });
169
+
170
+ async function seed(h) {
171
+ const now = new Date().toISOString();
172
+ const client = new ObjectId();
173
+ const agency = new ObjectId();
174
+ const site = new ObjectId();
175
+ const staffRole = new ObjectId();
176
+ const clientRole = new ObjectId();
177
+ const agencyRole = new ObjectId();
178
+
179
+ await h.db.collection("organizations").insertMany([
180
+ { _id: client, name: "OO Client", email: "oo-client@e2e.example.com", type: "org", nature: "property_management_agency", status: "active", createdAt: now, defaultSite: site.toString() },
181
+ { _id: agency, name: "OO Agency", email: "oo-agency-org@e2e.example.com", type: "org", nature: "security_agency", status: "active", createdAt: now },
182
+ ]);
183
+
184
+ await h.db.collection("sites").insertOne({
185
+ _id: site, name: "OO Tower", org: client, orgId: client, status: "active", timezone: "Asia/Singapore", createdAt: now,
186
+ });
187
+
188
+ const rows = await h.db.collection("customer.sites").insertMany([
189
+ { name: "OO Tower", org: agency, siteOrg: client, siteOrgName: "OO Client", site, status: "active", createdAt: now },
190
+ { name: "OO Tower", org: client, siteOrg: client, siteOrgName: "OO Client", site, status: "active", createdAt: now },
191
+ ]);
192
+
193
+ await h.db.collection("roles").insertMany([
194
+ { _id: staffRole, name: "Super Admin", type: "admin", default: true, permissions: [], status: "active" },
195
+ { _id: clientRole, name: "Owner", org: client, type: "organization", permissions: ["*"], status: "active" },
196
+ { _id: agencyRole, name: "Owner", org: agency, type: "organization", permissions: ["*"], status: "active" },
197
+ ]);
198
+
199
+ const emails = [MANAGER, AGENCY, STAFF];
200
+ const users = await h.db.collection("users").insertMany(
201
+ emails.map((email) => ({ email, name: email.split("@")[0], status: "active", createdAt: now })),
202
+ );
203
+ const hashed = await h.hashPassword(PASSWORD);
204
+ await h.db.collection("users").updateMany({ email: { $in: emails } }, { $set: { password: hashed } });
205
+ const [manager, agencyAdmin, staff] = [0, 1, 2].map((i) => users.insertedIds[i]);
206
+
207
+ await h.db.collection("members").insertMany([
208
+ { user: manager, org: client, type: "organization", role: clientRole, status: "active" },
209
+ // the provider's company-wide admin: no membership in the client at all
210
+ { user: agencyAdmin, org: agency, type: "organization", role: agencyRole, status: "active" },
211
+ { user: staff, type: "admin", role: staffRole, status: "active" },
212
+ ]);
213
+
214
+ return { site, served: rows.insertedIds[0].toString(), own: rows.insertedIds[1].toString() };
215
+ }
@@ -0,0 +1,41 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+
4
+ import { orgSearchMatch } from "./.build/utils/org-search.util.mjs";
5
+
6
+ const matches = (search, org) => {
7
+ const m = orgSearchMatch(search);
8
+ if (!m) return true;
9
+ return m.$or.some((clause) => {
10
+ const [field, { $regex, $options }] = Object.entries(clause)[0];
11
+ return new RegExp($regex, $options).test(org[field] ?? "");
12
+ });
13
+ };
14
+
15
+ const LAKE = { name: "The LakeGarden Residences", email: "ops@lakegarden.example.com" };
16
+
17
+ test("a blank or non-string term is no filter", () => {
18
+ for (const s of ["", " ", undefined, null, 42, ["x"]]) assert.equal(orgSearchMatch(s), null);
19
+ });
20
+
21
+ test("part of a name finds the client, in any case", () => {
22
+ assert.ok(matches("Lake", LAKE));
23
+ assert.ok(matches("lakegar", LAKE));
24
+ assert.ok(matches(" GARDEN res ", { name: "Garden Res" }));
25
+ });
26
+
27
+ test("the e-mail is searched too", () => {
28
+ assert.ok(matches("ops@lake", LAKE));
29
+ });
30
+
31
+ test("a term the client does not contain does not match", () => {
32
+ assert.equal(matches("Wing Tai", LAKE), false);
33
+ // $text ORed words: "The Estates" matched any org with "the". Substring does not.
34
+ assert.equal(matches("The Estates", LAKE), false);
35
+ });
36
+
37
+ test("regex characters are literal, not a pattern", () => {
38
+ assert.equal(matches(".*", LAKE), false);
39
+ assert.ok(matches("A.B (Pte)", { name: "A.B (Pte) Ltd" }));
40
+ assert.equal(matches("A.B", { name: "AxB Ltd" }), false);
41
+ });
@@ -202,7 +202,7 @@ test("the site read returns the EFFECTIVE set as a second field", () => {
202
202
  * indistinguishable from a failed save.
203
203
  */
204
204
  assert.match(SITE_CONTROLLER, /residentAppModulesEffective: effectiveResidentAppModules\(/);
205
- assert.match(SITE_CONTROLLER, /res\.json\(await withResidentAppCeiling\(site\)\)/);
205
+ assert.match(SITE_CONTROLLER, /res\.json\(await withResidentAppCeiling\(site(, detailsEditable)?\)\)/);
206
206
  // CONTROL: the saved field is still returned untouched alongside it.
207
207
  assert.match(SITE_CONTROLLER, /\.\.\.\(site\.metadata \?\? \{\}\)/);
208
208
  });
@@ -0,0 +1,52 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+
4
+ import {
5
+ mayEditSiteDetails,
6
+ siteOwnerOnlyMessage,
7
+ touchesSiteOwnerFields,
8
+ } from "./.build/utils/site-owner-edit.util.mjs";
9
+
10
+ // Owner decision 2026-09-25: only the owning client edits a site's details.
11
+ const OWNER = "6a0000000000000000000001";
12
+ const PROVIDER = "6a0000000000000000000002";
13
+
14
+ test("a member of the owning organisation may edit", () => {
15
+ assert.equal(mayEditSiteDetails({ staff: false, actorOrgIds: [OWNER], ownerOrg: OWNER }), true);
16
+ });
17
+
18
+ test("a provider that only serves the site may not", () => {
19
+ assert.equal(mayEditSiteDetails({ staff: false, actorOrgIds: [PROVIDER], ownerOrg: OWNER }), false);
20
+ });
21
+
22
+ test("Seven365 staff may", () => {
23
+ assert.equal(mayEditSiteDetails({ staff: true, actorOrgIds: [], ownerOrg: OWNER }), true);
24
+ });
25
+
26
+ test("an ObjectId-like owner compares by its string", () => {
27
+ const oid = { toString: () => OWNER };
28
+ assert.equal(mayEditSiteDetails({ staff: false, actorOrgIds: [OWNER], ownerOrg: oid }), true);
29
+ });
30
+
31
+ test("a site with no owner on record is staff-only", () => {
32
+ assert.equal(mayEditSiteDetails({ staff: false, actorOrgIds: [OWNER], ownerOrg: undefined }), false);
33
+ assert.equal(mayEditSiteDetails({ staff: false, actorOrgIds: [""], ownerOrg: "" }), false);
34
+ });
35
+
36
+ test("only address and timezone are owner fields on PATCH /sites/id/:id", () => {
37
+ assert.equal(touchesSiteOwnerFields({ address: { line1: "x" } }), true);
38
+ assert.equal(touchesSiteOwnerFields({ timezone: "Asia/Singapore" }), true);
39
+ assert.equal(touchesSiteOwnerFields({ deliveryCompanyList: [], metadata: { guardPosts: 2 } }), false);
40
+ assert.equal(touchesSiteOwnerFields(null), false);
41
+ });
42
+
43
+ test("the refusal names the owner, or says another organisation", () => {
44
+ assert.equal(
45
+ siteOwnerOnlyMessage("Management Pte Ltd"),
46
+ "This site belongs to Management Pte Ltd. Only they can change its details.",
47
+ );
48
+ assert.equal(
49
+ siteOwnerOnlyMessage(""),
50
+ "This site belongs to another organisation. Only they can change its details.",
51
+ );
52
+ });