@7365admin1/layer-common 4.97.0 → 4.97.1-staging.501
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/CHANGELOG.md +4 -4
- package/assets/css/primitives.css +57 -0
- package/assets/css/screens.css +8 -4
- package/components/AccessCardDetailsDialog.vue +59 -6
- package/components/AccessCardPreviewDialog.vue +371 -53
- package/components/AppSelect.vue +143 -4
- package/components/BuildingUnitFormEdit.vue +6 -0
- package/components/BuildingUnitManagement.vue +298 -0
- package/components/Dialog/UpdateMoreAction.vue +11 -1
- package/components/DocumentForm.vue +407 -112
- package/components/DocumentManagement.vue +213 -12
- package/components/Facility/BookingSetup.vue +63 -0
- package/components/HidAccessLogDashboard.vue +74 -17
- package/components/HidAccessPermissions.vue +532 -0
- package/components/HidIntercomManagement.vue +183 -14
- package/components/HidProfileQrCode.vue +332 -0
- package/components/HidQrCodeConfiguration.vue +17 -195
- package/components/HidReaderManagement.vue +398 -0
- package/components/HidReaderUserRoster.vue +44 -3
- package/components/HidUserEnrollment.vue +2242 -279
- package/components/InvitationClientForm.vue +19 -1
- package/components/Nfc/NFCPatrolRouteForm.vue +109 -58
- package/components/Nfc/NFCPatrolRouteMain.vue +3 -18
- package/components/Nfc/PatrolReport/PatrolActivityTable.vue +0 -8
- package/components/Nfc/PatrolReport/PatrolRouteSummary.vue +1 -1
- package/components/ServiceProviderMain.vue +48 -0
- package/components/SiteProviderChange.vue +371 -0
- package/components/TableMain.vue +22 -7
- package/components/VisitorForm.vue +12 -0
- package/components/VisitorManagement.vue +267 -5
- package/composables/useAccessManagement.ts +17 -1
- package/composables/useCustomerSite.ts +29 -0
- package/composables/useDocument.ts +7 -0
- package/composables/useFacility.ts +11 -0
- package/composables/useHidAmico.ts +165 -0
- package/composables/useHidNavigation.ts +25 -1
- package/composables/useHidReaderSelection.ts +50 -0
- package/composables/useMember.ts +12 -0
- package/composables/useNFCPatrolReport.ts +36 -32
- package/composables/useNFCPatrolReportFilters.ts +21 -3
- package/composables/useNFCPatrolRoute.ts +10 -3
- package/composables/usePeople.ts +19 -0
- package/composables/useServiceProvider.ts +45 -2
- package/composables/useSiteCategory.ts +45 -0
- package/package.json +1 -1
- package/pages/[org]/[site]/access-mgmt/administrator/index.vue +1 -1
- package/pages/[org]/[site]/access-mgmt/hid-cards/index.vue +1 -1
- package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +23 -0
- package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
- package/types/document.d.ts +14 -0
- package/types/facility.d.ts +4 -0
- package/types/member.d.ts +4 -0
- package/types/nfc-patrol-report.ts +0 -2
- package/types/people.d.ts +28 -1
- package/types/service-provider.d.ts +5 -0
- package/types/site.d.ts +7 -1
- package/utils/hid-enrolment-subject.ts +366 -0
- package/utils/hid-permission-assignments.ts +259 -0
- package/utils/hid-reader-selection.ts +52 -0
- package/utils/nfc-patrol-time.ts +99 -0
- package/utils/occupancy-role.ts +109 -0
- package/utils/service-type.ts +30 -0
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WHO A HID ENROLMENT IS FOR — the pure decisions behind the subject picker.
|
|
3
|
+
*
|
|
4
|
+
* `HidUserEnrollment.vue` can enrol a resident or a staff member. The write path
|
|
5
|
+
* always carried both (`subjectLink` maps them onto `person` or `member`); what
|
|
6
|
+
* was missing was a way to choose. These are the parts of that choice worth
|
|
7
|
+
* testing on their own, kept here because a `.vue` component has no test harness
|
|
8
|
+
* in this repo.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* What the ENROLLING dropdown offers. Three of these four are the server's own
|
|
13
|
+
* permission categories; `service_provider_staff` is this screen's own value
|
|
14
|
+
* and deliberately not one of them - see `subjectLinkOf`.
|
|
15
|
+
*/
|
|
16
|
+
export type HidEnrolmentSubject =
|
|
17
|
+
| "resident"
|
|
18
|
+
| "property_management"
|
|
19
|
+
| "service_provider_staff";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The dropdown's options, in the order they are drawn.
|
|
23
|
+
*
|
|
24
|
+
* `title`/`value` because `AppSelect` takes that shape.
|
|
25
|
+
*/
|
|
26
|
+
export const HID_ENROLMENT_SUBJECTS: ReadonlyArray<{
|
|
27
|
+
title: string;
|
|
28
|
+
value: HidEnrolmentSubject;
|
|
29
|
+
}> = [
|
|
30
|
+
{ title: "Resident", value: "resident" },
|
|
31
|
+
{ title: "Member", value: "property_management" },
|
|
32
|
+
{ title: "Service provider", value: "service_provider_staff" },
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* What an EDIT calls the subject it is already attached to.
|
|
37
|
+
*
|
|
38
|
+
* Wider than the dropdown on purpose. An identity's category cannot change after
|
|
39
|
+
* it is created, so an edit states it rather than offering it — and the records
|
|
40
|
+
* in the wild include `service_provider`, which the dropdown does not offer yet
|
|
41
|
+
* but `openEdit` does resolve. Falling back to the first option would label a
|
|
42
|
+
* contractor "Resident", which is worse than saying nothing useful.
|
|
43
|
+
*/
|
|
44
|
+
export function subjectCategoryLabel(category: unknown): string {
|
|
45
|
+
const labels: Record<string, string> = {
|
|
46
|
+
resident: "Resident",
|
|
47
|
+
property_management: "Member",
|
|
48
|
+
// The dropdown's own value: ONE PERSON from a provider company.
|
|
49
|
+
service_provider_staff: "Service provider",
|
|
50
|
+
// The server's category, which names a COMPANY. Records in the wild carry
|
|
51
|
+
// it, and an edit must not call such a row a resident.
|
|
52
|
+
service_provider: "Service provider",
|
|
53
|
+
visitor: "Visitor",
|
|
54
|
+
};
|
|
55
|
+
return labels[String(category ?? "")] ?? "Unknown";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* One page of `GET /api/members`, read defensively.
|
|
60
|
+
*
|
|
61
|
+
* `paginate` puts `{ items, pages }` at the root, but `items` sits under `data`
|
|
62
|
+
* on some of this product's endpoints, so both are read — the same allowance
|
|
63
|
+
* `readCandidatePage` makes. A response that carries neither is an empty page
|
|
64
|
+
* rather than a thrown error: an empty staff picker with a placeholder beats a
|
|
65
|
+
* broken dialog.
|
|
66
|
+
*/
|
|
67
|
+
export function readMemberPage(response: unknown): {
|
|
68
|
+
items: Record<string, unknown>[];
|
|
69
|
+
pages: number;
|
|
70
|
+
total: number;
|
|
71
|
+
} {
|
|
72
|
+
const source = (response && typeof response === "object" ? response : {}) as Record<string, unknown>;
|
|
73
|
+
const nested = (source.data && typeof source.data === "object" ? source.data : {}) as Record<string, unknown>;
|
|
74
|
+
const raw = Array.isArray(source.items)
|
|
75
|
+
? source.items
|
|
76
|
+
: Array.isArray(nested.items)
|
|
77
|
+
? nested.items
|
|
78
|
+
: [];
|
|
79
|
+
const pages = Number(source.pages ?? nested.pages ?? 1);
|
|
80
|
+
const items = raw.filter((row): row is Record<string, unknown> => Boolean(row) && typeof row === "object");
|
|
81
|
+
/*
|
|
82
|
+
* `total` drives "showing 10 of 23" and the Load more button. It falls back to
|
|
83
|
+
* the page's own length, not to zero, so a response without it simply reads as
|
|
84
|
+
* "this is everything" — a missing count must never make the button offer a
|
|
85
|
+
* page that is not there.
|
|
86
|
+
*/
|
|
87
|
+
const total = Number(source.total ?? nested.total ?? items.length);
|
|
88
|
+
return {
|
|
89
|
+
items,
|
|
90
|
+
pages: Number.isFinite(pages) && pages > 0 ? Math.floor(pages) : 1,
|
|
91
|
+
total: Number.isFinite(total) && total >= 0 ? Math.floor(total) : items.length,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Can this member actually be enrolled?
|
|
97
|
+
*
|
|
98
|
+
* Reader access is bound by USER id — `resolvePermissionUserBindings` in
|
|
99
|
+
* `iservice365-core` drops every subject without one — so a member with no app
|
|
100
|
+
* account cannot be given access and is not a candidate. The id arrives as a
|
|
101
|
+
* string from JSON but may be an object if a caller passes a raw document, so
|
|
102
|
+
* both are read rather than trusting the shape.
|
|
103
|
+
*/
|
|
104
|
+
export function memberHasAccount(row: Record<string, unknown> | null | undefined): boolean {
|
|
105
|
+
const user = row?.user;
|
|
106
|
+
if (!user) return false;
|
|
107
|
+
if (typeof user === "object") {
|
|
108
|
+
const id = (user as { _id?: unknown; toString?: () => string })._id ?? user;
|
|
109
|
+
return Boolean(String(id ?? "").trim());
|
|
110
|
+
}
|
|
111
|
+
return Boolean(String(user).trim());
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* How a member reads in the picker: their name, and their role beneath it.
|
|
116
|
+
*
|
|
117
|
+
* THE ACCOUNT'S NAME FIRST, then the membership's. The two diverge — a
|
|
118
|
+
* membership is created with whatever name was typed at invite time, and the
|
|
119
|
+
* person may have set their own on the account since — and the account name is
|
|
120
|
+
* the one they are known by. `userName` comes from the members endpoint's own
|
|
121
|
+
* lookup into `users`; a member with no account has none, but such a row is not
|
|
122
|
+
* a candidate anyway (`memberHasAccount`).
|
|
123
|
+
*
|
|
124
|
+
* Every step falls back, because a row with no name at all still has to be
|
|
125
|
+
* selectable rather than blank, or it cannot be told apart from the next one.
|
|
126
|
+
*/
|
|
127
|
+
export function memberCandidateOf(row: Record<string, unknown>): {
|
|
128
|
+
subjectId: string;
|
|
129
|
+
name: string;
|
|
130
|
+
subtitle: string;
|
|
131
|
+
} {
|
|
132
|
+
const text = (value: unknown) => String(value ?? "").trim();
|
|
133
|
+
return {
|
|
134
|
+
subjectId: text(row._id),
|
|
135
|
+
name: text(row.userName) || text(row.name) || text(row.email) || "Member",
|
|
136
|
+
subtitle: text(row.roleName) || text(row.email) || "",
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Why somebody the operator can see elsewhere is not in this list.
|
|
142
|
+
*
|
|
143
|
+
* Left unexplained, an absence reads as a broken screen — the same reason the
|
|
144
|
+
* resident cascade carries `unitResidentNote`. Returns "" when there is nothing
|
|
145
|
+
* to say, so the caller can render it unconditionally.
|
|
146
|
+
*/
|
|
147
|
+
export function hiddenSubjectNote(count: number, noun: "resident" | "member"): string {
|
|
148
|
+
if (!Number.isFinite(count) || count <= 0) return "";
|
|
149
|
+
const whole = Math.floor(count);
|
|
150
|
+
const subject = whole === 1 ? `1 ${noun}` : `${whole} ${noun}s`;
|
|
151
|
+
const verb = whole === 1 ? "is" : "are";
|
|
152
|
+
const holder = whole === 1 ? "that person has" : "they have";
|
|
153
|
+
return `${subject} at this site ${verb} not listed:`
|
|
154
|
+
+ ` HID enrollment needs an app account, and ${holder} none yet.`;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/* ── THE LINK THAT REACHES THE DEVICE ──────────────────────────────────── */
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* WHICH SUBJECT FIELD AN ENROLMENT WRITES, and what the identity is called.
|
|
161
|
+
*
|
|
162
|
+
* This is the one decision in the dialog that changes who a door lets in, so it
|
|
163
|
+
* lives here with tests rather than inline in the template's script.
|
|
164
|
+
*
|
|
165
|
+
* `service_provider_staff` links through `member`, NOT `serviceProvider`, and
|
|
166
|
+
* that is the whole design:
|
|
167
|
+
*
|
|
168
|
+
* - `serviceProvider` names a `site.service-providers` row, which is a COMPANY.
|
|
169
|
+
* `resolvePermissionUserBindings` expands one into every active member of
|
|
170
|
+
* that organisation with NO site filter, so granting it puts a 200-person
|
|
171
|
+
* firm on a door that eight of them attend.
|
|
172
|
+
* - A provider employee's membership lives in `members` with `siteId` set to
|
|
173
|
+
* this site - `members` carries a unique index on `{org, siteId, user, type}`,
|
|
174
|
+
* so it cannot exist there without one. That makes the person site-scoped by
|
|
175
|
+
* construction, which is the whole point.
|
|
176
|
+
*
|
|
177
|
+
* The identity `type` is `"contractor"` rather than `"staff"`, and it is load
|
|
178
|
+
* bearing on the server as well as here: core's `permissionSubjectOfIdentity`
|
|
179
|
+
* reads it to tell a contractor's `member` link from a property-management one,
|
|
180
|
+
* and files the grant under `service_provider_member` or `property_management`
|
|
181
|
+
* accordingly. It is also what the Access Permissions tabs filter on.
|
|
182
|
+
*
|
|
183
|
+
* An earlier version filed provider staff under `property_management`, since that
|
|
184
|
+
* category's subject list already accepts these rows. It worked for access and
|
|
185
|
+
* failed for identity: `permissionIdentityType` derives the identity's type from
|
|
186
|
+
* the category, so every contractor came back as `staff` - and because the
|
|
187
|
+
* reconcile rewrites the identity it finds, the `"contractor"` written here was
|
|
188
|
+
* overwritten seconds later.
|
|
189
|
+
*
|
|
190
|
+
* An empty `subjectId` returns `{}` ON PURPOSE. Sending `person: ""` is not
|
|
191
|
+
* "leave this alone", it is "clear it": the server reads an empty string as the
|
|
192
|
+
* link being removed and then refuses the write for having no subject at all.
|
|
193
|
+
*/
|
|
194
|
+
export function subjectLinkOf(
|
|
195
|
+
category: unknown,
|
|
196
|
+
subjectId: unknown,
|
|
197
|
+
): {
|
|
198
|
+
person?: string;
|
|
199
|
+
member?: string;
|
|
200
|
+
serviceProvider?: string;
|
|
201
|
+
type?: "resident" | "staff" | "contractor";
|
|
202
|
+
} {
|
|
203
|
+
const id = String(subjectId ?? "").trim();
|
|
204
|
+
if (!id) return {};
|
|
205
|
+
const of = (
|
|
206
|
+
field: "person" | "member" | "serviceProvider",
|
|
207
|
+
type: "resident" | "staff" | "contractor",
|
|
208
|
+
) => ({
|
|
209
|
+
person: field === "person" ? id : "",
|
|
210
|
+
member: field === "member" ? id : "",
|
|
211
|
+
serviceProvider: field === "serviceProvider" ? id : "",
|
|
212
|
+
type,
|
|
213
|
+
});
|
|
214
|
+
switch (String(category ?? "")) {
|
|
215
|
+
case "resident":
|
|
216
|
+
return of("person", "resident");
|
|
217
|
+
case "service_provider_staff":
|
|
218
|
+
return of("member", "contractor");
|
|
219
|
+
case "service_provider":
|
|
220
|
+
return of("serviceProvider", "contractor");
|
|
221
|
+
default:
|
|
222
|
+
return of("member", "staff");
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Which PERMISSION CATEGORY an enrolment's access grant is stored under.
|
|
228
|
+
*
|
|
229
|
+
* Mirrors `permissionSubjectOfIdentity` in core, which reads the stored links
|
|
230
|
+
* rather than this dropdown: a `member` link resolves to `property_management`
|
|
231
|
+
* whatever the identity's `type` says. Provider staff therefore share the staff
|
|
232
|
+
* category, which is correct - they are validated against the same subject list
|
|
233
|
+
* - and the identity `type` is what tells them apart on screen.
|
|
234
|
+
*/
|
|
235
|
+
export function permissionCategoryOf(category: unknown): string {
|
|
236
|
+
const value = String(category ?? "");
|
|
237
|
+
if (value === "resident") return "resident";
|
|
238
|
+
if (value === "service_provider") return "service_provider";
|
|
239
|
+
if (value === "service_provider_staff") return "service_provider_member";
|
|
240
|
+
return "property_management";
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* The dropdown value for a grant's category — the inverse of
|
|
245
|
+
* `permissionCategoryOf`.
|
|
246
|
+
*
|
|
247
|
+
* An edit STATES the subject type rather than offering it, because an identity's
|
|
248
|
+
* category cannot change after it is created. This is how a stored record is
|
|
249
|
+
* turned back into the value the form holds, and it is wider than the dropdown on
|
|
250
|
+
* purpose: records in the wild carry `service_provider`, which names a COMPANY
|
|
251
|
+
* and which the dropdown does not offer.
|
|
252
|
+
*
|
|
253
|
+
* Paired with `subjectOfIdentity` so the mapping lives in one place. `openEdit`
|
|
254
|
+
* used to repeat the whole links-and-type ternary inline, which is how the copy
|
|
255
|
+
* in `HidAccessPermissions.vue` was able to go stale without anything noticing.
|
|
256
|
+
*/
|
|
257
|
+
export function enrolmentSubjectOfCategory(category: unknown): string {
|
|
258
|
+
const value = String(category ?? "");
|
|
259
|
+
if (value === "resident") return "resident";
|
|
260
|
+
if (value === "service_provider_member") return "service_provider_staff";
|
|
261
|
+
if (value === "service_provider") return "service_provider";
|
|
262
|
+
return "property_management";
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/* ── PROVIDER STAFF AS PICKER ROWS ─────────────────────────────────────── */
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Can this provider employee be enrolled?
|
|
269
|
+
*
|
|
270
|
+
* Two conditions, and both have to be checked here rather than trusted from the
|
|
271
|
+
* list. An app account, because reader access is bound by user id
|
|
272
|
+
* (`memberHasAccount`). And an ACTIVE membership: `getProviderMembersBySite`
|
|
273
|
+
* returns everyone who is not deleted, so a suspended person is in the list the
|
|
274
|
+
* Members screen draws - marked, deliberately, so the property manager can see
|
|
275
|
+
* them. Offering a suspended person a door is a different matter.
|
|
276
|
+
*/
|
|
277
|
+
export function providerCanEnrol(
|
|
278
|
+
row: Record<string, unknown> | null | undefined,
|
|
279
|
+
): boolean {
|
|
280
|
+
if (!memberHasAccount(row)) return false;
|
|
281
|
+
return String(row?.status ?? "").trim() === "active";
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* How a provider employee reads in the picker: their name, their company and
|
|
286
|
+
* the service beneath it.
|
|
287
|
+
*
|
|
288
|
+
* The company comes FIRST in the subtitle. Two contractors with the same first
|
|
289
|
+
* name are common, and which firm somebody belongs to is what the property
|
|
290
|
+
* manager actually recognises them by - the service type alone ("Security")
|
|
291
|
+
* describes half the list.
|
|
292
|
+
*/
|
|
293
|
+
export function providerCandidateOf(row: Record<string, unknown>): {
|
|
294
|
+
subjectId: string;
|
|
295
|
+
name: string;
|
|
296
|
+
subtitle: string;
|
|
297
|
+
} {
|
|
298
|
+
const text = (value: unknown) => String(value ?? "").trim();
|
|
299
|
+
const parts = [text(row.company), text(row.typeLabel)].filter(Boolean);
|
|
300
|
+
return {
|
|
301
|
+
subjectId: text(row._id),
|
|
302
|
+
name: text(row.name) || text(row.email) || "Service provider",
|
|
303
|
+
subtitle: parts.join(" · ") || text(row.role) || text(row.email) || "",
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Does this list tell us who has an app account?
|
|
309
|
+
*
|
|
310
|
+
* `GET /api/service-providers/site-members` only began returning `user` in core
|
|
311
|
+
* 3.130; before that the service layer dropped it even though the repository
|
|
312
|
+
* projected it. Frontend and backend deploy separately, so this screen can run
|
|
313
|
+
* against either. Asked of the ROWS rather than of a version number: the key is
|
|
314
|
+
* present on every row or on none.
|
|
315
|
+
*
|
|
316
|
+
* It matters because the answer flips a filter from "cannot be bound to a door"
|
|
317
|
+
* to "unknown", and a screen that silently reports NOBODY can be enrolled is
|
|
318
|
+
* worse than one that offers somebody the server then refuses by name.
|
|
319
|
+
*/
|
|
320
|
+
export function providerAccountsKnown(
|
|
321
|
+
rows: ReadonlyArray<Record<string, unknown>>,
|
|
322
|
+
): boolean {
|
|
323
|
+
return rows.some((row) => Boolean(row) && typeof row === "object" && "user" in row);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Who may be offered a door, from whatever the endpoint returned.
|
|
328
|
+
*
|
|
329
|
+
* With accounts known, both conditions apply (`providerCanEnrol`). Without them,
|
|
330
|
+
* active membership is all that can be checked here — the server still refuses
|
|
331
|
+
* anyone it cannot bind, with a message naming them, which is a better failure
|
|
332
|
+
* than an empty picker.
|
|
333
|
+
*/
|
|
334
|
+
export function providerEnrollableRows<T extends Record<string, unknown>>(
|
|
335
|
+
rows: ReadonlyArray<T>,
|
|
336
|
+
): T[] {
|
|
337
|
+
const known = providerAccountsKnown(rows);
|
|
338
|
+
return rows.filter((row) =>
|
|
339
|
+
known ? providerCanEnrol(row) : String(row?.status ?? "").trim() === "active",
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/* ── THE SERVICE FILTER'S "ALL" ────────────────────────────────────────── */
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* WHY "ALL SERVICES" CANNOT BE THE EMPTY STRING HERE.
|
|
347
|
+
*
|
|
348
|
+
* `filterProviderMembers` reads an empty `type` as "do not filter", and the
|
|
349
|
+
* Members screen's own filter uses `value: ""` for All services - but that screen
|
|
350
|
+
* draws a Vuetify `v-select`, which renders an empty value perfectly well.
|
|
351
|
+
*
|
|
352
|
+
* `AppSelect` does not. Its `hasSingleValue` is false for `""`, so the field
|
|
353
|
+
* falls back to the placeholder, draws in the placeholder's grey, and the option
|
|
354
|
+
* is never marked as the chosen one in the menu. The filter worked; it just
|
|
355
|
+
* looked like nothing was selected and like only the real services existed.
|
|
356
|
+
*
|
|
357
|
+
* So the option carries a real value here and is translated on the way to the
|
|
358
|
+
* filter. Changing `AppSelect` instead would touch every one of its callers.
|
|
359
|
+
*/
|
|
360
|
+
export const HID_ALL_SERVICES = "all";
|
|
361
|
+
|
|
362
|
+
/** The `type` to filter by: "" for All services, the service code otherwise. */
|
|
363
|
+
export function serviceFilterOf(selected: unknown): string {
|
|
364
|
+
const value = String(selected ?? "").trim();
|
|
365
|
+
return value === HID_ALL_SERVICES ? "" : value;
|
|
366
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WHO IS ASSIGNED TO A HID READER — the editing model behind the permissions
|
|
3
|
+
* dialog.
|
|
4
|
+
*
|
|
5
|
+
* This is the step that actually grants access. Enrolling a person gives the
|
|
6
|
+
* reader a face, a card or a PIN it can RECOGNISE; it puts nobody in the group
|
|
7
|
+
* the access rule is attached to, so a recognised person is still refused at
|
|
8
|
+
* the door (access log event 6). `PUT /sites/:siteId/permissions` is the only
|
|
9
|
+
* call in the system that writes that group membership.
|
|
10
|
+
*
|
|
11
|
+
* Two contracts make this file necessary rather than inlining the logic in the
|
|
12
|
+
* component:
|
|
13
|
+
*
|
|
14
|
+
* 1. **The PUT REPLACES the whole assignment set for the reader.** The server
|
|
15
|
+
* keeps other readers' rows and overwrites this reader's with exactly what
|
|
16
|
+
* is sent. The candidate list, however, is fetched ONE CATEGORY AT A TIME.
|
|
17
|
+
* Saving from the tab in front of you while sending only that tab's people
|
|
18
|
+
* would silently revoke every resident if you were looking at the service
|
|
19
|
+
* providers tab. So the edit state is held for the whole reader and the
|
|
20
|
+
* payload is always built from all of it.
|
|
21
|
+
*
|
|
22
|
+
* 2. **The body schema accepts three keys and nothing else.**
|
|
23
|
+
* `hidPermissionAssignmentSchema` is `{ subjectId, category, intercom }`,
|
|
24
|
+
* and Joi rejects unknown keys rather than stripping them. The candidate
|
|
25
|
+
* rows carry `name`, `subtitle`, `location` and friends for display, so the
|
|
26
|
+
* payload has to be narrowed deliberately — passing a candidate straight
|
|
27
|
+
* through is a 400.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The real categories. `intercom` is a candidate FILTER, never a category.
|
|
32
|
+
*
|
|
33
|
+
* Mirrors `HID_PERMISSION_CATEGORIES` in core, and has to: `seedAssignments`
|
|
34
|
+
* DROPS a row whose category is not in this list, so a category missing here
|
|
35
|
+
* silently loses that grant from the edit state - and the save that follows,
|
|
36
|
+
* being a whole-reader replace, would revoke it.
|
|
37
|
+
*/
|
|
38
|
+
export const HID_PERMISSION_CATEGORIES: THidPermissionCategory[] = [
|
|
39
|
+
"resident",
|
|
40
|
+
"property_management",
|
|
41
|
+
"service_provider",
|
|
42
|
+
"service_provider_member",
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
export type HidAssignmentState = Map<string, { category: THidPermissionCategory; intercom: boolean }>;
|
|
46
|
+
|
|
47
|
+
/** Body row for `updateSitePermissions` — exactly the keys Joi allows. */
|
|
48
|
+
export type HidAssignmentPayload = {
|
|
49
|
+
subjectId: string;
|
|
50
|
+
category: THidPermissionCategory;
|
|
51
|
+
intercom: boolean;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
function isRealCategory(value: unknown): value is THidPermissionCategory {
|
|
55
|
+
return HID_PERMISSION_CATEGORIES.includes(value as THidPermissionCategory);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The reader's CURRENT assignments, as the edit state.
|
|
60
|
+
*
|
|
61
|
+
* Seeded from `getSitePermissions`, which returns every category at once —
|
|
62
|
+
* that is what makes a whole-reader payload possible from a one-category view.
|
|
63
|
+
* Rows with an unrecognised category are dropped rather than carried: sending
|
|
64
|
+
* one back fails the enum check and takes the entire save with it.
|
|
65
|
+
*/
|
|
66
|
+
export function seedAssignments(
|
|
67
|
+
assignments: readonly THidPermissionAssignment[] | undefined | null,
|
|
68
|
+
): HidAssignmentState {
|
|
69
|
+
const state: HidAssignmentState = new Map();
|
|
70
|
+
if (!Array.isArray(assignments)) return state;
|
|
71
|
+
for (const assignment of assignments) {
|
|
72
|
+
const subjectId = String(assignment?.subjectId ?? "");
|
|
73
|
+
if (!subjectId || !isRealCategory(assignment?.category)) continue;
|
|
74
|
+
state.set(subjectId, {
|
|
75
|
+
category: assignment.category,
|
|
76
|
+
intercom: assignment.intercom === true,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return state;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Add or remove one person.
|
|
84
|
+
*
|
|
85
|
+
* `saved` is the state the dialog opened with, and it is consulted for one
|
|
86
|
+
* reason: the `intercom` flag. Nothing here edits that flag, but
|
|
87
|
+
* `userHasSiteIntercomPermission` reads it off these same rows, so it must
|
|
88
|
+
* survive a round trip through the checkbox.
|
|
89
|
+
*
|
|
90
|
+
* - **Untick then save** drops it, which is right — an unassigned person
|
|
91
|
+
* holding a dangling intercom right would keep answering the door panel
|
|
92
|
+
* after losing the door.
|
|
93
|
+
* - **Untick then re-tick, without saving** must restore it. Removing from the
|
|
94
|
+
* draft forgets the flag, so re-adding recovers it from `saved`; otherwise a
|
|
95
|
+
* misclick corrected a second later would silently revoke intercom on the
|
|
96
|
+
* next save, with nothing on screen to show it had happened.
|
|
97
|
+
*/
|
|
98
|
+
export function setAssignment(
|
|
99
|
+
state: HidAssignmentState,
|
|
100
|
+
saved: HidAssignmentState,
|
|
101
|
+
subjectId: string,
|
|
102
|
+
category: THidPermissionCategory,
|
|
103
|
+
selected: boolean,
|
|
104
|
+
): HidAssignmentState {
|
|
105
|
+
const next: HidAssignmentState = new Map(state);
|
|
106
|
+
const id = String(subjectId ?? "");
|
|
107
|
+
if (!id || !isRealCategory(category)) return next;
|
|
108
|
+
if (!selected) {
|
|
109
|
+
next.delete(id);
|
|
110
|
+
return next;
|
|
111
|
+
}
|
|
112
|
+
const intercom = next.get(id)?.intercom ?? saved.get(id)?.intercom ?? false;
|
|
113
|
+
next.set(id, { category, intercom: intercom === true });
|
|
114
|
+
return next;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** The whole reader's assignments, narrowed to the three keys the API accepts. */
|
|
118
|
+
export function toAssignmentPayload(state: HidAssignmentState): HidAssignmentPayload[] {
|
|
119
|
+
return [...state.entries()].map(([subjectId, value]) => ({
|
|
120
|
+
subjectId,
|
|
121
|
+
category: value.category,
|
|
122
|
+
intercom: value.intercom === true,
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* The server sends `selected` with each candidate, describing what is SAVED.
|
|
128
|
+
* Once the dialog is open the local edit state is the truth, so the flag is
|
|
129
|
+
* recomputed rather than trusted — otherwise paging or searching would redraw
|
|
130
|
+
* a row with the saved value and quietly discard an unsaved tick.
|
|
131
|
+
*/
|
|
132
|
+
export function applySelection(
|
|
133
|
+
candidates: readonly THidPermissionCandidate[] | undefined | null,
|
|
134
|
+
state: HidAssignmentState,
|
|
135
|
+
): THidPermissionCandidate[] {
|
|
136
|
+
if (!Array.isArray(candidates)) return [];
|
|
137
|
+
return candidates.map((candidate) => ({
|
|
138
|
+
...candidate,
|
|
139
|
+
selected: state.has(String(candidate?.subjectId ?? "")),
|
|
140
|
+
}));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Per-category totals for the dialog header, counted over the whole reader. */
|
|
144
|
+
export function countByCategory(state: HidAssignmentState): Record<THidPermissionCategory, number> {
|
|
145
|
+
/*
|
|
146
|
+
* Every category seeded at zero, and the increment guarded.
|
|
147
|
+
* `counts[category] += 1` on a key this object does not hold yields NaN, so a
|
|
148
|
+
* category added to the union but missed here would print "NaN" beside a tab
|
|
149
|
+
* rather than a number. That is exactly what happened when
|
|
150
|
+
* `service_provider_member` was added.
|
|
151
|
+
*/
|
|
152
|
+
const counts = HID_PERMISSION_CATEGORIES.reduce(
|
|
153
|
+
(seeded, category) => ({ ...seeded, [category]: 0 }),
|
|
154
|
+
{} as Record<THidPermissionCategory, number>,
|
|
155
|
+
);
|
|
156
|
+
for (const value of state.values()) {
|
|
157
|
+
counts[value.category] = (counts[value.category] ?? 0) + 1;
|
|
158
|
+
}
|
|
159
|
+
return counts;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Has anything changed since the dialog opened? Drives the Save button. */
|
|
163
|
+
export function hasChanges(saved: HidAssignmentState, draft: HidAssignmentState): boolean {
|
|
164
|
+
if (saved.size !== draft.size) return true;
|
|
165
|
+
for (const [subjectId, value] of draft) {
|
|
166
|
+
const before = saved.get(subjectId);
|
|
167
|
+
if (!before) return true;
|
|
168
|
+
if (before.category !== value.category) return true;
|
|
169
|
+
if (before.intercom !== value.intercom) return true;
|
|
170
|
+
}
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* What a listing response tells us: the rows, and how many pages exist.
|
|
176
|
+
*
|
|
177
|
+
* It deliberately does NOT return the current page, and the caller must keep
|
|
178
|
+
* owning that. `paginate` in `@7365admin1/node-server-utils` returns only
|
|
179
|
+
* `{ items, pages, pageRange }` — it never echoes the page it was asked for. A
|
|
180
|
+
* caller that read one back therefore got a default on every fetch and pinned
|
|
181
|
+
* itself to page one, so the pager moved and the rows never did.
|
|
182
|
+
*
|
|
183
|
+
* `items` sits at the root on some of these endpoints and under `data` on
|
|
184
|
+
* others, so both are read.
|
|
185
|
+
*/
|
|
186
|
+
export function readCandidatePage(response: unknown): {
|
|
187
|
+
items: THidPermissionCandidate[];
|
|
188
|
+
pages: number;
|
|
189
|
+
pageRange: string;
|
|
190
|
+
} {
|
|
191
|
+
const source = (response && typeof response === "object" ? response : {}) as Record<string, unknown>;
|
|
192
|
+
const nested = (source.data && typeof source.data === "object" ? source.data : {}) as Record<string, unknown>;
|
|
193
|
+
const items = Array.isArray(source.items)
|
|
194
|
+
? source.items
|
|
195
|
+
: Array.isArray(nested.items)
|
|
196
|
+
? nested.items
|
|
197
|
+
: [];
|
|
198
|
+
const pages = Number(source.pages ?? nested.pages ?? 1);
|
|
199
|
+
// `paginate` builds this ("1-10 of 37") and the table renders it verbatim.
|
|
200
|
+
// Without it the pager draws its placeholder, "-- - -- of --".
|
|
201
|
+
const pageRange = String(source.pageRange ?? nested.pageRange ?? "");
|
|
202
|
+
return {
|
|
203
|
+
items: items as THidPermissionCandidate[],
|
|
204
|
+
pages: Number.isFinite(pages) && pages > 0 ? pages : 1,
|
|
205
|
+
pageRange,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/* ── THE SUBJECT AN IDENTITY NAMES ─────────────────────────────────────── */
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* WHICH GRANT AN ENROLLED PERSON'S ACCESS IS FILED UNDER.
|
|
213
|
+
*
|
|
214
|
+
* Mirrors `permissionSubjectOfIdentity` in core, which is the authority. This
|
|
215
|
+
* repository cannot import it - layer-common does not depend on the core
|
|
216
|
+
* package - so there is a copy, and the point of putting it HERE is that there
|
|
217
|
+
* is only one.
|
|
218
|
+
*
|
|
219
|
+
* There used to be two: a local `subjectOf` in `HidAccessPermissions.vue` and
|
|
220
|
+
* the same ternary inline in `HidUserEnrollment.vue`. The first was stale. It
|
|
221
|
+
* read every `member` link as `property_management`, so granting a contractor
|
|
222
|
+
* from the permissions screen wrote a staff assignment - and the reconcile then
|
|
223
|
+
* derived `staff` from that category and rewrote the identity's `type`, moving
|
|
224
|
+
* the person out of the service-provider tab and into the member one. The
|
|
225
|
+
* screen for managing contractors reclassified them by being used.
|
|
226
|
+
*
|
|
227
|
+
* A `member` link is how BOTH a property-management member and a service
|
|
228
|
+
* provider's own employee are stored - the person's membership at this site -
|
|
229
|
+
* so the identity's `type` is the discriminator. `"contractor"` is written by
|
|
230
|
+
* the enrolment form and re-confirmed by `permissionIdentityType` on every
|
|
231
|
+
* reconcile, so the two agree instead of one overwriting the other.
|
|
232
|
+
*
|
|
233
|
+
* Returns null for a visitor and for an identity linked to nobody. Visitor
|
|
234
|
+
* access comes from `user_access_rules` rather than a group, so there is nothing
|
|
235
|
+
* to switch; an identity holding only an account link names no subject to
|
|
236
|
+
* assign. Both are still DRAWN by the permissions screen, disabled, with a
|
|
237
|
+
* reason - dropping them silently is what once made the pager say "1-9 of 9"
|
|
238
|
+
* over seven rows.
|
|
239
|
+
*/
|
|
240
|
+
export function subjectOfIdentity(
|
|
241
|
+
identity: Record<string, unknown> | null | undefined,
|
|
242
|
+
): { subjectId: string; category: THidPermissionCategory } | null {
|
|
243
|
+
if (!identity) return null;
|
|
244
|
+
if (identity.person) {
|
|
245
|
+
return { subjectId: String(identity.person), category: "resident" };
|
|
246
|
+
}
|
|
247
|
+
if (identity.member) {
|
|
248
|
+
return {
|
|
249
|
+
subjectId: String(identity.member),
|
|
250
|
+
category: String(identity.type ?? "") === "contractor"
|
|
251
|
+
? "service_provider_member"
|
|
252
|
+
: "property_management",
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
if (identity.serviceProvider) {
|
|
256
|
+
return { subjectId: String(identity.serviceProvider), category: "service_provider" };
|
|
257
|
+
}
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WHICH HID READER THE OPERATOR IS WORKING ON — the one rule behind it.
|
|
3
|
+
*
|
|
4
|
+
* Every HID screen used to hold its own `ref("")` and default it to
|
|
5
|
+
* `readers[0]`, so picking HID 2 on HID Reader Users and clicking through to
|
|
6
|
+
* HID Cards put you back on HID 1. They are separate PAGES, so the component
|
|
7
|
+
* unmounted and the ref was rebuilt from scratch every time — there was no way
|
|
8
|
+
* to make a choice stick. "I am working on HID 2" is a mode, not a per-screen
|
|
9
|
+
* preference.
|
|
10
|
+
*
|
|
11
|
+
* Navigation between those pages is a route change rather than a page load
|
|
12
|
+
* (`NavigationItem.vue` renders the menu's `route` through `:to`), so the
|
|
13
|
+
* module-scoped ref in `useHidReaderSelection` survives it. This file holds the
|
|
14
|
+
* part worth testing: deciding whether a remembered choice may still be used.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export type HidReaderChoice = { siteId: string; readerId: string };
|
|
18
|
+
|
|
19
|
+
/** Anything with an id — the four screens all carry a different reader shape. */
|
|
20
|
+
type ReaderLike = { _id?: unknown };
|
|
21
|
+
|
|
22
|
+
export const EMPTY_HID_READER_CHOICE: HidReaderChoice = { siteId: "", readerId: "" };
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The reader a screen should show, given what this site actually has.
|
|
26
|
+
*
|
|
27
|
+
* A remembered id is honoured ONLY when it belongs to this site and is still in
|
|
28
|
+
* the list. That single condition covers every way it goes stale:
|
|
29
|
+
*
|
|
30
|
+
* - the operator switched site, so the id belongs to a site they have left
|
|
31
|
+
* - the reader was deleted or deactivated since they chose it
|
|
32
|
+
* - nothing has been chosen yet
|
|
33
|
+
*
|
|
34
|
+
* In all three the first reader is returned instead. The alternative — using
|
|
35
|
+
* the id anyway — sends requests for a reader the site does not own, which come
|
|
36
|
+
* back empty and read on screen as a reader with no users, no cards and no
|
|
37
|
+
* logs, rather than as the mistake it is.
|
|
38
|
+
*/
|
|
39
|
+
export function resolveHidReaderId(
|
|
40
|
+
siteId: string,
|
|
41
|
+
readers: readonly ReaderLike[] | null | undefined,
|
|
42
|
+
choice: HidReaderChoice = EMPTY_HID_READER_CHOICE,
|
|
43
|
+
): string {
|
|
44
|
+
const ids = (Array.isArray(readers) ? readers : [])
|
|
45
|
+
.map((reader) => String(reader?._id ?? ""))
|
|
46
|
+
.filter(Boolean);
|
|
47
|
+
|
|
48
|
+
if (choice.siteId === String(siteId ?? "") && ids.includes(choice.readerId)) {
|
|
49
|
+
return choice.readerId;
|
|
50
|
+
}
|
|
51
|
+
return ids[0] ?? "";
|
|
52
|
+
}
|