@7365admin1/layer-common 4.3.0 → 4.4.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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @iservice365/layer-common
2
2
 
3
+ ## 4.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 9854dc5: The role editor now offers only the catalogue modules Seven365 has given the client (`organizations.modules`, core 3.62.0). Absent and empty both mean EVERYTHING and every uncertainty fails open — a failed lookup, an unreadable key, or a list matching nothing all show the full catalogue — so no existing client sees any change until Seven365 sets a list.
8
+
9
+ ## 4.3.1
10
+
11
+ ### Patch Changes
12
+
13
+ - 54579b3: Fix two permission strings that resolved to nothing for live production members: alias `work-orders:see-work-order-details` to the canonical `work_orders:` spelling (4 roles, 8 members), and offer `virtual-patrol:see-all-virtual-patrols` in the security picker, which `core` and `web-app-property-management` already enforce but no picker offered (1 role, 5 members). Catalogue and alias only — nothing is granted to anybody.
14
+
3
15
  ## 4.3.0
4
16
 
5
17
  ### Minor Changes
@@ -848,11 +860,11 @@
848
860
  `utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
849
861
  own rule from two endpoints the console already calls, unprojected:
850
862
 
851
- GET /api/members/user/:user/app/admin the Seven365 staff membership
852
- GET /api/roles/id/:role that membership's role document
863
+ GET /api/members/user/:user/app/admin the Seven365 staff membership
864
+ GET /api/roles/id/:role that membership's role document
853
865
 
854
- owner = member.type === "admin" && role.type === "admin" && role.default === true
855
- staff = member.type === "admin" && role.type === "admin"
866
+ owner = member.type === "admin" && role.type === "admin" && role.default === true
867
+ staff = member.type === "admin" && role.type === "admin"
856
868
 
857
869
  `role.default` is the marker because it is the only property of a platform
858
870
  staff role no API caller can set - `role.controller.ts` validates create and
@@ -365,16 +365,33 @@ watchEffect(() => {
365
365
 
366
366
  const roles = ref<Array<Record<string, any>>>([]);
367
367
 
368
- const { getRoles } = useRole();
368
+ /*
369
+ * This asked for the organisation's own roles ONLY, so it silently withheld the
370
+ * ORG-LESS template roles -- and those are not an edge case: on staging 341 of
371
+ * the 942 role-carrying invitations name one, and `core invite-role-scope.util
372
+ * roleInvitable` accepts them explicitly ("a role with no `org` is a TEMPLATE
373
+ * role"). Onboarding's "Invite Org Admin" and "Invite Site Admin" are the two
374
+ * screens that mount this form, and a brand-new organisation is exactly the
375
+ * case with no roles of its own yet, so the picker could be empty at the one
376
+ * moment it matters most.
377
+ *
378
+ * `getInvitableRoles` is the union the server accepts: the organisation's own
379
+ * roles (still filtered by `props.app`, so nothing that is offered today stops
380
+ * being offered) PLUS the org-less templates, MINUS the `type: "admin"`
381
+ * Seven365 console roles that `roleInvitable` refuses on any non-staff
382
+ * invitation. Widening, except for options that could only ever be picked and
383
+ * then rejected.
384
+ */
385
+ const { getInvitableRoles } = useRole();
369
386
 
370
387
  const { data: RolesData, refresh: refreshRoles } = await useLazyAsyncData(
371
388
  "get-roles-by-type-" + props.org + "-" + props.app,
372
389
  () =>
373
- getRoles({
374
- org: props.org,
375
- type: props.app,
376
- limit: 50,
377
- }),
390
+ getInvitableRoles({
391
+ org: props.org,
392
+ type: props.app,
393
+ limit: 50,
394
+ }),
378
395
  { watch: [() => props.app] }
379
396
  );
380
397
 
@@ -471,9 +471,50 @@ function setMember({
471
471
  }
472
472
 
473
473
  const roles = ref<Array<Record<string, any>>>([]);
474
+ /*
475
+ * THE ROLES THIS SCREEN MAY ASSIGN.
476
+ *
477
+ * Two defects were fixed here together, because fixing either alone leaves the
478
+ * picker wrong.
479
+ *
480
+ * 1. `limit: 20`. The server caps `limit` at 100 and defaults to 10
481
+ * (`core role.controller.ts:320`), and this screen asked for 20 and never
482
+ * paged. One live organisation already has 47 active
483
+ * `property_management_agency` roles, so 27 of its roles could not be
484
+ * assigned to anybody from this screen at all -- the list simply stopped.
485
+ * 100 is the validated ceiling, not a guess.
486
+ *
487
+ * 2. No `site`. A role created on a site CARRIES that site, and
488
+ * `RolePermissionMain` was fixed to send it so the role editor stops listing
489
+ * other estates' roles -- but this screen, which is what actually hands a
490
+ * role to a person, was never given the same scope. So a site's member page
491
+ * offered every other site's roles for assignment.
492
+ *
493
+ * Passing `site` cannot hide an organisation-wide role: `core role.repo.ts:304`
494
+ * matches `{ site }` OR `{ site: "" }` OR `{ site: null }`, which covers every
495
+ * role created before the field existed. Measured against staging before
496
+ * changing anything: of 397 active memberships, 47 hold a site-pinned role and
497
+ * 6 hold one pinned to a DIFFERENT site than the membership. All six are test
498
+ * accounts, and none loses access -- `selectedRole` below is seeded from the
499
+ * membership itself, not from this list, so an unlisted current role still
500
+ * submits unchanged.
501
+ *
502
+ * `props.siteId` is empty on the organisation-level and console member screens,
503
+ * and an empty `site` is a no-op server-side (`if (site)`), so those are
504
+ * unchanged. The site is part of the cache key on purpose: without it the first
505
+ * site to ask would answer for the next one out of Nuxt's payload cache and the
506
+ * filter would be decorative -- the same trap the server's own Redis key had.
507
+ */
474
508
  const { getRoles } = useRole();
475
- const { data: getAllRoleReq } = useLazyAsyncData(`get-roles-${props.type}-${props.orgId}`, () =>
476
- getRoles({ org: props.orgId, type: props.type, limit: 20 })
509
+ const { data: getAllRoleReq } = useLazyAsyncData(
510
+ `get-roles-${props.type}-${props.orgId}-${props.siteId}`,
511
+ () =>
512
+ getRoles({
513
+ org: props.orgId,
514
+ type: props.type,
515
+ site: props.siteId,
516
+ limit: 100,
517
+ })
477
518
  );
478
519
 
479
520
  watchEffect(() => {
@@ -73,7 +73,7 @@
73
73
  <StatusChip
74
74
  :dot="false"
75
75
  tone="info"
76
- :label="String(getPermissionCount(value))"
76
+ :label="getPermissionCount(value)"
77
77
  />
78
78
  </template>
79
79
 
@@ -96,7 +96,7 @@
96
96
  <v-dialog v-model="createDialog" width="500" persistent>
97
97
  <RolePermissionFormCreate
98
98
  @cancel="createDialog = false"
99
- :permissions="props.permissions"
99
+ :permissions="offeredPermissions"
100
100
  :org="props.orgId"
101
101
  :site-id="props.siteId"
102
102
  :site-state="siteFieldShown"
@@ -202,6 +202,7 @@
202
202
  // Relative import: this layer's `utils/` is not auto-imported into consumers.
203
203
  import { showSiteField } from "../utils/role";
204
204
  import { holdsPermission } from "../utils/permission-spellings";
205
+ import { catalogueForOrg } from "../utils/org-modules";
205
206
 
206
207
  const props = defineProps({
207
208
  orgId: {
@@ -304,6 +305,38 @@ const props = defineProps({
304
305
 
305
306
  const { headerSearch } = useLocal();
306
307
 
308
+ /*
309
+ * THE CATALOGUE THIS CLIENT IS ACTUALLY OFFERED.
310
+ *
311
+ * Owner brief 2026-09-09: Seven365 decides which modules a client gets. Until
312
+ * now every client's role editor offered the same 127-entry catalogue whether
313
+ * they bought one service or seven.
314
+ *
315
+ * FAILS OPEN, everywhere. No organisation has a `modules` list today, so absent
316
+ * means EVERYTHING - and so does an empty list, an unreadable one, a failed
317
+ * request, and a list that matches nothing at all. The `.catch` matters as much
318
+ * as the rule: a role editor that empties itself because a lookup timed out is
319
+ * indistinguishable from a broken screen.
320
+ *
321
+ * DRAWS, does not AUTHORISE. The server re-decides every request from the role
322
+ * the caller holds; this only decides which boxes exist to tick.
323
+ */
324
+ const { getById: _getOrgForModules } = useOrg();
325
+
326
+ const { data: orgForModules } = useLazyAsyncData(
327
+ `org-modules-${props.orgId}`,
328
+ () =>
329
+ props.orgId
330
+ ? _getOrgForModules(props.orgId).catch(() => null)
331
+ : Promise.resolve(null),
332
+ { watch: [() => props.orgId] }
333
+ );
334
+
335
+ /** `props.permissions`, narrowed to what Seven365 gave this client. */
336
+ const offeredPermissions = computed(() =>
337
+ catalogueForOrg(props.permissions ?? {}, (orgForModules.value as any)?.modules)
338
+ );
339
+
307
340
  const { getRoles: _getRoles } = useRole();
308
341
 
309
342
  const page = ref(1);
@@ -410,8 +443,34 @@ const edit = ref(false);
410
443
 
411
444
  const roleId = ref("");
412
445
 
413
- function getPermissionCount(permissions: unknown): number {
414
- return Array.isArray(permissions) ? permissions.length : 0;
446
+ /*
447
+ * The chip counted only what a role HOLDS, so every role read "3" or "0" with
448
+ * nothing to compare it against -- and a role with none of them read a bare
449
+ * "0", which looks like a broken row rather than "nothing granted yet". It now
450
+ * reads `held / offered`, where `offered` is the size of the catalogue this
451
+ * screen was handed (`props.permissions`, the same tree the editor ticks).
452
+ *
453
+ * A role holding the `*` wildcard is shown as "All": its stored array has ONE
454
+ * entry, so counting it would have printed "1 / 127" for the role that can do
455
+ * everything -- the most misleading number on the screen.
456
+ *
457
+ * Display only. Nothing here decides what anybody may do; the ticks in the
458
+ * editor and the server's own checks are untouched.
459
+ */
460
+ const permissionCatalogueSize = computed(() =>
461
+ Object.values(offeredPermissions.value ?? {}).reduce(
462
+ (total: number, actions: any) =>
463
+ total + Object.keys(actions ?? {}).length,
464
+ 0
465
+ )
466
+ );
467
+
468
+ function getPermissionCount(permissions: unknown): string {
469
+ const held = Array.isArray(permissions) ? permissions : [];
470
+ if (held.includes("*")) return "All";
471
+
472
+ const offered = permissionCatalogueSize.value;
473
+ return offered > 0 ? `${held.length} / ${offered}` : String(held.length);
415
474
  }
416
475
 
417
476
  function updateRolePermissionsInList(
@@ -480,8 +539,8 @@ function filterPermissions(
480
539
 
481
540
  const Permissions = computed(() => {
482
541
  return edit.value
483
- ? props.permissions
484
- : filterPermissions(props.permissions, originalPermissions.value);
542
+ ? offeredPermissions.value
543
+ : filterPermissions(offeredPermissions.value, originalPermissions.value);
485
544
  });
486
545
 
487
546
  function successfulUpdate() {
@@ -55,18 +55,27 @@ export default function useRole() {
55
55
  * deliberately does not check a role's site, because a site is not a tenant
56
56
  * boundary. A site-scoped screen still gets the organisation's site-less
57
57
  * roles, because `getRoles` matches those too.
58
+ *
59
+ * `type` narrows the TENANT half only, and is there so a caller that already
60
+ * filters by membership type keeps exactly the list it has today and only
61
+ * GAINS the org-less templates. The template read stays on
62
+ * `type: "organization"` whatever is passed: an org-less role is a template
63
+ * for any app, and `roleInvitable` does not compare a role's type against the
64
+ * invitation's app at all -- it only refuses the platform-staff type, which
65
+ * the `admin` filter below already drops.
58
66
  */
59
67
  async function getInvitableRoles(
60
- { search = "", org = "", site = "", limit = 50 } = {} as {
68
+ { search = "", org = "", site = "", type = "", limit = 50 } = {} as {
61
69
  search?: string;
62
70
  org?: string;
63
71
  site?: string;
72
+ type?: string;
64
73
  limit?: number;
65
74
  }
66
75
  ) {
67
76
  const [tenant, templates] = await Promise.all([
68
77
  org
69
- ? getRoles({ search, org, site, limit })
78
+ ? getRoles({ search, org, site, type, limit })
70
79
  : Promise.resolve({ items: [] } as Record<string, any>),
71
80
  getRoles({ search, type: "organization", limit }),
72
81
  ]);
@@ -219,6 +219,29 @@ export default function useSecurityPermission() {
219
219
  description:
220
220
  "Allows the user to remove a question from the system permanently.",
221
221
  },
222
+ /*
223
+ * ENFORCED BY THE SERVER, OFFERED BY NOBODY — until now.
224
+ *
225
+ * `see-all-virtual-patrols` is the umbrella "see the patrols" right, as
226
+ * distinct from the route / question / log families around it. It is
227
+ * checked in `core` and in `web-app-property-management`, and it appeared
228
+ * in NO picker in the estate, so no role could ever be granted it and the
229
+ * check behind it answered only to `*` or an empty list.
230
+ *
231
+ * Not hypothetical: measured on PRODUCTION 2026-09-09, one active role
232
+ * holds it with **5 live members** behind it — granted before the picker
233
+ * lost it, and ungrantable to anybody since.
234
+ *
235
+ * Catalogue-only. This widens what may be OFFERED and grants nothing to
236
+ * anybody: an unticked action stays refused, exactly as it is today. Same
237
+ * shape as the nine `access-card-mgmt` strings that were added for the
238
+ * same reason.
239
+ */
240
+ "see-all-virtual-patrols": {
241
+ check: true,
242
+ description:
243
+ "Allows the user to view all virtual patrols.",
244
+ },
222
245
  "add-virtual-patrol-log": {
223
246
  check: true,
224
247
  description: "Allows the user to add a new log to the system.",
@@ -525,6 +525,13 @@ export const LEGACY_PERMISSION_ALIASES: Readonly<
525
525
  // ships this spelling.
526
526
  "work-orders:create-work-order": "work_orders:create-work-order",
527
527
  "work-orders:see-all-work-orders": "work_orders:see-all-work-orders",
528
+ // The sibling that was missed. Every other hyphenated work-order spelling is
529
+ // aliased here, and `workOrder:see-work-order-details` and
530
+ // `work_order:see-work-order-details` both are too — this one, alone, was
531
+ // not. Measured on PRODUCTION 2026-09-09: **4 active roles hold it, with 8
532
+ // live members behind them**, and it resolved to nothing, so those people
533
+ // could not open a work order's details however the role was ticked.
534
+ "work-orders:see-work-order-details": "work_orders:see-work-order-details",
528
535
  "work-orders:update-work-order": "work_orders:update-work-order",
529
536
  "work-orders:delete-work-order": "work_orders:delete-work-order",
530
537
  // Needed by: `-security`, which says `add-` where every other app says
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.3.0",
5
+ "version": "4.4.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.",
@@ -0,0 +1,74 @@
1
+ /**
2
+ * NARROW A ROLE CATALOGUE TO THE MODULES SEVEN365 GAVE THIS CLIENT.
3
+ *
4
+ * The client half of `core src/utils/org-modules.util.ts`, and deliberately a
5
+ * COPY rather than an import: this package cannot depend on `@7365admin1/core`
6
+ * (it is the frontend layer, and `core` is a server package). The copy is
7
+ * fifteen lines and fails open, and `test/org-module-catalogue.test.mjs` pins it
8
+ * against the same cases the server's tests use.
9
+ *
10
+ * ## What this is for
11
+ *
12
+ * Owner brief, 2026-09-09: *"Seven365 will give the modules that they only need
13
+ * on the application/services that they want."* Every client's role editor
14
+ * currently offers the same 127-entry catalogue whether they bought one service
15
+ * or seven, which is a large part of why roles and permissions read as
16
+ * confusing.
17
+ *
18
+ * ## It DRAWS, it does not AUTHORISE
19
+ *
20
+ * This decides what the role EDITOR offers. It is not an access boundary: the
21
+ * server re-decides every request from the role the caller actually holds, and a
22
+ * permission already granted keeps working whatever this list says. Removing a
23
+ * module does not revoke anything — it stops the module being offered the next
24
+ * time somebody edits a role.
25
+ *
26
+ * ## Absent and empty both mean EVERYTHING
27
+ *
28
+ * No organisation has a `modules` field today. If absent meant "nothing", this
29
+ * would empty the role editor for every client the moment it deployed. It fails
30
+ * open on every uncertainty — a missing list, a non-array, an unreadable key,
31
+ * and a list that matches nothing at all.
32
+ */
33
+
34
+ /** May this client's role editor OFFER this module? Fails open. */
35
+ export function orgAllowsModule(
36
+ modules: readonly string[] | null | undefined,
37
+ resource: string | null | undefined,
38
+ ): boolean {
39
+ if (!Array.isArray(modules) || modules.length === 0) return true;
40
+
41
+ const key = typeof resource === "string" ? resource.trim() : "";
42
+ if (!key) return true;
43
+
44
+ return modules.includes(key);
45
+ }
46
+
47
+ /**
48
+ * Narrow a catalogue — `{ resource: { action: {...} } }`, the shape every
49
+ * `use*Permission` returns and `RolePermissionMain` takes as a prop.
50
+ *
51
+ * Given no list the catalogue is returned UNCHANGED (the same object, not a
52
+ * copy), so the default path costs nothing and cannot subtly reorder anything.
53
+ */
54
+ export function catalogueForOrg<T extends Record<string, unknown>>(
55
+ catalogue: T,
56
+ modules: readonly string[] | null | undefined,
57
+ ): T {
58
+ if (!Array.isArray(modules) || modules.length === 0) return catalogue;
59
+ if (!catalogue || typeof catalogue !== "object") return catalogue;
60
+
61
+ const narrowed: Record<string, unknown> = {};
62
+ for (const [resource, actions] of Object.entries(catalogue)) {
63
+ if (orgAllowsModule(modules, resource)) narrowed[resource] = actions;
64
+ }
65
+
66
+ /*
67
+ * A list that matched NOTHING shows the whole catalogue rather than an empty
68
+ * one. A blank role editor is indistinguishable from a broken screen, and the
69
+ * likeliest cause of matching nothing is a console typo or a catalogue whose
70
+ * resource keys were renamed — neither of which should take the editor away
71
+ * from the client.
72
+ */
73
+ return (Object.keys(narrowed).length ? narrowed : catalogue) as T;
74
+ }