@7365admin1/layer-common 4.2.29 → 4.3.1

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.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 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.
8
+
9
+ ## 4.3.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 9d151eb: release switching to different organization with app redirection
14
+
3
15
  ## 4.2.29
4
16
 
5
17
  ### Patch Changes
@@ -842,11 +854,11 @@
842
854
  `utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
843
855
  own rule from two endpoints the console already calls, unprojected:
844
856
 
845
- GET /api/members/user/:user/app/admin the Seven365 staff membership
846
- GET /api/roles/id/:role that membership's role document
857
+ GET /api/members/user/:user/app/admin the Seven365 staff membership
858
+ GET /api/roles/id/:role that membership's role document
847
859
 
848
- owner = member.type === "admin" && role.type === "admin" && role.default === true
849
- staff = member.type === "admin" && role.type === "admin"
860
+ owner = member.type === "admin" && role.type === "admin" && role.default === true
861
+ staff = member.type === "admin" && role.type === "admin"
850
862
 
851
863
  `role.default` is the marker because it is the only property of a platform
852
864
  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
 
@@ -410,8 +410,34 @@ const edit = ref(false);
410
410
 
411
411
  const roleId = ref("");
412
412
 
413
- function getPermissionCount(permissions: unknown): number {
414
- return Array.isArray(permissions) ? permissions.length : 0;
413
+ /*
414
+ * The chip counted only what a role HOLDS, so every role read "3" or "0" with
415
+ * nothing to compare it against -- and a role with none of them read a bare
416
+ * "0", which looks like a broken row rather than "nothing granted yet". It now
417
+ * reads `held / offered`, where `offered` is the size of the catalogue this
418
+ * screen was handed (`props.permissions`, the same tree the editor ticks).
419
+ *
420
+ * A role holding the `*` wildcard is shown as "All": its stored array has ONE
421
+ * entry, so counting it would have printed "1 / 127" for the role that can do
422
+ * everything -- the most misleading number on the screen.
423
+ *
424
+ * Display only. Nothing here decides what anybody may do; the ticks in the
425
+ * editor and the server's own checks are untouched.
426
+ */
427
+ const permissionCatalogueSize = computed(() =>
428
+ Object.values(props.permissions ?? {}).reduce(
429
+ (total: number, actions: any) =>
430
+ total + Object.keys(actions ?? {}).length,
431
+ 0
432
+ )
433
+ );
434
+
435
+ function getPermissionCount(permissions: unknown): string {
436
+ const held = Array.isArray(permissions) ? permissions : [];
437
+ if (held.includes("*")) return "All";
438
+
439
+ const offered = permissionCatalogueSize.value;
440
+ return offered > 0 ? `${held.length} / ${offered}` : String(held.length);
415
441
  }
416
442
 
417
443
  function updateRolePermissionsInList(
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Where each line of business lives.
3
+ *
4
+ * An organisation's `nature` says which of the seven vertical apps it belongs
5
+ * to, and every one of those apps' base URLs is already in this layer's
6
+ * runtime config. Without this map each app had to carry its own copy, which is
7
+ * how a switcher ends up able to LIST an organisation it cannot open.
8
+ *
9
+ * `real_estate_developer` is deliberately absent: it is an allowed nature with
10
+ * no app of its own, and `appUrl` answers "" for it rather than guessing.
11
+ */
12
+ const APP_URL_KEY_BY_NATURE: Record<string, string> = {
13
+ security_agency: "APP_SECURITY",
14
+ property_management_agency: "APP_PROPERTY_MANAGEMENT",
15
+ cleaning_services: "APP_HYGIENE",
16
+ mechanical_electrical_services: "APP_MECHANICAL_ELECTRICAL",
17
+ pest_control_services: "APP_PEST_CONTROL",
18
+ landscaping_services: "APP_LANDSCAPING",
19
+ pool_maintenance_services: "APP_POOL_MAINTENANCE",
20
+ };
21
+
22
+ export default function useAppLinks() {
23
+ const config = useRuntimeConfig().public as unknown as Record<string, string>;
24
+
25
+ /** The base URL of the app this nature belongs to, or "" when there is none. */
26
+ function appUrl(nature = ""): string {
27
+ const key = APP_URL_KEY_BY_NATURE[nature];
28
+
29
+ return key ? config[key] || "" : "";
30
+ }
31
+
32
+ /**
33
+ * Where to land somebody switching into `org`. Returns "" when the app is
34
+ * unknown or unconfigured, so a caller can fall back to navigating locally
35
+ * rather than sending them to a broken URL.
36
+ */
37
+ function appDashboardUrl(nature = "", org = "", site = ""): string {
38
+ const base = appUrl(nature);
39
+
40
+ return base ? `${base}/${org}/${site || "site"}/dashboard` : "";
41
+ }
42
+
43
+ return { appUrl, appDashboardUrl, APP_URL_KEY_BY_NATURE };
44
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * WHICH SITE to open an organisation at.
3
+ *
4
+ * `organizations.defaultSite` is the intended answer - `customer-site.service`
5
+ * sets it to the first site an organisation is ever given - but it is not a
6
+ * guarantee:
7
+ *
8
+ * - an organisation abandoned before the site step has none at all, and the
9
+ * switcher can list it, because the list is every organisation you belong
10
+ * to rather than every one that is finished;
11
+ * - a `defaultSite` can name a site that has since been removed or is no
12
+ * longer active, and the sites list is the only thing that knows.
13
+ *
14
+ * Both used to end the same way: the app built `…/<org>/site/dashboard` with
15
+ * the literal word "site" where an id belongs. So the stored answer is CHECKED
16
+ * against the list, and the first live site stands in when it does not hold up.
17
+ */
18
+ export default function useOrgSite() {
19
+ const { getAll } = useCustomerSite();
20
+
21
+ /**
22
+ * The site id to open `org` at, or "" when it has no usable site.
23
+ *
24
+ * `preferred` is tried first and kept only if the organisation really has it.
25
+ * A failed lookup falls back to `preferred` rather than blocking the switch -
26
+ * a stale id is still a better guess than a placeholder.
27
+ */
28
+ async function resolveOrgSite(org = "", preferred = ""): Promise<string> {
29
+ if (!org) return "";
30
+
31
+ const clean = preferred && preferred !== "site" ? preferred : "";
32
+
33
+ const response: any = await getAll({ org, limit: 50 }).catch(() => null);
34
+
35
+ if (!response) return clean;
36
+
37
+ const items: any[] = response?.items ?? [];
38
+
39
+ // Customer-site rows carry the site id in `.site`; a raw site document
40
+ // carries its own `._id`. Accept either, the same way onboarding does.
41
+ const ids = items
42
+ .map((item) => String(item?.site || item?._id || ""))
43
+ .filter(Boolean);
44
+
45
+ if (clean && ids.includes(clean)) return clean;
46
+
47
+ return ids[0] || "";
48
+ }
49
+
50
+ return { resolveOrgSite };
51
+ }
@@ -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.2.29",
5
+ "version": "4.3.1",
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.",