@7365admin1/layer-common 4.180.2 → 4.182.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.
@@ -163,7 +163,8 @@ export function inventoryControls(a?: Partial<TInventoryAccess> | null) {
163
163
  return {
164
164
  tabs: {
165
165
  stock: c.canView,
166
- mine: (c.canRequest || c.canUse) && !c.canManage,
166
+ // Anyone who may record usage gets My Stock, store admins included: the server allows it (manage implies use).
167
+ mine: c.canUse || (c.canRequest && !c.canManage),
167
168
  requests: c.canRequest || c.canApprove,
168
169
  people: c.canApprove || c.canHandle,
169
170
  reports: c.canReports || c.canApprove,
@@ -10,11 +10,19 @@
10
10
  * FAILS OPEN. A route that is not listed here is allowed whatever the list says.
11
11
  * Only prefixes whose page each app gates on exactly one module are listed
12
12
  * (checked against every app's own `useLocalPermission` nav gate, 2026-09-11).
13
- * Shared or ambiguous pages stay out: calendar, keys (gated on `site-settings`),
14
- * the Cards and QR Tagging pages under access-mgmt (each app's own
15
- * `access-card-mgmt` gate), equipment and inventory, service-providers and
16
- * support tickets. The HID pages under access-mgmt ARE listed, one by one,
17
- * because each is gated on `hid-mgmt` alone (`useHidAccessPermission`).
13
+ * Shared or ambiguous pages stay out: equipment (every app's Equipment URL is a
14
+ * redirect to Inventory, no page of its own), the service-provider inventory
15
+ * page, support tickets and the org-level marketplace (vendor side, not
16
+ * `marketplace-mgmt`). The Pass & Key pages (`keys`) are gated on
17
+ * `passes-and-keys-mgmt` alone in both apps that have them (DV-0396), Cards and
18
+ * QR Tagging on `access-card-mgmt`, the service-provider list on
19
+ * `service-provider-mgmt`, Property Management's site Marketplace on
20
+ * `marketplace-mgmt`, CCTV Engine on `cctv-engine` and the four Security Ops
21
+ * pages on `security-ops`, so those ARE listed (2026-11-16). `cctv-mgmt` is
22
+ * catalogue-only: no page reads it, so there is nothing to map. The HID pages
23
+ * under access-mgmt are listed one by one, because each is gated on `hid-mgmt`
24
+ * alone (`useHidAccessPermission`); Cards is the bare `access-mgmt` route, so
25
+ * every page beside it MUST be listed or it would fall under the card module.
18
26
  *
19
27
  * NEVER MAPPED: the dashboard, settings, members, invitations and roles. A client
20
28
  * must always be able to run its own people and roles; the server never denies
@@ -71,9 +79,21 @@ export const MODULE_ROUTES: Readonly<Record<string, string>> = Object.freeze({
71
79
  "org-site-pool-schedule-area": "area-mgmt",
72
80
  "org-site-pool-schedule-unit": "unit-mgmt",
73
81
  "org-site-service-provider-mgmt": "service-provider-mgmt",
82
+ // The shared service-provider list in Security, Hygiene and the other trade apps
83
+ // (and Property Management): every app's menu reads `useServiceProviderPermission`,
84
+ // which is `service-provider-mgmt` (alias `service-provider`, same spelling group).
85
+ "org-site-service-providers": "service-provider-mgmt",
86
+ "org-site-marketplace": "marketplace-mgmt",
87
+ "org-site-keys": "passes-and-keys-mgmt",
88
+ "org-site-cctv-engine": "cctv-engine",
89
+ "org-site-security-ops": "security-ops",
90
+ // Cards is the bare `access-mgmt` route; every HID page and QR Tagging below
91
+ // is longer, so it wins. A new page under access-mgmt needs its own entry.
92
+ "org-site-access-mgmt": "access-card-mgmt",
93
+ "org-site-access-mgmt-qr-tagging": "access-card-mgmt",
74
94
  // HID access management (decision of 2026-10-16): the seven HID pages under
75
- // `access-mgmt`, named one by one so the Cards and QR Tagging pages beside
76
- // them stay unmapped. `hid-mgmt` is a governed module in core, so a client
95
+ // `access-mgmt`, named one by one so they stay apart from Cards and
96
+ // QR Tagging beside them. `hid-mgmt` is a governed module in core, so a client
77
97
  // that was not given it loses the pages and the drawer group together.
78
98
  "org-site-access-mgmt-hid-readers": "hid-mgmt",
79
99
  "org-site-access-mgmt-administrator": "hid-mgmt",
@@ -133,6 +153,9 @@ export function permissionsDenied(
133
153
  return permissions.every((p) => denied.includes(String(p).split(":")[0]));
134
154
  }
135
155
 
156
+ /** Carved-out pages: shown to anyone, but never the only thing left in a trimmed group. */
157
+ const ROUTES_THAT_DONT_KEEP_A_GROUP = ["org-site-facility-settings"];
158
+
136
159
  type TRouted = { route?: { name?: unknown } | null; children?: TRouted[] };
137
160
 
138
161
  /** A menu without the pages the client was not given; a group left empty goes too. */
@@ -145,6 +168,30 @@ export function withoutDeniedRoutes<T extends TRouted>(
145
168
  if (routeDenied(item.route?.name, denied)) return [];
146
169
  if (!item.children?.length) return [item];
147
170
  const children = withoutDeniedRoutes(item.children as T[], denied);
148
- return children.length ? [{ ...item, children }] : [];
171
+ // A page carved out of its module (Facility Settings) must not keep a group
172
+ // alive on its own once the group's module pages were taken away.
173
+ const lost = children.length < item.children.length;
174
+ const stray = children.every((c) => ROUTES_THAT_DONT_KEEP_A_GROUP.includes(String(c.route?.name)));
175
+ return children.length && !(lost && stray) ? [{ ...item, children }] : [];
149
176
  });
150
177
  }
178
+
179
+ /**
180
+ * A permission catalogue (`{ resource: actions }`, what `RolePermissionMain`
181
+ * takes) without the modules the client's list took away, so a role editor
182
+ * never offers a box the client cannot use (owner, 2026-11-16). `denied` is the
183
+ * server's deny list (`useLocalSetup().userAppModulesDenied`), which already
184
+ * covers a list saved with nothing ticked and never holds an always-allowed
185
+ * module. No deny list: the same object back.
186
+ */
187
+ export function withoutDeniedResources<T extends Record<string, unknown>>(
188
+ catalogue: T,
189
+ denied: readonly string[] | null | undefined,
190
+ ): T {
191
+ if (!Array.isArray(denied) || !denied.length || !catalogue || typeof catalogue !== "object") {
192
+ return catalogue;
193
+ }
194
+ return Object.fromEntries(
195
+ Object.entries(catalogue).filter(([resource]) => !denied.includes(resource.trim())),
196
+ ) as T;
197
+ }