@7365admin1/layer-common 4.9.1-staging.307 → 4.9.1-staging.309
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/components/DashboardMain.vue +17 -5
- package/components/Layout/NavigationDrawer.vue +8 -2
- package/components/MemberMain.vue +10 -1
- package/components/RolePermissionMain.vue +7 -2
- package/composables/useLocalSetup.ts +7 -0
- package/composables/useMember.ts +11 -0
- package/package.json +1 -1
- package/plugins/secure-member.client.ts +60 -2
- package/utils/module-routes.ts +128 -0
- package/utils/org-modules.ts +26 -0
- package/utils/role.ts +18 -0
|
@@ -1226,6 +1226,7 @@ import type { CookieOptions } from "#app";
|
|
|
1226
1226
|
// its utils by relative path (`StatusChip.vue`, `CameraWall.vue`,
|
|
1227
1227
|
// `plugins/vuetify.ts`), and a bare call resolved to nothing when driven.
|
|
1228
1228
|
import { buildWorkOrderStatus } from "../utils/dashboard";
|
|
1229
|
+
import { permissionsDenied } from "../utils/module-routes";
|
|
1229
1230
|
|
|
1230
1231
|
// ─── Types ────────────────────────────────────────────────────────────────────
|
|
1231
1232
|
|
|
@@ -1372,7 +1373,7 @@ const {
|
|
|
1372
1373
|
getDashboardHygieneFeedbacks,
|
|
1373
1374
|
} = useDashboard();
|
|
1374
1375
|
|
|
1375
|
-
const { userAppRole } = useLocalSetup();
|
|
1376
|
+
const { userAppRole, userAppModulesDenied } = useLocalSetup();
|
|
1376
1377
|
const { downloadPDF } = usePDFDownload();
|
|
1377
1378
|
const route = useRoute();
|
|
1378
1379
|
|
|
@@ -1459,12 +1460,23 @@ function canViewWidget(key: string) {
|
|
|
1459
1460
|
// Every other gate in this package returns `false` without a role; this one
|
|
1460
1461
|
// now agrees with them.
|
|
1461
1462
|
if (!permissions) return false;
|
|
1463
|
+
|
|
1464
|
+
// The two schedule widgets match ANY `*-schedule-mgmt` string, so no list
|
|
1465
|
+
// names their module: the module list does not govern them.
|
|
1466
|
+
const bySchedule =
|
|
1467
|
+
!isPropertyMode.value && ["taskSchedule", "taskCompleted"].includes(key);
|
|
1468
|
+
|
|
1469
|
+
// The client's module list (RP-5): a widget whose every module Seven365 did
|
|
1470
|
+
// not give this client is hidden. Checked BEFORE `*`, because a wildcard role
|
|
1471
|
+
// is exactly the one a module list has to narrow. An empty list -- every
|
|
1472
|
+
// client today -- hides nothing.
|
|
1473
|
+
if (!bySchedule && permissionsDenied(modulePermissions, userAppModulesDenied.value)) {
|
|
1474
|
+
return false;
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1462
1477
|
if (permissions.includes("*")) return true;
|
|
1463
1478
|
|
|
1464
|
-
if (
|
|
1465
|
-
!isPropertyMode.value &&
|
|
1466
|
-
["taskSchedule", "taskCompleted"].includes(key)
|
|
1467
|
-
) {
|
|
1479
|
+
if (bySchedule) {
|
|
1468
1480
|
return hasSchedulePermission(permissions, "see-all-schedules");
|
|
1469
1481
|
}
|
|
1470
1482
|
|
|
@@ -56,7 +56,8 @@
|
|
|
56
56
|
that order; `utils/nav-sections.ts` only decides which label to print above
|
|
57
57
|
which item, and an item whose title it does not know keeps its place under
|
|
58
58
|
the heading it follows. Nothing here can add, hide, move or rename a menu
|
|
59
|
-
entry, and no route, permission or click handler is involved.
|
|
59
|
+
entry, and no route, permission or click handler is involved. The one
|
|
60
|
+
thing that hides entries is the client's module list, in `navigationItems`.
|
|
60
61
|
-->
|
|
61
62
|
<v-navigation-drawer
|
|
62
63
|
v-model="drawer"
|
|
@@ -123,6 +124,7 @@
|
|
|
123
124
|
import { useDisplay } from "vuetify";
|
|
124
125
|
|
|
125
126
|
import { withSections } from "../../utils/nav-sections";
|
|
127
|
+
import { withoutDeniedRoutes } from "../../utils/module-routes";
|
|
126
128
|
|
|
127
129
|
const props = defineProps({
|
|
128
130
|
navigationItems: { type: Array, required: true },
|
|
@@ -163,6 +165,7 @@ watch(
|
|
|
163
165
|
const orgId = computed(() => String(route.params.org ?? ""));
|
|
164
166
|
const siteId = computed(() => String(route.params.site ?? ""));
|
|
165
167
|
const { useHidFaceReaderMenu } = useHidNavigation();
|
|
168
|
+
const { userAppModulesDenied } = useLocalSetup();
|
|
166
169
|
const { menuItem: hidFaceReaderMenu } = useHidFaceReaderMenu({
|
|
167
170
|
org: orgId,
|
|
168
171
|
site: siteId,
|
|
@@ -187,7 +190,10 @@ const navigationItems = computed(() => {
|
|
|
187
190
|
}
|
|
188
191
|
}
|
|
189
192
|
|
|
190
|
-
|
|
193
|
+
// The client's module list (RP-5): a page of a module Seven365 did not give
|
|
194
|
+
// this client is left out, and so is a group left with nothing in it. An
|
|
195
|
+
// empty list -- every client today -- changes nothing.
|
|
196
|
+
return withoutDeniedRoutes(items, userAppModulesDenied.value);
|
|
191
197
|
});
|
|
192
198
|
|
|
193
199
|
const sectionedItems = computed(() => withSections(navigationItems.value));
|
|
@@ -211,7 +211,7 @@
|
|
|
211
211
|
<v-col cols="12">
|
|
212
212
|
<v-select
|
|
213
213
|
v-model="selectedRole"
|
|
214
|
-
:items="
|
|
214
|
+
:items="pickerRoles"
|
|
215
215
|
item-value="_id"
|
|
216
216
|
item-title="name"
|
|
217
217
|
density="comfortable"
|
|
@@ -258,6 +258,8 @@
|
|
|
258
258
|
</template>
|
|
259
259
|
|
|
260
260
|
<script setup lang="ts">
|
|
261
|
+
import { withCurrentRole } from "../utils/role";
|
|
262
|
+
|
|
261
263
|
const props = defineProps({
|
|
262
264
|
/** The design's page title. Every app that mounts this screen calls it
|
|
263
265
|
Members; a caller that names it otherwise passes its own. */
|
|
@@ -455,6 +457,7 @@ const memberRoleForm = ref(false);
|
|
|
455
457
|
const assignRoleDialog = ref(false);
|
|
456
458
|
const selectedRole = ref<string | null>(null);
|
|
457
459
|
const selectedMemberRole = ref("");
|
|
460
|
+
const selectedMemberRoleName = ref("");
|
|
458
461
|
|
|
459
462
|
function setMember({
|
|
460
463
|
dialog = false,
|
|
@@ -468,9 +471,15 @@ function setMember({
|
|
|
468
471
|
selectedMemberId.value = role._id;
|
|
469
472
|
selectedRole.value = role.role;
|
|
470
473
|
selectedMemberRole.value = role.role;
|
|
474
|
+
selectedMemberRoleName.value = role.roleName ?? "";
|
|
471
475
|
}
|
|
472
476
|
|
|
473
477
|
const roles = ref<Array<Record<string, any>>>([]);
|
|
478
|
+
// Web audit M1: the member's own role is always offered, even when the
|
|
479
|
+
// site-scoped list below does not return it (widen-only, `utils/role.ts`).
|
|
480
|
+
const pickerRoles = computed(() =>
|
|
481
|
+
withCurrentRole(roles.value, selectedMemberRole.value, selectedMemberRoleName.value)
|
|
482
|
+
);
|
|
474
483
|
/*
|
|
475
484
|
* THE ROLES THIS SCREEN MAY ASSIGN.
|
|
476
485
|
*
|
|
@@ -203,7 +203,11 @@
|
|
|
203
203
|
// Relative import: this layer's `utils/` is not auto-imported into consumers.
|
|
204
204
|
import { showSiteField } from "../utils/role";
|
|
205
205
|
import { holdsPermission } from "../utils/permission-spellings";
|
|
206
|
-
import {
|
|
206
|
+
import {
|
|
207
|
+
catalogueForOrg,
|
|
208
|
+
effectiveModules,
|
|
209
|
+
siteModulesForOrg,
|
|
210
|
+
} from "../utils/org-modules";
|
|
207
211
|
|
|
208
212
|
const props = defineProps({
|
|
209
213
|
orgId: {
|
|
@@ -362,7 +366,8 @@ const offeredPermissions = computed(() =>
|
|
|
362
366
|
props.permissions ?? {},
|
|
363
367
|
effectiveModules(
|
|
364
368
|
(orgForModules.value as any)?.modules,
|
|
365
|
-
(
|
|
369
|
+
// Only the site's OWN organisation is narrowed by it (owner Q1).
|
|
370
|
+
siteModulesForOrg(siteForModules.value as any, props.orgId)
|
|
366
371
|
)
|
|
367
372
|
)
|
|
368
373
|
);
|
|
@@ -25,6 +25,12 @@ export function useLocalSetup() {
|
|
|
25
25
|
|
|
26
26
|
const isAppRoleResolved = computed(() => userAppRoleStatus.value === "resolved");
|
|
27
27
|
|
|
28
|
+
// The modules this person's apps must HIDE at the current org|site: the
|
|
29
|
+
// client's Seven365 module list (RP-5, 2026-09-11), answered by the server as
|
|
30
|
+
// a deny list. `[]` means hide nothing -- the answer for every client with no
|
|
31
|
+
// list, and for any failure. Written only by `plugins/secure-member.client.ts`.
|
|
32
|
+
const userAppModulesDenied = useState<string[]>("userAppModulesDenied", () => []);
|
|
33
|
+
|
|
28
34
|
const id = useState<string | null>("memberShipOrgId", () => null);
|
|
29
35
|
|
|
30
36
|
const orgNature = useState<string>("orgNature", () => "");
|
|
@@ -33,6 +39,7 @@ export function useLocalSetup() {
|
|
|
33
39
|
userAppRole,
|
|
34
40
|
userAppRoleStatus,
|
|
35
41
|
isAppRoleResolved,
|
|
42
|
+
userAppModulesDenied,
|
|
36
43
|
id,
|
|
37
44
|
orgNature,
|
|
38
45
|
};
|
package/composables/useMember.ts
CHANGED
|
@@ -39,6 +39,17 @@ export default function useMember() {
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
// The modules this person's apps must hide (RP-5): `{ denied: string[] }`,
|
|
43
|
+
// resolved for the membership exactly as `getByUserType` resolves it. Awaited
|
|
44
|
+
// by the router guard on every org|site change, so a hung request must not
|
|
45
|
+
// stall navigation: it times out, and the caller treats that as "deny nothing".
|
|
46
|
+
function getDeniedModules(user: string, type: string, org?: string, site?: string) {
|
|
47
|
+
return useNuxtApp().$api<{ denied?: unknown }>(
|
|
48
|
+
`/api/members/user/${user}/app/${type}/modules`,
|
|
49
|
+
{ method: "GET", query: { org, site }, timeout: 5000 },
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
42
53
|
async function getAll({
|
|
43
54
|
page = 1,
|
|
44
55
|
search = "",
|
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.9.1-staging.
|
|
5
|
+
"version": "4.9.1-staging.309",
|
|
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.",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { routeDenied } from "../utils/module-routes.ts";
|
|
2
3
|
|
|
3
4
|
const hexSchema = z
|
|
4
5
|
.string()
|
|
@@ -8,13 +9,19 @@ function statusOf(error: any) {
|
|
|
8
9
|
return error?.statusCode ?? error?.status ?? error?.response?.status;
|
|
9
10
|
}
|
|
10
11
|
|
|
12
|
+
/** A route param that is a real id, or "": a malformed one is never sent. */
|
|
13
|
+
function idParam(value: unknown) {
|
|
14
|
+
return hexSchema.safeParse(value).success ? String(value) : "";
|
|
15
|
+
}
|
|
16
|
+
|
|
11
17
|
export default defineNuxtPlugin(() => {
|
|
12
18
|
const router = useRouter();
|
|
13
|
-
const { getByUserType } = useMember();
|
|
19
|
+
const { getByUserType, getDeniedModules } = useMember();
|
|
14
20
|
const { getRoleById } = useRole();
|
|
15
21
|
const { getById } = useOrg();
|
|
16
22
|
|
|
17
|
-
const { userAppRole, userAppRoleStatus, id, orgNature } =
|
|
23
|
+
const { userAppRole, userAppRoleStatus, userAppModulesDenied, id, orgNature } =
|
|
24
|
+
useLocalSetup();
|
|
18
25
|
|
|
19
26
|
// Resolved once per signed-in session, not once per navigation. Keyed by the
|
|
20
27
|
// user cookie so signing in as somebody else re-resolves.
|
|
@@ -22,6 +29,12 @@ export default defineNuxtPlugin(() => {
|
|
|
22
29
|
let inFlight: Promise<void> | null = null;
|
|
23
30
|
let hasMemberDocument = false;
|
|
24
31
|
|
|
32
|
+
// The client's module list is decided per org|site, so it has its own key.
|
|
33
|
+
// `deniedWanted` is the latest key asked for: an older answer that lands after
|
|
34
|
+
// a newer navigation is dropped instead of overwriting it.
|
|
35
|
+
let deniedFor: string | null = null;
|
|
36
|
+
let deniedWanted: string | null = null;
|
|
37
|
+
|
|
25
38
|
// Deliberately never redirects and never throws.
|
|
26
39
|
//
|
|
27
40
|
// `GET /api/members/user/:id/app/:type` returns 404 for any account holding no
|
|
@@ -65,6 +78,38 @@ export default defineNuxtPlugin(() => {
|
|
|
65
78
|
userAppRoleStatus.value = "resolved";
|
|
66
79
|
}
|
|
67
80
|
|
|
81
|
+
// THE CLIENT'S MODULE LIST (RP-5, 2026-09-11). The server answers with the
|
|
82
|
+
// modules this person's apps must HIDE, for the membership the role came from
|
|
83
|
+
// (its org) at the route's site. It FAILS OPEN: no member document, the
|
|
84
|
+
// endpoint missing (it 404s until API-core ships it), any error, or an answer
|
|
85
|
+
// that is not a list all mean nothing is denied -- never "hide everything".
|
|
86
|
+
// It never touches the role or its status.
|
|
87
|
+
async function resolveDenied(userId: string, site: string) {
|
|
88
|
+
if (!hasMemberDocument) {
|
|
89
|
+
deniedFor = deniedWanted = null;
|
|
90
|
+
userAppModulesDenied.value = [];
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const org = id.value ?? "";
|
|
94
|
+
const key = `${userId}|${org}|${site}`;
|
|
95
|
+
if (deniedFor === key) return;
|
|
96
|
+
deniedWanted = key;
|
|
97
|
+
|
|
98
|
+
let denied: string[] = [];
|
|
99
|
+
try {
|
|
100
|
+
const APP = useRuntimeConfig().public.APP;
|
|
101
|
+
const res = await getDeniedModules(userId, APP, org || undefined, site || undefined);
|
|
102
|
+
const list = (res as any)?.denied;
|
|
103
|
+
if (Array.isArray(list)) denied = list.filter((k): k is string => typeof k === "string");
|
|
104
|
+
} catch {
|
|
105
|
+
// Fail open: `denied` stays [].
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (deniedWanted !== key) return;
|
|
109
|
+
deniedFor = key;
|
|
110
|
+
userAppModulesDenied.value = denied;
|
|
111
|
+
}
|
|
112
|
+
|
|
68
113
|
router.beforeEach(async (to) => {
|
|
69
114
|
const userId = useCookie("user").value ?? "";
|
|
70
115
|
|
|
@@ -75,6 +120,19 @@ export default defineNuxtPlugin(() => {
|
|
|
75
120
|
// default open granted everything, gates that fail closed denied everything.
|
|
76
121
|
// Awaited, so no gate is ever evaluated against an unresolved role.
|
|
77
122
|
if (userId) await resolveAppRole(userId);
|
|
123
|
+
if (userId) await resolveDenied(userId, idParam(to.params.site));
|
|
124
|
+
else if (userAppModulesDenied.value.length) {
|
|
125
|
+
// Signed out: never carry the previous person's list.
|
|
126
|
+
deniedFor = deniedWanted = null;
|
|
127
|
+
userAppModulesDenied.value = [];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// A page of a module Seven365 did not give this client goes to the site's
|
|
131
|
+
// dashboard, which is never governed. Every governed route is an
|
|
132
|
+
// `org-site-*` page, so both params are there. Unmapped routes pass.
|
|
133
|
+
if (routeDenied(to.name, userAppModulesDenied.value)) {
|
|
134
|
+
return { name: "org-site-dashboard", params: { org: to.params.org, site: to.params.site } };
|
|
135
|
+
}
|
|
78
136
|
|
|
79
137
|
const isMember = to.meta?.memberOnly;
|
|
80
138
|
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WHICH MODULE EACH PAGE BELONGS TO — the web half of the module gate.
|
|
3
|
+
*
|
|
4
|
+
* Owner decision 1B / RP-5 (2026-09-11): the modules Seven365 gives a client
|
|
5
|
+
* become a real gate. The server answers each person with a DENY list
|
|
6
|
+
* (`GET /api/members/user/:id/app/:type/modules`, core `deniedModules`), kept in
|
|
7
|
+
* `useLocalSetup().userAppModulesDenied`; this map says which pages a denied
|
|
8
|
+
* module takes away.
|
|
9
|
+
*
|
|
10
|
+
* FAILS OPEN. A route that is not listed here is allowed whatever the list says.
|
|
11
|
+
* Only prefixes whose page each app gates on exactly one module are listed
|
|
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
|
+
* access-mgmt (`site-settings:manage-entry-pass` also opens it), equipment and
|
|
15
|
+
* inventory, the property CCTV wall, service-providers and support tickets.
|
|
16
|
+
*
|
|
17
|
+
* NEVER MAPPED: the dashboard, settings, members, invitations and roles. A client
|
|
18
|
+
* must always be able to run its own people and roles; the server never denies
|
|
19
|
+
* them either (`ALWAYS_ALLOWED`).
|
|
20
|
+
*
|
|
21
|
+
* Each key is a Nuxt route-NAME prefix: `org-site-work-orders` covers
|
|
22
|
+
* `org-site-work-orders` and `org-site-work-orders-id`. The longest matching
|
|
23
|
+
* prefix wins, so `org-site-cleaning-schedule-area` is area management, not the
|
|
24
|
+
* schedule. One spelling per module is enough: the server widens the deny list
|
|
25
|
+
* through the spelling groups, so every spelling of a denied module is in it.
|
|
26
|
+
*/
|
|
27
|
+
export const MODULE_ROUTES: Readonly<Record<string, string>> = Object.freeze({
|
|
28
|
+
"org-site-feedbacks": "feedbacks",
|
|
29
|
+
"org-site-work-orders": "work_orders",
|
|
30
|
+
"org-site-incident-reports": "incident-reports",
|
|
31
|
+
"org-site-bulletin-board": "bulletin-board",
|
|
32
|
+
"org-site-bulletin-videos": "bulletin-videos-mgmt",
|
|
33
|
+
"org-site-visitor-mgmt": "visitor-mgmt",
|
|
34
|
+
"org-site-visitor-management": "visitor-mgmt",
|
|
35
|
+
"org-site-vehicle-management": "vehicle-mgmt",
|
|
36
|
+
"org-site-building-mgmt": "building-mgmt",
|
|
37
|
+
"org-site-daily-occurrence-books": "daily-occurrence-books",
|
|
38
|
+
"org-site-dob": "daily-occurrence-books",
|
|
39
|
+
"org-site-manpower-monitoring": "manpower-monitoring",
|
|
40
|
+
// Includes its CCTV page: security's drawer shows it to whoever can see
|
|
41
|
+
// Virtual Patrol, so it follows the same module.
|
|
42
|
+
"org-site-virtual-patrol": "virtual-patrol",
|
|
43
|
+
"org-site-robot-management": "robot-mgmt",
|
|
44
|
+
"org-site-attendance": "attendance-mgmt",
|
|
45
|
+
"org-site-my-attendance": "my-attendance",
|
|
46
|
+
"org-site-schedule-task": "schedule-task-mgmt",
|
|
47
|
+
"org-site-cleaning-schedule": "cleaning-schedule-mgmt",
|
|
48
|
+
"org-site-cleaning-schedule-area": "area-mgmt",
|
|
49
|
+
"org-site-cleaning-schedule-unit": "unit-mgmt",
|
|
50
|
+
// M&E's schedule is the cleaning schedule module (its catalogue has no other).
|
|
51
|
+
"org-site-technician-schedule": "cleaning-schedule-mgmt",
|
|
52
|
+
"org-site-technician-schedule-area": "area-mgmt",
|
|
53
|
+
"org-site-technician-schedule-unit": "unit-mgmt",
|
|
54
|
+
"org-site-pest-schedule": "pest-schedule-mgmt",
|
|
55
|
+
"org-site-pest-schedule-area": "area-mgmt",
|
|
56
|
+
"org-site-pest-schedule-unit": "unit-mgmt",
|
|
57
|
+
"org-site-landscape-schedule": "landscape-schedule-mgmt",
|
|
58
|
+
"org-site-landscape-schedule-area": "area-mgmt",
|
|
59
|
+
"org-site-landscape-schedule-unit": "unit-mgmt",
|
|
60
|
+
"org-site-pool-schedule": "pool-schedule-mgmt",
|
|
61
|
+
"org-site-pool-schedule-area": "area-mgmt",
|
|
62
|
+
"org-site-pool-schedule-unit": "unit-mgmt",
|
|
63
|
+
"org-site-service-provider-mgmt": "service-provider-mgmt",
|
|
64
|
+
"org-site-online-forms": "online-form-configuration",
|
|
65
|
+
"org-site-nfc": "nfc-patrol",
|
|
66
|
+
"org-site-document-mgmt": "document-mgmt",
|
|
67
|
+
"org-site-event-mgmt": "event-mgmt",
|
|
68
|
+
"org-site-emergency-contacts": "emergency-contact",
|
|
69
|
+
"org-site-online-billing": "billing-mgmt",
|
|
70
|
+
"org-site-soa-mgmt": "SOA-mgmt",
|
|
71
|
+
"org-site-people-mgmt": "people-mgmt",
|
|
72
|
+
"org-site-supply-mgmt": "supply-mgmt",
|
|
73
|
+
"org-site-facility": "facility-mgmt",
|
|
74
|
+
"org-site-facility-mgmt": "facility-mgmt",
|
|
75
|
+
"org-site-facility-booking": "facility-booking-mgmt",
|
|
76
|
+
"org-site-facility-bookings": "facility-booking-mgmt",
|
|
77
|
+
"org-site-facility-calendar": "facility-booking-mgmt",
|
|
78
|
+
// Carved OUT of `org-site-facility`: property-management draws it for anyone
|
|
79
|
+
// who can manage site settings, so it is not facility's page alone.
|
|
80
|
+
"org-site-facility-settings": "",
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const PREFIXES = Object.keys(MODULE_ROUTES).sort((a, b) => b.length - a.length);
|
|
84
|
+
|
|
85
|
+
/** The module a route belongs to, or "" when the route is not governed. */
|
|
86
|
+
export function routeModule(name: unknown): string {
|
|
87
|
+
const route = typeof name === "string" ? name : "";
|
|
88
|
+
const prefix = PREFIXES.find((p) => route === p || route.startsWith(`${p}-`));
|
|
89
|
+
return prefix ? MODULE_ROUTES[prefix] : "";
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Did the client's list take this route's module away? Unmapped: never. */
|
|
93
|
+
export function routeDenied(
|
|
94
|
+
name: unknown,
|
|
95
|
+
denied: readonly string[] | null | undefined,
|
|
96
|
+
): boolean {
|
|
97
|
+
const module = routeModule(name);
|
|
98
|
+
return Boolean(module) && Array.isArray(denied) && denied.includes(module);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Is EVERY resource these permission strings name denied? A widget or control
|
|
103
|
+
* that any one allowed module can open stays; an empty list is never denied.
|
|
104
|
+
*/
|
|
105
|
+
export function permissionsDenied(
|
|
106
|
+
permissions: readonly string[] | null | undefined,
|
|
107
|
+
denied: readonly string[] | null | undefined,
|
|
108
|
+
): boolean {
|
|
109
|
+
if (!Array.isArray(permissions) || !permissions.length) return false;
|
|
110
|
+
if (!Array.isArray(denied) || !denied.length) return false;
|
|
111
|
+
return permissions.every((p) => denied.includes(String(p).split(":")[0]));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
type TRouted = { route?: { name?: unknown } | null; children?: TRouted[] };
|
|
115
|
+
|
|
116
|
+
/** A menu without the pages the client was not given; a group left empty goes too. */
|
|
117
|
+
export function withoutDeniedRoutes<T extends TRouted>(
|
|
118
|
+
items: readonly T[],
|
|
119
|
+
denied: readonly string[] | null | undefined,
|
|
120
|
+
): T[] {
|
|
121
|
+
if (!Array.isArray(denied) || !denied.length) return [...items];
|
|
122
|
+
return items.flatMap((item) => {
|
|
123
|
+
if (routeDenied(item.route?.name, denied)) return [];
|
|
124
|
+
if (!item.children?.length) return [item];
|
|
125
|
+
const children = withoutDeniedRoutes(item.children as T[], denied);
|
|
126
|
+
return children.length ? [{ ...item, children }] : [];
|
|
127
|
+
});
|
|
128
|
+
}
|
package/utils/org-modules.ts
CHANGED
|
@@ -187,6 +187,32 @@ export function effectiveModules(
|
|
|
187
187
|
return allowed.length ? allowed : org;
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
+
/**
|
|
191
|
+
* The site tier, but only for the organisation that OWNS the site.
|
|
192
|
+
*
|
|
193
|
+
* Owner Q1, 2026-09-11: a service provider's role editor follows the
|
|
194
|
+
* PROVIDER's own company modules, never the client's. A provider editing
|
|
195
|
+
* roles while working on a client's site passes that site's id, and the site
|
|
196
|
+
* list there is what the CLIENT chose for its own staff - so it must not
|
|
197
|
+
* narrow the provider. Only when the site belongs to the organisation whose
|
|
198
|
+
* roles are being edited does the site tier apply.
|
|
199
|
+
*
|
|
200
|
+
* Fails open: no site, no `orgId` on it, or no org to compare with all mean
|
|
201
|
+
* "no site tier", which leaves the organisation's own list in charge.
|
|
202
|
+
*/
|
|
203
|
+
export function siteModulesForOrg(
|
|
204
|
+
site: { orgId?: unknown; org?: unknown; metadata?: { modules?: unknown } } | null | undefined,
|
|
205
|
+
orgId: unknown,
|
|
206
|
+
): readonly string[] | undefined {
|
|
207
|
+
// `org` is the legacy field name; core reads `orgId ?? org` the same way.
|
|
208
|
+
const siteOrg = String(site?.orgId ?? site?.org ?? "");
|
|
209
|
+
const org = String(orgId ?? "");
|
|
210
|
+
if (!siteOrg || !org || siteOrg !== org) return undefined;
|
|
211
|
+
|
|
212
|
+
const modules = site?.metadata?.modules;
|
|
213
|
+
return Array.isArray(modules) ? modules : undefined;
|
|
214
|
+
}
|
|
215
|
+
|
|
190
216
|
function isKey(value: unknown): value is string {
|
|
191
217
|
return typeof value === "string" && value.trim().length > 0;
|
|
192
218
|
}
|
package/utils/role.ts
CHANGED
|
@@ -8,3 +8,21 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export const showSiteField = (siteState: boolean, type: string): boolean =>
|
|
10
10
|
siteState && type !== "admin";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The Assign Role picker's list, with the member's CURRENT role always in it.
|
|
14
|
+
*
|
|
15
|
+
* The list is scoped to the site and capped at 100, so a member can hold a role
|
|
16
|
+
* it does not return (pinned to another site, or past the cap). The picker then
|
|
17
|
+
* showed a bare id and "Role already assigned" against nothing. Widen-only: the
|
|
18
|
+
* current role is appended when missing, nothing is removed or reordered.
|
|
19
|
+
*/
|
|
20
|
+
export function withCurrentRole<T extends { _id?: unknown; name?: unknown }>(
|
|
21
|
+
roles: readonly T[] | null | undefined,
|
|
22
|
+
currentId: string | null | undefined,
|
|
23
|
+
currentName: string | null | undefined,
|
|
24
|
+
): Array<T | { _id: string; name: string }> {
|
|
25
|
+
const list = Array.isArray(roles) ? [...roles] : [];
|
|
26
|
+
if (!currentId || list.some((r) => String(r?._id) === currentId)) return list;
|
|
27
|
+
return [...list, { _id: currentId, name: currentName || currentId }];
|
|
28
|
+
}
|