@7365admin1/layer-common 4.2.13 → 4.2.14

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 CHANGED
@@ -1,5 +1,21 @@
1
1
  # @iservice365/layer-common
2
2
 
3
+ ## 4.2.14
4
+
5
+ ### Patch Changes
6
+
7
+ - 1d22a74: Gate the six HID access-mgmt screens on the access-card-mgmt permissions the API already enforces
8
+
9
+ The access-logs, administrator, hid-cards, hid-readers, hid-users and intercom
10
+ pages carried no permission check, so any member of any organisation could type
11
+ the URL and reach door access, biometric enrolment, physical cards and the
12
+ access log. HidEnabledGate now also requires the caller to hold one of the nine
13
+ access-card-mgmt strings, site-settings:manage-entry-pass, or the wildcard.
14
+
15
+ Those are the same strings /api/access-management/hid already enforces, so the
16
+ set now refused is a strict subset of the set the API refuses today: nobody with
17
+ a working screen loses it.
18
+
3
19
  ## 4.2.13
4
20
 
5
21
  ### Patch Changes
@@ -595,11 +611,11 @@
595
611
  `utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
596
612
  own rule from two endpoints the console already calls, unprojected:
597
613
 
598
- GET /api/members/user/:user/app/admin the Seven365 staff membership
599
- GET /api/roles/id/:role that membership's role document
614
+ GET /api/members/user/:user/app/admin the Seven365 staff membership
615
+ GET /api/roles/id/:role that membership's role document
600
616
 
601
- owner = member.type === "admin" && role.type === "admin" && role.default === true
602
- staff = member.type === "admin" && role.type === "admin"
617
+ owner = member.type === "admin" && role.type === "admin" && role.default === true
618
+ staff = member.type === "admin" && role.type === "admin"
603
619
 
604
620
  `role.default` is the marker because it is the only property of a platform
605
621
  staff role no API caller can set - `role.controller.ts` validates create and
@@ -17,7 +17,22 @@
17
17
  a coloured slab. Icons are translated centrally — no hand-mapping here.
18
18
  -->
19
19
  <template>
20
- <slot v-if="hidEnabled" />
20
+ <!-- Nothing at all while the role is still resolving. `userAppRole` is null
21
+ on the first tick for EVERYONE including the `*` owner, so drawing the
22
+ denial here would flash "no permission" at the owner on every load. -->
23
+ <template v-if="!isAppRoleResolved" />
24
+
25
+ <slot v-else-if="hidEnabled && canAccessHidScreens" />
26
+
27
+ <div v-else-if="hidEnabled" class="screen-empty hid-gate">
28
+ <span class="hid-gate__icon tone-info">
29
+ <v-icon icon="mdi-lock-outline" size="24" />
30
+ </span>
31
+ <h2 class="hid-gate__title">You do not have permission for HID access management</h2>
32
+ <p class="hid-gate__body">
33
+ Ask an administrator to grant your role access card management for this site.
34
+ </p>
35
+ </div>
21
36
 
22
37
  <div v-else class="screen-empty hid-gate">
23
38
  <span class="hid-gate__icon tone-info">
@@ -45,6 +60,14 @@ const props = withDefaults(
45
60
  const { getSiteById } = useSiteSettings();
46
61
  const { getHidServiceEnabled } = useOptionalServices();
47
62
 
63
+ // The permission half of the same gate. This component is the only thing all
64
+ // six `access-mgmt` pages have in common, so putting the check here governs all
65
+ // six -- and all 66 inherited routes across the eleven apps -- without a page
66
+ // guard per screen. See `composables/useHidAccessPermission.ts` for why the
67
+ // gate cannot remove access that currently works.
68
+ const { canAccessHidScreens } = useHidAccessPermission();
69
+ const { isAppRoleResolved } = useLocalSetup();
70
+
48
71
  // Do not await this request during route setup. Every HID page uses this gate;
49
72
  // awaiting it makes Nuxt Suspense keep rendering the previous page until the
50
73
  // site request finishes, so the URL changes while the visible module appears
@@ -0,0 +1,115 @@
1
+ /**
2
+ * WHO MAY REACH THE SIX HID `access-mgmt` SCREENS.
3
+ *
4
+ * `pages/[org]/[site]/access-mgmt/{access-logs, administrator, hid-cards,
5
+ * hid-readers, hid-users, intercom}/index.vue` shipped with
6
+ * `middleware: ["01-auth","02-org"], memberOnly: true` and no permission check
7
+ * at all. Every one of the eleven Nuxt apps inherits all six, so that was 66
8
+ * routes on which any member of any organisation could type the URL and reach
9
+ * door access, biometric enrolment, physical cards and the access log. The menu
10
+ * that links five of them (`useHidNavigation`) is gated on
11
+ * `getHidServiceEnabled(site)` -- a SITE SERVICE FLAG, not a permission -- so
12
+ * the menu was never a boundary either.
13
+ *
14
+ * ## Why adding this gate cannot lock anybody out
15
+ *
16
+ * Every data call these screens make goes through `useHidAmico` to
17
+ * `/api/access-management/hid`, and every route there carries `requireAuth`
18
+ * plus `authorizeView` or `authorizeManage`. Those resolve through
19
+ * `authorizeHidAccess` (`core/services/hid-amico.service.ts`) to the lists in
20
+ * `core/utils/hid-access.util.ts` -- the nine `access-card-mgmt` strings below.
21
+ *
22
+ * WARNING: there are TWO different `HID_MANAGE_PERMISSIONS` in `core` and they
23
+ * are NOT the same list. `hid-amico-authz.util.ts` exports
24
+ * `["site-settings:manage-entry-pass"]`; `hid-access.util.ts` exports the
25
+ * `access-card-mgmt` family. `hid-amico.service.ts` imports the one from
26
+ * `hid-access.util.ts` -- and `authorizeSiteForCaller`'s own doc comment is
27
+ * stale and still claims the other. Follow the import, not the name.
28
+ *
29
+ * So a member holding none of these strings already gets a 401 on every list
30
+ * call on all six screens: the screens are non-functional for them today, and
31
+ * they see chrome plus an error toast. The set this gate refuses is a strict
32
+ * SUBSET of the set the server already refuses in production, which is a
33
+ * stronger guarantee than the usual widen-never-swap argument because it is
34
+ * anchored on live server behaviour rather than on a role census.
35
+ *
36
+ * `site-settings:manage-entry-pass` is unioned in -- it is what
37
+ * `hid-amico-authz.util.ts` enforces on the entry-pass paths and the string the
38
+ * HID menu has always been associated with -- and `*` keeps its short-circuit.
39
+ *
40
+ * ## Intercom is gated with the other five
41
+ *
42
+ * `intercom` was the one screen that might have lived entirely on
43
+ * `authorizeMember` endpoints (`/intercom/status`, `/intercom/call`,
44
+ * `/intercom/hangup`). It does not. `HidIntercomManagement.reload()` opens with
45
+ * `getReaders()` (`GET /readers`, `authorizeView`) and filters its rows out of
46
+ * that response; the contacts tab, the dial-code dialog, the make-call dialog
47
+ * and the web phone are all reached from a row, and `loadSipAccount()` is only
48
+ * ever called from one of those dialogs. Without `authorizeView` the screen is
49
+ * an empty table and an error, so gating it removes nothing that works.
50
+ *
51
+ * ## Drawing, not securing
52
+ *
53
+ * The server re-decides every HID call on its own. This hides screens that do
54
+ * not work; it does not add protection the API does not already have.
55
+ */
56
+
57
+ /** The nine strings `core/utils/hid-access.util.ts` enforces, view + manage. */
58
+ const HID_ACTIONS = [
59
+ "see-all-card",
60
+ "see-all-qr-tagging",
61
+ "view",
62
+ "add-access-card",
63
+ "update-access-card",
64
+ "replace-access-card",
65
+ "delete-access-card",
66
+ "assign-access-card",
67
+ "manage-hid",
68
+ ] as const;
69
+
70
+ export function useHidAccessPermission() {
71
+ const { hasPermission } = usePermission();
72
+ const { siteSettingsPermissions } = useCommonPermissions();
73
+ const { userAppRole } = useLocalSetup();
74
+
75
+ // `hasPermission` needs BOTH the role's string AND a catalogue entry for it:
76
+ // a resource missing from the catalogue is a dead gate however the role is
77
+ // granted. `access-card-mgmt` exists in no shared catalogue composable, so it
78
+ // is built here, exactly as `useServiceProviderPermission` builds its own.
79
+ const permissions: TPermissions = {
80
+ "access-card-mgmt": Object.fromEntries(
81
+ HID_ACTIONS.map((action) => [
82
+ action,
83
+ {
84
+ check: true,
85
+ description: `Allows the user to reach the HID access management screens (${action}).`,
86
+ },
87
+ ]),
88
+ ),
89
+ "site-settings": siteSettingsPermissions,
90
+ };
91
+
92
+ /**
93
+ * Can this member open a HID `access-mgmt` screen at all? Any single string
94
+ * the server accepts is enough -- somebody granted only `delete-access-card`
95
+ * still has to open the screen to use it.
96
+ */
97
+ const canAccessHidScreens = computed(() => {
98
+ const role = userAppRole.value;
99
+ if (!role) return false;
100
+ if (role.permissions.includes("*")) return true;
101
+ if (hasPermission(role, permissions, "site-settings", "manage-entry-pass")) return true;
102
+ return HID_ACTIONS.some((action) =>
103
+ hasPermission(role, permissions, "access-card-mgmt", action),
104
+ );
105
+ });
106
+
107
+ // Only the gate is returned. `isAppRoleResolved` is deliberately NOT
108
+ // re-exported: `gate-defaults.test.mjs` sweeps every ref a permission
109
+ // composable returns and requires it to read false for an unresolved role,
110
+ // which a "has the lookup finished" flag is not. Callers that need it take it
111
+ // from `useLocalSetup()`, which is where it lives.
112
+ return { canAccessHidScreens };
113
+ }
114
+
115
+ export default useHidAccessPermission;
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.2.13",
5
+ "version": "4.2.14",
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.",