@7365admin1/layer-common 4.149.2 → 4.151.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 +16 -4
- package/components/EntryPassInformation.vue +13 -0
- package/components/HidAccessPermissions.vue +202 -40
- package/components/HidEnabledGate.vue +29 -10
- package/components/HidIntercomManagement.vue +26 -13
- package/components/HidProfileQrCode.vue +6 -2
- package/components/HidQrCodeConfiguration.vue +2 -2
- package/components/HidReaderForm.vue +239 -1
- package/components/HidReaderManagement.vue +26 -8
- package/components/HidReaderUserRoster.vue +3 -1
- package/components/HidServiceSettingsPanel.vue +2 -2
- package/components/HidUserEnrollment.vue +1662 -162
- package/components/OvernightParkingAvailability.vue +123 -11
- package/components/Robot/Detail.vue +23 -4
- package/components/SiteSettings.vue +5 -2
- package/components/VisitorForm.vue +39 -11
- package/composables/useCleaningPermission.ts +11 -0
- package/composables/useHidAccessPermission.ts +176 -81
- package/composables/useHidAmico.ts +37 -0
- package/composables/useHidNavigation.ts +44 -23
- package/composables/useLandscapingPermission.ts +11 -0
- package/composables/useMechanicalElectricalPermission.ts +5 -0
- package/composables/usePestControlPermission.ts +11 -0
- package/composables/usePoolMaintenancePermission.ts +11 -0
- package/composables/usePropertyPermission.ts +31 -7
- package/composables/useSecurityPermission.ts +33 -13
- package/composables/useServiceProvider.ts +9 -4
- package/constants/permissions.ts +73 -21
- package/package.json +1 -1
- package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +3 -0
- package/types/overnight-parking.d.ts +14 -0
- package/types/site.d.ts +7 -1
- package/utils/hid-enrolment-subject.ts +226 -4
- package/utils/hid-permission-assignments.ts +75 -6
- package/utils/hid-qr-validity.ts +25 -0
- package/utils/hid-reader-audiences.ts +557 -0
- package/utils/hid-registration.ts +24 -0
- package/utils/module-routes.ts +15 -2
- package/utils/nav-sections.ts +1 -1
- package/utils/robot-credential-form.ts +4 -2
- package/utils/robot-display.ts +28 -6
- package/utils/robot-setup.ts +1 -0
|
@@ -575,12 +575,10 @@ export default function useSecurityPermission() {
|
|
|
575
575
|
description: "Allows the user to delete/remove a unit.",
|
|
576
576
|
},
|
|
577
577
|
},
|
|
578
|
-
//
|
|
579
|
-
//
|
|
580
|
-
//
|
|
581
|
-
//
|
|
582
|
-
// call. Offering them here does not open any gate; it makes the server's
|
|
583
|
-
// existing rule grantable.
|
|
578
|
+
// Access cards. Until 2026-10 this family was also what every
|
|
579
|
+
// `/api/access-management/hid` route read; HID now has `hid-mgmt` below and
|
|
580
|
+
// the card strings here mean cards again (the server still accepts them
|
|
581
|
+
// for HID during the alias period, see `useHidAccessPermission`).
|
|
584
582
|
"access-card-mgmt": {
|
|
585
583
|
"see-all-card": {
|
|
586
584
|
check: true,
|
|
@@ -590,11 +588,6 @@ export default function useSecurityPermission() {
|
|
|
590
588
|
check: true,
|
|
591
589
|
description: "Allows the user to view QR tagging.",
|
|
592
590
|
},
|
|
593
|
-
view: {
|
|
594
|
-
check: true,
|
|
595
|
-
description:
|
|
596
|
-
"Allows the user to view access card management, including HID readers and access logs.",
|
|
597
|
-
},
|
|
598
591
|
"add-access-card": {
|
|
599
592
|
check: true,
|
|
600
593
|
description: "Allows the user to add a new access card to the system.",
|
|
@@ -616,10 +609,37 @@ export default function useSecurityPermission() {
|
|
|
616
609
|
check: true,
|
|
617
610
|
description: "Allows the user to replace a lost or damaged access card.",
|
|
618
611
|
},
|
|
619
|
-
|
|
612
|
+
},
|
|
613
|
+
// HID access management (decision of 2026-10-16). Five strings under one
|
|
614
|
+
// resource, mirrored from core `src/utils/hid-access.util.ts`; the HID
|
|
615
|
+
// screens, menu and buttons (`useHidAccessPermission`) and every
|
|
616
|
+
// `/api/access-management/hid` route read them. Wildcard passes all five,
|
|
617
|
+
// an empty list passes none, either manage right implies view.
|
|
618
|
+
"hid-mgmt": {
|
|
619
|
+
"use-hid-access": {
|
|
620
|
+
check: true,
|
|
621
|
+
description:
|
|
622
|
+
"Allows the user to see HID Access in the app and use their own QR code, face, PIN, card and intercom at this site.",
|
|
623
|
+
},
|
|
624
|
+
"see-all-hid": {
|
|
625
|
+
check: true,
|
|
626
|
+
description:
|
|
627
|
+
"Allows the user to view the site's HID readers, enrolled people, cards and access logs.",
|
|
628
|
+
},
|
|
629
|
+
"manage-hid-readers": {
|
|
630
|
+
check: true,
|
|
631
|
+
description:
|
|
632
|
+
"Allows the user to add, configure, test, sync and remove HID readers. Includes viewing.",
|
|
633
|
+
},
|
|
634
|
+
"manage-hid-users": {
|
|
635
|
+
check: true,
|
|
636
|
+
description:
|
|
637
|
+
"Allows the user to enrol and remove people, cards and PINs, and assign HID access groups. Includes viewing.",
|
|
638
|
+
},
|
|
639
|
+
"manage-hid-settings": {
|
|
620
640
|
check: true,
|
|
621
641
|
description:
|
|
622
|
-
"Allows the user to
|
|
642
|
+
"Allows the user to switch HID on or off for the site and configure the HID QR code.",
|
|
623
643
|
},
|
|
624
644
|
},
|
|
625
645
|
// Two resources below are checked ONLY by the iSecure365 mobile app, which
|
|
@@ -19,10 +19,15 @@ export type TSiteProviderMember = {
|
|
|
19
19
|
unit?: string | null;
|
|
20
20
|
unitName?: string;
|
|
21
21
|
/**
|
|
22
|
-
* The person's user account.
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
22
|
+
* The person's user account. Anything acting on the PERSON needs this rather
|
|
23
|
+
* than `_id`, which identifies the membership: an access card carries it as
|
|
24
|
+
* `userId`, and HID reader access is bound by it -
|
|
25
|
+
* `resolvePermissionUserBindings` drops every subject without one.
|
|
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".
|
|
26
31
|
*/
|
|
27
32
|
user?: string | null;
|
|
28
33
|
};
|
package/constants/permissions.ts
CHANGED
|
@@ -380,16 +380,38 @@ export const PERMISSIONS = {
|
|
|
380
380
|
"add-service-provider",
|
|
381
381
|
"invite-service-provider",
|
|
382
382
|
],
|
|
383
|
+
// Access cards and QR tagging: the Property Management screens of those
|
|
384
|
+
// names. Until 2026-10 the HID screens borrowed this family (core
|
|
385
|
+
// `hid-access.util.ts` read nine of its strings); HID now has `hid-mgmt`
|
|
386
|
+
// below. `view` and `manage-hid` were only ever HID rights, so they left with
|
|
387
|
+
// it: see `RETIRED_PERMISSIONS` for how they are still read during the alias
|
|
388
|
+
// period.
|
|
383
389
|
"access-card-mgmt": [
|
|
384
390
|
"see-all-card",
|
|
385
391
|
"see-all-qr-tagging",
|
|
386
|
-
"view",
|
|
387
392
|
"add-access-card",
|
|
388
393
|
"update-access-card",
|
|
389
394
|
"replace-access-card",
|
|
390
395
|
"delete-access-card",
|
|
391
396
|
"assign-access-card",
|
|
392
|
-
|
|
397
|
+
],
|
|
398
|
+
// HID access management (decision of 2026-10-16). The five strings are
|
|
399
|
+
// defined in core `src/utils/hid-access.util.ts` (`HID_RESOURCE` and the
|
|
400
|
+
// `HID_*_PERMISSIONS` lists); this package does not depend on `@7365admin1/core`,
|
|
401
|
+
// so it keeps its own copy and `test/hid-access-gate.test.mjs` pins the five.
|
|
402
|
+
// use-hid-access user side: own QR, face, PIN, card, intercom
|
|
403
|
+
// see-all-hid read any HID admin screen
|
|
404
|
+
// manage-hid-readers add, configure, test, sync, remove readers
|
|
405
|
+
// manage-hid-users enrol and remove people, cards, PINs, groups
|
|
406
|
+
// manage-hid-settings HID on or off and the QR configuration for a site
|
|
407
|
+
// Wildcard passes all five; an empty list passes none; either manage right
|
|
408
|
+
// implies view. The module deny list key is the resource name.
|
|
409
|
+
"hid-mgmt": [
|
|
410
|
+
"use-hid-access",
|
|
411
|
+
"see-all-hid",
|
|
412
|
+
"manage-hid-readers",
|
|
413
|
+
"manage-hid-users",
|
|
414
|
+
"manage-hid-settings",
|
|
393
415
|
],
|
|
394
416
|
|
|
395
417
|
// ---- security ----
|
|
@@ -659,12 +681,14 @@ export const LEGACY_PERMISSION_ALIASES: Readonly<
|
|
|
659
681
|
/**
|
|
660
682
|
* Strings the SERVER enforces that no UI checks and no role editor can grant.
|
|
661
683
|
*
|
|
662
|
-
* `core/src/utils/hid-access.util.ts
|
|
663
|
-
*
|
|
664
|
-
* whole estate spells visitor rights
|
|
665
|
-
* `:update-visitor` and so on; a bare `visitor`
|
|
666
|
-
* in any repo, so no role can hold these and
|
|
667
|
-
*
|
|
684
|
+
* `core/src/utils/hid-access.util.ts` keeps `visitor:create`, `visitor:update`
|
|
685
|
+
* and `visitor:check-out` in `HID_VISITOR_PERMISSIONS` (the visitor pass revoke
|
|
686
|
+
* routes) until the alias drop. The whole estate spells visitor rights
|
|
687
|
+
* `visitor-mgmt:add-visitor`, `:update-visitor` and so on; a bare `visitor`
|
|
688
|
+
* resource appears in no catalogue in any repo, so no role can hold these and
|
|
689
|
+
* the branch is reachable only through `*`, through
|
|
690
|
+
* `visitor-mgmt:update-visitor` (which the same list now also accepts) or
|
|
691
|
+
* through the HID manage users strings it unions in.
|
|
668
692
|
*
|
|
669
693
|
* They are NOT aliased to `visitor-mgmt:*` here, because doing so would be a
|
|
670
694
|
* decision with a real consequence in both directions:
|
|
@@ -695,19 +719,47 @@ export const SERVER_ONLY_UNGRANTABLE: readonly string[] = Object.freeze([
|
|
|
695
719
|
* Canonical strings that are CHECKED -- by this package and by the server -- and
|
|
696
720
|
* that no role editor can GRANT.
|
|
697
721
|
*
|
|
698
|
-
*
|
|
699
|
-
* the HID menu and
|
|
700
|
-
*
|
|
701
|
-
*
|
|
702
|
-
*
|
|
703
|
-
*
|
|
722
|
+
* Empty since 2026-10-16. It used to hold `access-card-mgmt:view`,
|
|
723
|
+
* `:assign-access-card` and `:manage-hid`, which the HID menu accepted and
|
|
724
|
+
* `core/src/utils/hid-access.util.ts` enforced while no app's catalogue offered
|
|
725
|
+
* them. HID now has its own `hid-mgmt` family, offered in full by the property
|
|
726
|
+
* and security catalogues and as `use-hid-access` by the five service
|
|
727
|
+
* catalogues (M&E joined on 2026-10-19); `assign-access-card` is offered by
|
|
728
|
+
* both card catalogues; `view` and `manage-hid` are retired (below). Kept,
|
|
729
|
+
* and still pinned by the drift test, so the next string of this shape is
|
|
730
|
+
* recorded here rather than found by somebody staring at a blank screen.
|
|
704
731
|
*/
|
|
705
732
|
export const CHECKED_BUT_UNGRANTABLE: readonly TPermissionString[] =
|
|
706
|
-
Object.freeze([
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
733
|
+
Object.freeze([]);
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* Strings that are no longer canonical and have no canonical equivalent, but
|
|
737
|
+
* that this package and the server STILL READ for one release.
|
|
738
|
+
*
|
|
739
|
+
* `access-card-mgmt:view` and `access-card-mgmt:manage-hid` were the HID
|
|
740
|
+
* rights before `hid-mgmt` existed. Core `hid-access.util.ts` keeps them in
|
|
741
|
+
* `HID_LEGACY_VIEW_PERMISSIONS` and `HID_LEGACY_MANAGE_PERMISSIONS` until the
|
|
742
|
+
* live roles are backfilled onto the five `hid-mgmt` strings, and
|
|
743
|
+
* `useHidAccessPermission` reads them at the same levels during that period.
|
|
744
|
+
* No role editor offers them any more, and nothing new may be written against
|
|
745
|
+
* them.
|
|
746
|
+
*
|
|
747
|
+
* They are NOT legacy aliases: an alias joins two spellings of ONE grant into
|
|
748
|
+
* an equivalence class (`utils/permission-spellings.ts`) and joins the two
|
|
749
|
+
* resources into one module spelling group (`utils/org-modules.ts`). Access
|
|
750
|
+
* cards and HID are two modules, and `manage-hid` meant three HID levels at
|
|
751
|
+
* once, so neither of those is true here.
|
|
752
|
+
*
|
|
753
|
+
* `isKnownPermission` answers true for these; `canonicalPermission` does not
|
|
754
|
+
* resolve them. The alias drop deletes this list and the composable's legacy
|
|
755
|
+
* branches together.
|
|
756
|
+
*/
|
|
757
|
+
export const RETIRED_PERMISSIONS: Readonly<Record<string, string>> = Object.freeze({
|
|
758
|
+
"access-card-mgmt:view":
|
|
759
|
+
"HID view right before hid-mgmt:see-all-hid; read until the alias drop",
|
|
760
|
+
"access-card-mgmt:manage-hid":
|
|
761
|
+
"HID manage right before hid-mgmt:manage-hid-*; read until the alias drop",
|
|
762
|
+
});
|
|
711
763
|
|
|
712
764
|
const CANONICAL = new Set<string>(PERMISSION_STRINGS);
|
|
713
765
|
|
|
@@ -724,7 +776,7 @@ export function canonicalPermission(
|
|
|
724
776
|
return LEGACY_PERMISSION_ALIASES[value];
|
|
725
777
|
}
|
|
726
778
|
|
|
727
|
-
/** Is this string one the catalogue knows
|
|
779
|
+
/** Is this string one the catalogue knows: canonical, legacy, or retired but still read? */
|
|
728
780
|
export function isKnownPermission(value: string): boolean {
|
|
729
|
-
return canonicalPermission(value) !== undefined;
|
|
781
|
+
return canonicalPermission(value) !== undefined || value in RETIRED_PERMISSIONS;
|
|
730
782
|
}
|
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.151.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.",
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<v-container fluid>
|
|
3
|
+
<!-- The member's own pass, so the gate asks for the use right, not the
|
|
4
|
+
admin view right every other HID page asks for. -->
|
|
3
5
|
<HidEnabledGate
|
|
4
6
|
:site="siteId"
|
|
5
7
|
:org="orgId"
|
|
8
|
+
level="use"
|
|
6
9
|
message="Enable HID as a service for this site before generating a QR code."
|
|
7
10
|
>
|
|
8
11
|
<HidProfileQrCode :site="siteId" />
|
|
@@ -14,6 +14,20 @@ declare type TOvernightParkingAvailability = {
|
|
|
14
14
|
sunday: TOvernightParkingDay;
|
|
15
15
|
isAllowPlateNumberOpenBarrier?: boolean;
|
|
16
16
|
autoApproveOvernightParking?: boolean;
|
|
17
|
+
visitorQrCodes?: TVisitorQrCode[];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
declare type TVisitorQrCodeType = "hid" | "entryPass" | "security";
|
|
21
|
+
|
|
22
|
+
// How long an HID visitor pass lasts: until the end of the visit day, or
|
|
23
|
+
// until the visitor's first entry.
|
|
24
|
+
declare type TVisitorQrUsage = "wholeDay" | "singleUse";
|
|
25
|
+
|
|
26
|
+
declare type TVisitorQrCode = {
|
|
27
|
+
type: TVisitorQrCodeType;
|
|
28
|
+
isEnabled: boolean;
|
|
29
|
+
// HID only.
|
|
30
|
+
usage?: TVisitorQrUsage;
|
|
17
31
|
};
|
|
18
32
|
|
|
19
33
|
declare type TOvernightParkingRequestStatus =
|
package/types/site.d.ts
CHANGED
|
@@ -5,7 +5,10 @@ declare type THidQrCodeFormat = "0" | "1" | "2";
|
|
|
5
5
|
declare type THidPermissionCategory =
|
|
6
6
|
| "resident"
|
|
7
7
|
| "property_management"
|
|
8
|
-
|
|
8
|
+
/** A provider COMPANY - granting one admits every active member of that org. */
|
|
9
|
+
| "service_provider"
|
|
10
|
+
/** ONE PERSON from a provider company, by their membership at this site. */
|
|
11
|
+
| "service_provider_member";
|
|
9
12
|
|
|
10
13
|
declare type THidPermissionAssignment = {
|
|
11
14
|
subjectId: string;
|
|
@@ -27,7 +30,10 @@ declare type THidSitePermissions = {
|
|
|
27
30
|
counts: {
|
|
28
31
|
resident: number;
|
|
29
32
|
propertyManagement: number;
|
|
33
|
+
/** Provider COMPANIES granted. */
|
|
30
34
|
serviceProvider: number;
|
|
35
|
+
/** Named provider people granted. Counted apart from the companies. */
|
|
36
|
+
serviceProviderMember: number;
|
|
31
37
|
intercom: number;
|
|
32
38
|
};
|
|
33
39
|
};
|
|
@@ -8,14 +8,20 @@
|
|
|
8
8
|
* in this repo.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
|
|
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";
|
|
12
20
|
|
|
13
21
|
/**
|
|
14
22
|
* The dropdown's options, in the order they are drawn.
|
|
15
23
|
*
|
|
16
|
-
* `title`/`value` because `AppSelect` takes that shape.
|
|
17
|
-
* option is expected next; adding it here is most of the work, since the write
|
|
18
|
-
* path already maps `service_provider` onto `serviceProvider`.
|
|
24
|
+
* `title`/`value` because `AppSelect` takes that shape.
|
|
19
25
|
*/
|
|
20
26
|
export const HID_ENROLMENT_SUBJECTS: ReadonlyArray<{
|
|
21
27
|
title: string;
|
|
@@ -23,6 +29,7 @@ export const HID_ENROLMENT_SUBJECTS: ReadonlyArray<{
|
|
|
23
29
|
}> = [
|
|
24
30
|
{ title: "Resident", value: "resident" },
|
|
25
31
|
{ title: "Member", value: "property_management" },
|
|
32
|
+
{ title: "Service provider", value: "service_provider_staff" },
|
|
26
33
|
];
|
|
27
34
|
|
|
28
35
|
/**
|
|
@@ -38,6 +45,10 @@ export function subjectCategoryLabel(category: unknown): string {
|
|
|
38
45
|
const labels: Record<string, string> = {
|
|
39
46
|
resident: "Resident",
|
|
40
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.
|
|
41
52
|
service_provider: "Service provider",
|
|
42
53
|
visitor: "Visitor",
|
|
43
54
|
};
|
|
@@ -142,3 +153,214 @@ export function hiddenSubjectNote(count: number, noun: "resident" | "member"): s
|
|
|
142
153
|
return `${subject} at this site ${verb} not listed:`
|
|
143
154
|
+ ` HID enrollment needs an app account, and ${holder} none yet.`;
|
|
144
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
|
+
}
|
|
@@ -27,11 +27,19 @@
|
|
|
27
27
|
* through is a 400.
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
|
-
/**
|
|
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
|
+
*/
|
|
31
38
|
export const HID_PERMISSION_CATEGORIES: THidPermissionCategory[] = [
|
|
32
39
|
"resident",
|
|
33
40
|
"property_management",
|
|
34
41
|
"service_provider",
|
|
42
|
+
"service_provider_member",
|
|
35
43
|
];
|
|
36
44
|
|
|
37
45
|
export type HidAssignmentState = Map<string, { category: THidPermissionCategory; intercom: boolean }>;
|
|
@@ -134,11 +142,20 @@ export function applySelection(
|
|
|
134
142
|
|
|
135
143
|
/** Per-category totals for the dialog header, counted over the whole reader. */
|
|
136
144
|
export function countByCategory(state: HidAssignmentState): Record<THidPermissionCategory, number> {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
+
}
|
|
142
159
|
return counts;
|
|
143
160
|
}
|
|
144
161
|
|
|
@@ -188,3 +205,55 @@ export function readCandidatePage(response: unknown): {
|
|
|
188
205
|
pageRange,
|
|
189
206
|
};
|
|
190
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
|
+
}
|