@7365admin1/layer-common 4.97.1-staging.502 → 4.98.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/CHANGELOG.md +885 -4
- package/components/AccessCardDetailsDialog.vue +2 -2
- package/components/AccessCardPreviewDialog.vue +9 -86
- package/components/HidAccessPermissions.vue +38 -146
- package/components/HidUserEnrollment.vue +39 -679
- package/components/VehicleQrStickerDialog.vue +8 -0
- package/composables/useAccessManagement.ts +1 -17
- package/composables/useServiceProvider.ts +4 -9
- package/package.json +1 -1
- package/types/site.d.ts +1 -7
- package/utils/hid-enrolment-subject.ts +4 -226
- package/utils/hid-permission-assignments.ts +6 -75
|
@@ -258,6 +258,14 @@ const shapeThumbs = computed(() => {
|
|
|
258
258
|
});
|
|
259
259
|
});
|
|
260
260
|
|
|
261
|
+
// Picking a shaped code makes the shape the sticker (no card); back to the
|
|
262
|
+
// square brings the standard card. The frame can still be changed after.
|
|
263
|
+
watch(
|
|
264
|
+
() => design.shape,
|
|
265
|
+
(now, before) => {
|
|
266
|
+
if ((now === "square") !== (before === "square")) design.frame = now === "square" ? DEFAULT_STICKER_DESIGN.frame : "none";
|
|
267
|
+
},
|
|
268
|
+
);
|
|
261
269
|
// A shape change can leave a frame or size that shape does not offer (the badge
|
|
262
270
|
// frame, or a size whose QR would print under 25 mm): fall back to one it does.
|
|
263
271
|
watch(
|
|
@@ -319,23 +319,7 @@ export default function useAccessManagement() {
|
|
|
319
319
|
);
|
|
320
320
|
}
|
|
321
321
|
|
|
322
|
-
|
|
323
|
-
* `holderType` is the GROUP the card was given from — "Visitor/Resident",
|
|
324
|
-
* "Management" or "Service Provider" (core `EAccessCardHolderTypes`).
|
|
325
|
-
*
|
|
326
|
-
* It is what lets the server resolve the holder afterwards: `assignees`
|
|
327
|
-
* carries a `users` id for a resident, but a membership id for a service
|
|
328
|
-
* provider, and only the group says which collection to look in. Omit it and
|
|
329
|
-
* the card stores `holderType: null`, so card details cannot name the holder.
|
|
330
|
-
*/
|
|
331
|
-
function assignUser(payload: {
|
|
332
|
-
assignees: string[];
|
|
333
|
-
unit: string;
|
|
334
|
-
type: string;
|
|
335
|
-
acm_url: string;
|
|
336
|
-
id?: string;
|
|
337
|
-
holderType?: "Visitor/Resident" | "Management" | "Service Provider";
|
|
338
|
-
}) {
|
|
322
|
+
function assignUser(payload: { assignees: string[]; unit: string; type: string; acm_url: string; id?: string }) {
|
|
339
323
|
return useNuxtApp().$api<Record<string, any>>(
|
|
340
324
|
`/api/access-management/assign-user`,
|
|
341
325
|
{ method: "POST", body: payload }
|
|
@@ -19,15 +19,10 @@ export type TSiteProviderMember = {
|
|
|
19
19
|
unit?: string | null;
|
|
20
20
|
unitName?: string;
|
|
21
21
|
/**
|
|
22
|
-
* The person's user account.
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* `
|
|
26
|
-
*
|
|
27
|
-
* Returned from core 3.130. Before that the repository projected it and the
|
|
28
|
-
* service layer dropped it, so against an older API it is absent on every
|
|
29
|
-
* row - `providerAccountsKnown` is how the HID enrolment screen tells the two
|
|
30
|
-
* apart rather than reading an absence as "nobody has an account".
|
|
22
|
+
* The person's user account. NOT yet returned by the endpoint — the
|
|
23
|
+
* repository projects it but the service layer drops it. Anything acting on
|
|
24
|
+
* the PERSON (assigning an access card writes it onto the card as `userId`)
|
|
25
|
+
* needs this rather than `_id`, which identifies the membership.
|
|
31
26
|
*/
|
|
32
27
|
user?: string | null;
|
|
33
28
|
};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@7365admin1/layer-common",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "4.
|
|
5
|
+
"version": "4.98.0",
|
|
6
6
|
"author": "7365admin1",
|
|
7
7
|
"main": "./nuxt.config.ts",
|
|
8
8
|
"//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",
|
package/types/site.d.ts
CHANGED
|
@@ -5,10 +5,7 @@ declare type THidQrCodeFormat = "0" | "1" | "2";
|
|
|
5
5
|
declare type THidPermissionCategory =
|
|
6
6
|
| "resident"
|
|
7
7
|
| "property_management"
|
|
8
|
-
|
|
9
|
-
| "service_provider"
|
|
10
|
-
/** ONE PERSON from a provider company, by their membership at this site. */
|
|
11
|
-
| "service_provider_member";
|
|
8
|
+
| "service_provider";
|
|
12
9
|
|
|
13
10
|
declare type THidPermissionAssignment = {
|
|
14
11
|
subjectId: string;
|
|
@@ -30,10 +27,7 @@ declare type THidSitePermissions = {
|
|
|
30
27
|
counts: {
|
|
31
28
|
resident: number;
|
|
32
29
|
propertyManagement: number;
|
|
33
|
-
/** Provider COMPANIES granted. */
|
|
34
30
|
serviceProvider: number;
|
|
35
|
-
/** Named provider people granted. Counted apart from the companies. */
|
|
36
|
-
serviceProviderMember: number;
|
|
37
31
|
intercom: number;
|
|
38
32
|
};
|
|
39
33
|
};
|
|
@@ -8,20 +8,14 @@
|
|
|
8
8
|
* in this repo.
|
|
9
9
|
*/
|
|
10
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";
|
|
11
|
+
export type HidEnrolmentSubject = "resident" | "property_management";
|
|
20
12
|
|
|
21
13
|
/**
|
|
22
14
|
* The dropdown's options, in the order they are drawn.
|
|
23
15
|
*
|
|
24
|
-
* `title`/`value` because `AppSelect` takes that shape.
|
|
16
|
+
* `title`/`value` because `AppSelect` takes that shape. A service-provider
|
|
17
|
+
* option is expected next; adding it here is most of the work, since the write
|
|
18
|
+
* path already maps `service_provider` onto `serviceProvider`.
|
|
25
19
|
*/
|
|
26
20
|
export const HID_ENROLMENT_SUBJECTS: ReadonlyArray<{
|
|
27
21
|
title: string;
|
|
@@ -29,7 +23,6 @@ export const HID_ENROLMENT_SUBJECTS: ReadonlyArray<{
|
|
|
29
23
|
}> = [
|
|
30
24
|
{ title: "Resident", value: "resident" },
|
|
31
25
|
{ title: "Member", value: "property_management" },
|
|
32
|
-
{ title: "Service provider", value: "service_provider_staff" },
|
|
33
26
|
];
|
|
34
27
|
|
|
35
28
|
/**
|
|
@@ -45,10 +38,6 @@ export function subjectCategoryLabel(category: unknown): string {
|
|
|
45
38
|
const labels: Record<string, string> = {
|
|
46
39
|
resident: "Resident",
|
|
47
40
|
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
41
|
service_provider: "Service provider",
|
|
53
42
|
visitor: "Visitor",
|
|
54
43
|
};
|
|
@@ -153,214 +142,3 @@ export function hiddenSubjectNote(count: number, noun: "resident" | "member"): s
|
|
|
153
142
|
return `${subject} at this site ${verb} not listed:`
|
|
154
143
|
+ ` HID enrollment needs an app account, and ${holder} none yet.`;
|
|
155
144
|
}
|
|
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
|
-
}
|
|
@@ -27,19 +27,11 @@
|
|
|
27
27
|
* through is a 400.
|
|
28
28
|
*/
|
|
29
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
|
-
*/
|
|
30
|
+
/** The three real categories. `intercom` is a candidate FILTER, never a category. */
|
|
38
31
|
export const HID_PERMISSION_CATEGORIES: THidPermissionCategory[] = [
|
|
39
32
|
"resident",
|
|
40
33
|
"property_management",
|
|
41
34
|
"service_provider",
|
|
42
|
-
"service_provider_member",
|
|
43
35
|
];
|
|
44
36
|
|
|
45
37
|
export type HidAssignmentState = Map<string, { category: THidPermissionCategory; intercom: boolean }>;
|
|
@@ -142,20 +134,11 @@ export function applySelection(
|
|
|
142
134
|
|
|
143
135
|
/** Per-category totals for the dialog header, counted over the whole reader. */
|
|
144
136
|
export function countByCategory(state: HidAssignmentState): Record<THidPermissionCategory, number> {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
}
|
|
137
|
+
const counts = { resident: 0, property_management: 0, service_provider: 0 } as Record<
|
|
138
|
+
THidPermissionCategory,
|
|
139
|
+
number
|
|
140
|
+
>;
|
|
141
|
+
for (const value of state.values()) counts[value.category] += 1;
|
|
159
142
|
return counts;
|
|
160
143
|
}
|
|
161
144
|
|
|
@@ -205,55 +188,3 @@ export function readCandidatePage(response: unknown): {
|
|
|
205
188
|
pageRange,
|
|
206
189
|
};
|
|
207
190
|
}
|
|
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
|
-
}
|