@7365admin1/layer-common 4.2.13 → 4.2.15

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,35 @@
1
1
  # @iservice365/layer-common
2
2
 
3
+ ## 4.2.15
4
+
5
+ ### Patch Changes
6
+
7
+ - b63f7a6: Hide the HID Face Reader menu from members who cannot open the screens
8
+
9
+ The menu was drawn from `getHidServiceEnabled(site)` — a site service flag, not
10
+ a permission — so a member with no access-card right saw all five items and only
11
+ met the refusal after clicking. `useHidNavigation` now asks the same question the
12
+ pages ask (`useHidAccessPermission.canAccessHidScreens`), ANDed with the service
13
+ flag. The duplicate, narrower permission list in `Layout/NavigationDrawer.vue` is
14
+ removed; folding it into the shared gate widens it (it omitted
15
+ `replace-access-card` and `site-settings:manage-entry-pass`).
16
+
17
+ ## 4.2.14
18
+
19
+ ### Patch Changes
20
+
21
+ - 1d22a74: Gate the six HID access-mgmt screens on the access-card-mgmt permissions the API already enforces
22
+
23
+ The access-logs, administrator, hid-cards, hid-readers, hid-users and intercom
24
+ pages carried no permission check, so any member of any organisation could type
25
+ the URL and reach door access, biometric enrolment, physical cards and the
26
+ access log. HidEnabledGate now also requires the caller to hold one of the nine
27
+ access-card-mgmt strings, site-settings:manage-entry-pass, or the wildcard.
28
+
29
+ Those are the same strings /api/access-management/hid already enforces, so the
30
+ set now refused is a strict subset of the set the API refuses today: nobody with
31
+ a working screen loses it.
32
+
3
33
  ## 4.2.13
4
34
 
5
35
  ### Patch Changes
@@ -595,11 +625,11 @@
595
625
  `utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
596
626
  own rule from two endpoints the console already calls, unprojected:
597
627
 
598
- GET /api/members/user/:user/app/admin the Seven365 staff membership
599
- GET /api/roles/id/:role that membership's role document
628
+ GET /api/members/user/:user/app/admin the Seven365 staff membership
629
+ GET /api/roles/id/:role that membership's role document
600
630
 
601
- owner = member.type === "admin" && role.type === "admin" && role.default === true
602
- staff = member.type === "admin" && role.type === "admin"
631
+ owner = member.type === "admin" && role.type === "admin" && role.default === true
632
+ staff = member.type === "admin" && role.type === "admin"
603
633
 
604
634
  `role.default` is the marker because it is the only property of a platform
605
635
  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
@@ -169,30 +169,10 @@ const { menuItem: hidFaceReaderMenu } = useHidFaceReaderMenu({
169
169
  cacheKey: "layout-navigation-hid-site",
170
170
  });
171
171
 
172
- const HID_NAVIGATION_PERMISSIONS = [
173
- "access-card-mgmt:see-all-card",
174
- "access-card-mgmt:see-all-qr-tagging",
175
- "access-card-mgmt:view",
176
- "access-card-mgmt:add-access-card",
177
- "access-card-mgmt:update-access-card",
178
- "access-card-mgmt:delete-access-card",
179
- "access-card-mgmt:assign-access-card",
180
- "access-card-mgmt:manage-hid",
181
- ];
182
-
183
- const { userAppRole } = useLocalSetup();
184
- const canAccessHid = computed(() => {
185
- const permissions = userAppRole.value?.permissions ?? [];
186
- return permissions.includes("*") || HID_NAVIGATION_PERMISSIONS.some(
187
- (permission) => permissions.includes(permission),
188
- );
189
- });
190
-
191
172
  const navigationItems = computed(() => {
192
173
  const items = [...(props.navigationItems as TNavigationItem[])];
193
174
 
194
175
  if (
195
- canAccessHid.value &&
196
176
  hidFaceReaderMenu.value &&
197
177
  !items.some((item) => item.title === hidFaceReaderMenu.value?.title)
198
178
  ) {
@@ -0,0 +1,124 @@
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
+ /**
58
+ * The nine strings `core/utils/hid-access.util.ts` enforces, view + manage.
59
+ *
60
+ * Written out in full `resource:action` form on purpose. `permission-vocabulary`
61
+ * harvests what this package checks by reading literals out of the source, and a
62
+ * bare action fed through a loop into `hasPermission(role, cat, "access-card-mgmt",
63
+ * action)` is invisible to it. Spelling the strings out keeps all nine visible.
64
+ */
65
+ const HID_PERMISSIONS = [
66
+ "access-card-mgmt:see-all-card",
67
+ "access-card-mgmt:see-all-qr-tagging",
68
+ "access-card-mgmt:view",
69
+ "access-card-mgmt:add-access-card",
70
+ "access-card-mgmt:update-access-card",
71
+ "access-card-mgmt:replace-access-card",
72
+ "access-card-mgmt:delete-access-card",
73
+ "access-card-mgmt:assign-access-card",
74
+ "access-card-mgmt:manage-hid",
75
+ ] as const;
76
+
77
+ const HID_ACTIONS = HID_PERMISSIONS.map((p) => p.split(":")[1]);
78
+
79
+ export function useHidAccessPermission() {
80
+ const { hasPermission } = usePermission();
81
+ const { siteSettingsPermissions } = useCommonPermissions();
82
+ const { userAppRole } = useLocalSetup();
83
+
84
+ // `hasPermission` needs BOTH the role's string AND a catalogue entry for it:
85
+ // a resource missing from the catalogue is a dead gate however the role is
86
+ // granted. `access-card-mgmt` exists in no shared catalogue composable, so it
87
+ // is built here, exactly as `useServiceProviderPermission` builds its own.
88
+ const permissions: TPermissions = {
89
+ "access-card-mgmt": Object.fromEntries(
90
+ HID_ACTIONS.map((action) => [
91
+ action,
92
+ {
93
+ check: true,
94
+ description: `Allows the user to reach the HID access management screens (${action}).`,
95
+ },
96
+ ]),
97
+ ),
98
+ "site-settings": siteSettingsPermissions,
99
+ };
100
+
101
+ /**
102
+ * Can this member open a HID `access-mgmt` screen at all? Any single string
103
+ * the server accepts is enough -- somebody granted only `delete-access-card`
104
+ * still has to open the screen to use it.
105
+ */
106
+ const canAccessHidScreens = computed(() => {
107
+ const role = userAppRole.value;
108
+ if (!role) return false;
109
+ if (role.permissions.includes("*")) return true;
110
+ if (hasPermission(role, permissions, "site-settings", "manage-entry-pass")) return true;
111
+ return HID_ACTIONS.some((action) =>
112
+ hasPermission(role, permissions, "access-card-mgmt", action),
113
+ );
114
+ });
115
+
116
+ // Only the gate is returned. `isAppRoleResolved` is deliberately NOT
117
+ // re-exported: `gate-defaults.test.mjs` sweeps every ref a permission
118
+ // composable returns and requires it to read false for an unresolved role,
119
+ // which a "has the lookup finished" flag is not. Callers that need it take it
120
+ // from `useLocalSetup()`, which is where it lives.
121
+ return { canAccessHidScreens };
122
+ }
123
+
124
+ export default useHidAccessPermission;
@@ -1,5 +1,27 @@
1
1
  import type { ComputedRef, Ref } from "vue";
2
2
 
3
+ /**
4
+ * THE HID FACE READER MENU IS A PERMISSION, NOT A SERVICE FLAG.
5
+ *
6
+ * This composable used to draw the five-item "HID Face Reader" group whenever
7
+ * `getHidServiceEnabled(site)` was true. That is a SITE SERVICE FLAG — it says
8
+ * the estate bought HID, not that this member may use it. Since the six
9
+ * `access-mgmt` screens were gated (`HidEnabledGate.vue`, layer-common #1363 /
10
+ * 4.2.14) a member without an access-card right still saw all five items and
11
+ * only met the refusal after clicking. A module a member cannot use should not
12
+ * be in the menu at all.
13
+ *
14
+ * The menu now asks the SAME question the pages ask —
15
+ * `useHidAccessPermission().canAccessHidScreens` — ANDed with the service flag,
16
+ * so no HID service still means no menu.
17
+ *
18
+ * `Layout/NavigationDrawer.vue` used to keep its own hand-written copy of the
19
+ * permission list, and that copy was NARROWER than the page gate: it omitted
20
+ * `replace-access-card` and `site-settings:manage-entry-pass`. Folding it in
21
+ * here therefore WIDENS — nobody who could see the menu can lose it — and
22
+ * leaves one list in one place.
23
+ */
24
+
3
25
  type HidNavigationParams = {
4
26
  org: string;
5
27
  site: string;
@@ -10,6 +32,7 @@ type HidNavigationSite = Record<string, unknown>;
10
32
  export default function useHidNavigation() {
11
33
  const { getSiteById } = useSiteSettings();
12
34
  const { getHidServiceEnabled } = useOptionalServices();
35
+ const { canAccessHidScreens } = useHidAccessPermission();
13
36
 
14
37
  function getHidFaceReaderMenu({ org, site }: HidNavigationParams) {
15
38
  return {
@@ -86,16 +109,22 @@ export default function useHidNavigation() {
86
109
  { immediate: true },
87
110
  );
88
111
 
89
- const enabled = computed(() =>
112
+ // The site bought HID.
113
+ const serviceEnabled = computed(() =>
90
114
  getHidServiceEnabled(site.value, siteDetails.value || fallbackSite?.value),
91
115
  );
92
116
 
117
+ // ...AND this member may open the screens behind it. `enabled` keeps its
118
+ // name and its meaning for callers: "should the HID menu be drawn".
119
+ const enabled = computed(() => serviceEnabled.value && canAccessHidScreens.value);
120
+
93
121
  const menuItem = computed(() =>
94
122
  enabled.value ? getHidFaceReaderMenu({ org: org.value, site: site.value }) : null,
95
123
  );
96
124
 
97
125
  return {
98
126
  enabled,
127
+ serviceEnabled,
99
128
  menuItem,
100
129
  siteDetails,
101
130
  };
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.15",
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.",