@7365admin1/layer-common 4.5.1-staging.293 → 4.5.1-staging.295
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/SwitchContext.vue +46 -2
- package/composables/useCleaningPermission.ts +5 -0
- package/composables/useLandscapingPermission.ts +5 -0
- package/composables/useMechanicalElectricalPermission.ts +6 -0
- package/composables/usePestControlPermission.ts +5 -0
- package/composables/usePoolMaintenancePermission.ts +5 -0
- package/composables/usePropertyPermission.ts +5 -0
- package/composables/useSecurityPermission.ts +5 -0
- package/package.json +1 -1
- package/utils/module-applications.ts +146 -0
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
<v-list-item
|
|
53
53
|
density="compact"
|
|
54
54
|
class="switch-context__row"
|
|
55
|
-
v-for="item in
|
|
55
|
+
v-for="item in uniqueItems"
|
|
56
56
|
:key="item.value"
|
|
57
57
|
@click="selectItem(item.value)"
|
|
58
58
|
>
|
|
@@ -158,8 +158,52 @@ const search = defineModel<string>("search", {
|
|
|
158
158
|
|
|
159
159
|
const emit = defineEmits(["search", "select", "manage", "add"]);
|
|
160
160
|
|
|
161
|
+
/**
|
|
162
|
+
* ONE ROW PER DESTINATION.
|
|
163
|
+
*
|
|
164
|
+
* Owner report, 2026-09-10: the site switcher showed a tick against TWO sites at
|
|
165
|
+
* once. It was not a comparison bug — `selected === item.value` is a strict
|
|
166
|
+
* equality and it was true for both rows, because BOTH ROWS WERE THE SAME SITE.
|
|
167
|
+
*
|
|
168
|
+
* The seven service applications all build this list from `customer-sites`,
|
|
169
|
+
* mapping `value: i.site`. A `customer-sites` row is an ENGAGEMENT, not a site,
|
|
170
|
+
* and one site can carry more than one — measured on production, provider org
|
|
171
|
+
* `69251bc6…` has two active rows for site `6923d666…`, identical in `site`,
|
|
172
|
+
* `siteOrg`, `org` and `status`, differing only in a stale `name` snapshot
|
|
173
|
+
* ("Seventh Condominium" from the older row, "NCC" from the newer). So the same
|
|
174
|
+
* site was listed twice and, being selected, was ticked twice.
|
|
175
|
+
*
|
|
176
|
+
* Picking either row sets the SAME `siteId`, so the two entries were
|
|
177
|
+
* indistinguishable in effect — the list offered a choice that was not a choice.
|
|
178
|
+
*
|
|
179
|
+
* Deduplicating belongs here rather than in seven layouts: this component's
|
|
180
|
+
* whole contract is "pick ONE of these", so two entries that do the same thing
|
|
181
|
+
* are its problem to reject. It also means a duplicate arriving from any other
|
|
182
|
+
* caller is handled without waiting for that caller to notice.
|
|
183
|
+
*
|
|
184
|
+
* FIRST OCCURRENCE WINS, deliberately. The applications receive these rows
|
|
185
|
+
* newest-first, so the surviving label is the current one — "NCC", which is what
|
|
186
|
+
* the breadcrumb already resolves from the site itself. Keeping the last would
|
|
187
|
+
* show the stale snapshot beside a breadcrumb that disagreed with it.
|
|
188
|
+
*
|
|
189
|
+
* An item with no `value` is left alone: it cannot collide, and silently
|
|
190
|
+
* dropping it would hide a malformed row instead of showing it.
|
|
191
|
+
*/
|
|
192
|
+
const uniqueItems = computed(() => {
|
|
193
|
+
const items = Array.isArray(prop.items) ? prop.items : [];
|
|
194
|
+
const seen = new Set<unknown>();
|
|
195
|
+
|
|
196
|
+
return items.filter((item) => {
|
|
197
|
+
const value = item?.value;
|
|
198
|
+
if (value === undefined || value === null || value === "") return true;
|
|
199
|
+
if (seen.has(value)) return false;
|
|
200
|
+
seen.add(value);
|
|
201
|
+
return true;
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
161
205
|
const name = computed(() => {
|
|
162
|
-
return
|
|
206
|
+
return uniqueItems.value.find((item) => item.value === selected.value)?.text ?? "";
|
|
163
207
|
});
|
|
164
208
|
|
|
165
209
|
/**
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
// Explicit import rather than Nuxt auto-import. Identical inside the app, and it
|
|
2
|
+
// makes this catalogue readable OUTSIDE a Nuxt context -- which is what lets
|
|
3
|
+
// `utils/module-applications.ts` derive the module-to-application map from the
|
|
4
|
+
// apps themselves instead of a hand-written list that silently goes stale.
|
|
5
|
+
import { useCommonPermissions } from "./useCommonPermission";
|
|
1
6
|
export default function useCleaningPermission() {
|
|
2
7
|
const {
|
|
3
8
|
rolePermissions,
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
// Explicit import rather than Nuxt auto-import. Identical inside the app, and it
|
|
2
|
+
// makes this catalogue readable OUTSIDE a Nuxt context -- which is what lets
|
|
3
|
+
// `utils/module-applications.ts` derive the module-to-application map from the
|
|
4
|
+
// apps themselves instead of a hand-written list that silently goes stale.
|
|
5
|
+
import { useCommonPermissions } from "./useCommonPermission";
|
|
1
6
|
/**
|
|
2
7
|
* THE LANDSCAPE ROLE CATALOGUE — the shared copy.
|
|
3
8
|
*
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
// Explicit import rather than Nuxt auto-import. Identical inside the app, and it
|
|
2
|
+
// makes this catalogue readable OUTSIDE a Nuxt context -- which is what lets
|
|
3
|
+
// `utils/module-applications.ts` derive the module-to-application map from the
|
|
4
|
+
// apps themselves instead of a hand-written list that silently goes stale.
|
|
5
|
+
import { useCommonPermissions } from "./useCommonPermission";
|
|
6
|
+
import useCleaningPermission from "./useCleaningPermission";
|
|
1
7
|
/**
|
|
2
8
|
* THE MECHANICAL & ELECTRICAL ROLE CATALOGUE — the shared copy.
|
|
3
9
|
*
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
// Explicit import rather than Nuxt auto-import. Identical inside the app, and it
|
|
2
|
+
// makes this catalogue readable OUTSIDE a Nuxt context -- which is what lets
|
|
3
|
+
// `utils/module-applications.ts` derive the module-to-application map from the
|
|
4
|
+
// apps themselves instead of a hand-written list that silently goes stale.
|
|
5
|
+
import { useCommonPermissions } from "./useCommonPermission";
|
|
1
6
|
/**
|
|
2
7
|
* THE PEST CONTROL ROLE CATALOGUE — the shared copy.
|
|
3
8
|
*
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
// Explicit import rather than Nuxt auto-import. Identical inside the app, and it
|
|
2
|
+
// makes this catalogue readable OUTSIDE a Nuxt context -- which is what lets
|
|
3
|
+
// `utils/module-applications.ts` derive the module-to-application map from the
|
|
4
|
+
// apps themselves instead of a hand-written list that silently goes stale.
|
|
5
|
+
import { useCommonPermissions } from "./useCommonPermission";
|
|
1
6
|
/**
|
|
2
7
|
* THE POOL MAINTENANCE ROLE CATALOGUE — the shared copy.
|
|
3
8
|
*
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
// Explicit import rather than Nuxt auto-import. Identical inside the app, and it
|
|
2
|
+
// makes this catalogue readable OUTSIDE a Nuxt context -- which is what lets
|
|
3
|
+
// `utils/module-applications.ts` derive the module-to-application map from the
|
|
4
|
+
// apps themselves instead of a hand-written list that silently goes stale.
|
|
5
|
+
import { useCommonPermissions } from "./useCommonPermission";
|
|
1
6
|
/**
|
|
2
7
|
* THE PROPERTY-MANAGEMENT ROLE CATALOGUE — the shared copy.
|
|
3
8
|
*
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
// Explicit import rather than Nuxt auto-import. Identical inside the app, and it
|
|
2
|
+
// makes this catalogue readable OUTSIDE a Nuxt context -- which is what lets
|
|
3
|
+
// `utils/module-applications.ts` derive the module-to-application map from the
|
|
4
|
+
// apps themselves instead of a hand-written list that silently goes stale.
|
|
5
|
+
import { useCommonPermissions } from "./useCommonPermission";
|
|
1
6
|
/**
|
|
2
7
|
* THE SECURITY ROLE CATALOGUE — the shared copy.
|
|
3
8
|
*
|
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.5.1-staging.
|
|
5
|
+
"version": "4.5.1-staging.295",
|
|
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,146 @@
|
|
|
1
|
+
import useSecurityPermission from "../composables/useSecurityPermission";
|
|
2
|
+
import useCleaningPermission from "../composables/useCleaningPermission";
|
|
3
|
+
import useLandscapingPermission from "../composables/useLandscapingPermission";
|
|
4
|
+
import useMechanicalElectricalPermission from "../composables/useMechanicalElectricalPermission";
|
|
5
|
+
import usePestControlPermission from "../composables/usePestControlPermission";
|
|
6
|
+
import usePoolMaintenancePermission from "../composables/usePoolMaintenancePermission";
|
|
7
|
+
import usePropertyPermission from "../composables/usePropertyPermission";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* WHICH APPLICATION EACH MODULE BELONGS TO.
|
|
11
|
+
*
|
|
12
|
+
* Owner report, 2026-09-10: *"I check security company and nature of business is
|
|
13
|
+
* security but have cleaning schedule management."* The Seven365 console's
|
|
14
|
+
* "Modules offered to this client" card listed the whole 47-entry catalogue as
|
|
15
|
+
* one flat alphabetical list, with nothing to say which service each module is
|
|
16
|
+
* part of — so a security client was offered Cleaning schedule management, and a
|
|
17
|
+
* cleaning client was offered Virtual patrol.
|
|
18
|
+
*
|
|
19
|
+
* R1 is written in terms of APPLICATIONS: *"assigns roles & permissions to an
|
|
20
|
+
* ORGANISATION for the applications it needs (Security, Cleaning, Pest, M&E, MA,
|
|
21
|
+
* Landscape, Pool)."* This is the map that makes that possible.
|
|
22
|
+
*
|
|
23
|
+
* ## DERIVED, never hand-written
|
|
24
|
+
*
|
|
25
|
+
* Each application's role editor already declares exactly what it offers — its
|
|
26
|
+
* `use*Permission` composable IS that declaration, and it is the same object the
|
|
27
|
+
* app passes to `RolePermissionMain` as `:permissions`. So the grouping is read
|
|
28
|
+
* from those composables at load time rather than copied out of them.
|
|
29
|
+
*
|
|
30
|
+
* A hand-written list would be correct on the day it was written and wrong the
|
|
31
|
+
* first time somebody adds a module to an app — silently, because nothing would
|
|
32
|
+
* fail. Deriving it means the console cannot disagree with the apps.
|
|
33
|
+
*
|
|
34
|
+
* The composables are pure (no Nuxt APIs, no lifecycle hooks), so calling them
|
|
35
|
+
* here is safe and costs one object construction each.
|
|
36
|
+
*
|
|
37
|
+
* ## A module can belong to SEVERAL applications, and that is not a mistake
|
|
38
|
+
*
|
|
39
|
+
* `cleaning-schedule-mgmt` is offered by BOTH Cleaning and M&E — M&E reuses the
|
|
40
|
+
* cleaning schedule module deliberately (`useMechanicalElectricalPermission`
|
|
41
|
+
* takes it from `useCleaningPermission`). `attendance-mgmt`, `site-settings`,
|
|
42
|
+
* `members`, `roles` and `invitations` are shared by nearly all of them.
|
|
43
|
+
*
|
|
44
|
+
* So this is a MANY-TO-MANY map, and the console has to show a shared module
|
|
45
|
+
* under each application that offers it. Presenting it as one-to-one would be
|
|
46
|
+
* the same class of wrongness as the flat list it replaces.
|
|
47
|
+
*
|
|
48
|
+
* ## It still stores a flat list of module keys
|
|
49
|
+
*
|
|
50
|
+
* `organizations.modules` is unchanged — a flat array of resource keys. Ticking
|
|
51
|
+
* an application ticks its keys. Nothing about the cascade, the server contract
|
|
52
|
+
* or the fail-open rule changes; this is how the choice is PRESENTED.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/** The seven service applications, in the order the owner names them in R1. */
|
|
56
|
+
export const APPLICATIONS = [
|
|
57
|
+
{ key: "security", label: "Security", composable: useSecurityPermission },
|
|
58
|
+
{ key: "cleaning", label: "Cleaning", composable: useCleaningPermission },
|
|
59
|
+
{ key: "pest", label: "Pest control", composable: usePestControlPermission },
|
|
60
|
+
{
|
|
61
|
+
key: "mechanical-electrical",
|
|
62
|
+
label: "Mechanical & electrical",
|
|
63
|
+
composable: useMechanicalElectricalPermission,
|
|
64
|
+
},
|
|
65
|
+
{ key: "landscape", label: "Landscape", composable: useLandscapingPermission },
|
|
66
|
+
{ key: "pool", label: "Pool maintenance", composable: usePoolMaintenancePermission },
|
|
67
|
+
{
|
|
68
|
+
key: "property-management",
|
|
69
|
+
label: "Property management",
|
|
70
|
+
composable: usePropertyPermission,
|
|
71
|
+
},
|
|
72
|
+
] as const;
|
|
73
|
+
|
|
74
|
+
export type ApplicationKey = (typeof APPLICATIONS)[number]["key"];
|
|
75
|
+
|
|
76
|
+
export type ApplicationModules = {
|
|
77
|
+
key: string;
|
|
78
|
+
label: string;
|
|
79
|
+
/** The resource keys this application's role editor offers. */
|
|
80
|
+
modules: string[];
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/** Read one application's resource keys straight out of its own catalogue. */
|
|
84
|
+
function modulesOf(composable: () => { permissions?: Record<string, unknown> }): string[] {
|
|
85
|
+
try {
|
|
86
|
+
const { permissions } = composable() ?? {};
|
|
87
|
+
if (!permissions || typeof permissions !== "object") return [];
|
|
88
|
+
return Object.keys(permissions).filter(Boolean);
|
|
89
|
+
} catch {
|
|
90
|
+
/*
|
|
91
|
+
* FAILS OPEN as an empty list, never a throw. This runs at module load in
|
|
92
|
+
* the console; a composable that changes shape must not take the whole
|
|
93
|
+
* client-configuration screen down with it — the screen falls back to the
|
|
94
|
+
* ungrouped catalogue, which is exactly what it showed before this existed.
|
|
95
|
+
*/
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Every application with the modules it offers, derived from the apps themselves. */
|
|
101
|
+
export function applicationModules(): ApplicationModules[] {
|
|
102
|
+
return APPLICATIONS.map((app) => ({
|
|
103
|
+
key: app.key,
|
|
104
|
+
label: app.label,
|
|
105
|
+
modules: modulesOf(app.composable as never),
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Which applications offer this module. Empty means none of the seven do. */
|
|
110
|
+
export function applicationsForModule(resource: string): string[] {
|
|
111
|
+
if (!resource) return [];
|
|
112
|
+
return applicationModules()
|
|
113
|
+
.filter((app) => app.modules.includes(resource))
|
|
114
|
+
.map((app) => app.label);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Group a catalogue's keys by application, plus everything left over.
|
|
119
|
+
*
|
|
120
|
+
* The leftovers matter: `constants/permissions.ts` and the seven composables are
|
|
121
|
+
* two different lists and they do NOT agree — `customers`, `sites`,
|
|
122
|
+
* `subscriptions` and `robot-mgmt` appear in the flat catalogue but in no
|
|
123
|
+
* application, and `access-control`, `passes-and-keys-mgmt`, `online-forms`,
|
|
124
|
+
* `blocklist` and `resident-transactions` are the reverse. Dropping either set
|
|
125
|
+
* silently would be worse than showing it: an unticked module a client needs is
|
|
126
|
+
* a module they cannot be given.
|
|
127
|
+
*/
|
|
128
|
+
export function groupModulesByApplication(catalogueKeys: readonly string[]): {
|
|
129
|
+
groups: ApplicationModules[];
|
|
130
|
+
ungrouped: string[];
|
|
131
|
+
} {
|
|
132
|
+
const keys = Array.isArray(catalogueKeys) ? catalogueKeys.filter(Boolean) : [];
|
|
133
|
+
const apps = applicationModules();
|
|
134
|
+
|
|
135
|
+
const groups = apps
|
|
136
|
+
.map((app) => ({
|
|
137
|
+
...app,
|
|
138
|
+
modules: app.modules.filter((module) => keys.includes(module)),
|
|
139
|
+
}))
|
|
140
|
+
.filter((app) => app.modules.length > 0);
|
|
141
|
+
|
|
142
|
+
const claimed = new Set(groups.flatMap((app) => app.modules));
|
|
143
|
+
const ungrouped = keys.filter((key) => !claimed.has(key));
|
|
144
|
+
|
|
145
|
+
return { groups, ungrouped };
|
|
146
|
+
}
|