@7365admin1/layer-common 4.4.2-staging.290 → 4.4.2-staging.292
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.
|
@@ -112,7 +112,7 @@
|
|
|
112
112
|
<v-list-item-title
|
|
113
113
|
class="text-capitalize role-create__row-title"
|
|
114
114
|
>
|
|
115
|
-
{{ String(actionKey)
|
|
115
|
+
{{ formatActionLabel(String(actionKey)) }}
|
|
116
116
|
</v-list-item-title>
|
|
117
117
|
<v-list-item-subtitle class="role-create__row-sub">
|
|
118
118
|
{{ action.description }}
|
|
@@ -143,6 +143,11 @@
|
|
|
143
143
|
</template>
|
|
144
144
|
|
|
145
145
|
<script setup lang="ts">
|
|
146
|
+
// Relative import: this layer's `utils/` is not auto-imported into consumers.
|
|
147
|
+
import {
|
|
148
|
+
formatActionLabel,
|
|
149
|
+
formatResourceLabel,
|
|
150
|
+
} from "../utils/permission-labels";
|
|
146
151
|
import useRole from "../composables/useRole";
|
|
147
152
|
import useUtils from "../composables/useUtils";
|
|
148
153
|
import useSite from "../composables/useSite";
|
|
@@ -191,13 +196,7 @@ const permState = shallowRef({
|
|
|
191
196
|
enabled: [] as string[],
|
|
192
197
|
});
|
|
193
198
|
|
|
194
|
-
const resourceLabels: Record<string, string> = {
|
|
195
|
-
"access-card-mgmt": "Access Mgmt",
|
|
196
|
-
};
|
|
197
199
|
|
|
198
|
-
function formatResourceLabel(key: string): string {
|
|
199
|
-
return resourceLabels[key] ?? key.replace(/-/g, " ");
|
|
200
|
-
}
|
|
201
200
|
|
|
202
201
|
function isCategoryEnabled(resource: string) {
|
|
203
202
|
return permState.value.enabled.includes(resource);
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
/>
|
|
76
76
|
</template>
|
|
77
77
|
<v-list-item-title class="text-capitalize role-perm__row-title">
|
|
78
|
-
{{ String(actionKey)
|
|
78
|
+
{{ formatActionLabel(String(actionKey)) }}
|
|
79
79
|
</v-list-item-title>
|
|
80
80
|
<v-list-item-subtitle class="role-perm__row-sub">
|
|
81
81
|
{{ action.description }}
|
|
@@ -119,6 +119,11 @@
|
|
|
119
119
|
</template>
|
|
120
120
|
|
|
121
121
|
<script setup lang="ts">
|
|
122
|
+
// Relative import: this layer's `utils/` is not auto-imported into consumers.
|
|
123
|
+
import {
|
|
124
|
+
formatActionLabel,
|
|
125
|
+
formatResourceLabel,
|
|
126
|
+
} from "../utils/permission-labels";
|
|
122
127
|
import useRole from "../composables/useRole";
|
|
123
128
|
import useUtils from "../composables/useUtils";
|
|
124
129
|
import {
|
|
@@ -163,13 +168,7 @@ const message = ref("");
|
|
|
163
168
|
const disable = ref(false);
|
|
164
169
|
const expandedResources = ref<string[]>([]);
|
|
165
170
|
|
|
166
|
-
const resourceLabels: Record<string, string> = {
|
|
167
|
-
"access-card-mgmt": "Access Mgmt",
|
|
168
|
-
};
|
|
169
171
|
|
|
170
|
-
function formatResourceLabel(key: string) {
|
|
171
|
-
return resourceLabels[key] ?? key.replace(/-/g, " ");
|
|
172
|
-
}
|
|
173
172
|
|
|
174
173
|
/**
|
|
175
174
|
* Is this box ticked?
|
|
@@ -202,7 +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
|
+
import { catalogueForOrg, effectiveModules } from "../utils/org-modules";
|
|
206
206
|
|
|
207
207
|
const props = defineProps({
|
|
208
208
|
orgId: {
|
|
@@ -332,9 +332,38 @@ const { data: orgForModules } = useLazyAsyncData(
|
|
|
332
332
|
{ watch: [() => props.orgId] }
|
|
333
333
|
);
|
|
334
334
|
|
|
335
|
-
|
|
335
|
+
/*
|
|
336
|
+
* TIER TWO OF THE CASCADE: THE MODULES THIS SITE WAS GIVEN.
|
|
337
|
+
*
|
|
338
|
+
* R1, 2026-09-10: the organisation may only give a site what Seven365 gave the
|
|
339
|
+
* organisation. When this editor is scoped to a site, the boxes it offers are
|
|
340
|
+
* the INTERSECTION of the two lists, not the organisation's alone.
|
|
341
|
+
*
|
|
342
|
+
* Only fetched when there is a site to fetch - an organisation-level role
|
|
343
|
+
* editor has no second tier and must not pay for a request. Fails open exactly
|
|
344
|
+
* as the org lookup does: no site, no field, or a failed request all leave the
|
|
345
|
+
* organisation's list in charge.
|
|
346
|
+
*/
|
|
347
|
+
const { getSiteById: _getSiteForModules } = useSite();
|
|
348
|
+
|
|
349
|
+
const { data: siteForModules } = useLazyAsyncData(
|
|
350
|
+
`site-modules-${props.siteId}`,
|
|
351
|
+
() =>
|
|
352
|
+
props.siteId
|
|
353
|
+
? _getSiteForModules(props.siteId).catch(() => null)
|
|
354
|
+
: Promise.resolve(null),
|
|
355
|
+
{ watch: [() => props.siteId] }
|
|
356
|
+
);
|
|
357
|
+
|
|
358
|
+
/** `props.permissions`, narrowed to what this client - and this site - was given. */
|
|
336
359
|
const offeredPermissions = computed(() =>
|
|
337
|
-
catalogueForOrg(
|
|
360
|
+
catalogueForOrg(
|
|
361
|
+
props.permissions ?? {},
|
|
362
|
+
effectiveModules(
|
|
363
|
+
(orgForModules.value as any)?.modules,
|
|
364
|
+
(siteForModules.value as any)?.metadata?.modules
|
|
365
|
+
)
|
|
366
|
+
)
|
|
338
367
|
);
|
|
339
368
|
|
|
340
369
|
const { getRoles: _getRoles } = useRole();
|
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.4.2-staging.
|
|
5
|
+
"version": "4.4.2-staging.292",
|
|
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.",
|
package/utils/org-modules.ts
CHANGED
|
@@ -72,3 +72,43 @@ export function catalogueForOrg<T extends Record<string, unknown>>(
|
|
|
72
72
|
*/
|
|
73
73
|
return (Object.keys(narrowed).length ? narrowed : catalogue) as T;
|
|
74
74
|
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* TIER THREE: THE MODULES A SITE'S ROLE EDITOR MAY OFFER.
|
|
78
|
+
*
|
|
79
|
+
* The client copy of `core src/utils/site-modules.util.ts`
|
|
80
|
+
* (`effectiveSiteModules`), same cases, same fail-open rule. R1, 2026-09-10:
|
|
81
|
+
* whatever Seven365 gave the ORGANISATION is the only set the organisation can
|
|
82
|
+
* give to a SITE, and then to that site's team members.
|
|
83
|
+
*
|
|
84
|
+
* Seven365 -> organizations.modules tier one
|
|
85
|
+
* the org -> sites.metadata.modules tier two
|
|
86
|
+
* the org -> a site role's permissions THIS - the editor offers the
|
|
87
|
+
* intersection of the two above
|
|
88
|
+
*
|
|
89
|
+
* Returns `[]` for EVERYTHING, exactly as the org tier does, so `catalogueForOrg`
|
|
90
|
+
* reads the same whichever tier fed it.
|
|
91
|
+
*
|
|
92
|
+
* Fails open at every step, and an intersection that comes out EMPTY falls back
|
|
93
|
+
* to the organisation's list rather than to nothing: the likeliest cause of a
|
|
94
|
+
* site list matching nothing is that Seven365 changed the org's set and the
|
|
95
|
+
* site's went stale, and a role editor offering zero boxes is indistinguishable
|
|
96
|
+
* from a broken screen.
|
|
97
|
+
*/
|
|
98
|
+
export function effectiveModules(
|
|
99
|
+
orgModules: readonly string[] | null | undefined,
|
|
100
|
+
siteModules: readonly string[] | null | undefined,
|
|
101
|
+
): string[] {
|
|
102
|
+
const org = Array.isArray(orgModules) ? orgModules.filter(isKey) : [];
|
|
103
|
+
const site = Array.isArray(siteModules) ? siteModules.filter(isKey) : [];
|
|
104
|
+
|
|
105
|
+
if (!org.length) return site;
|
|
106
|
+
if (!site.length) return org;
|
|
107
|
+
|
|
108
|
+
const allowed = site.filter((key) => org.includes(key));
|
|
109
|
+
return allowed.length ? allowed : org;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function isKey(value: unknown): value is string {
|
|
113
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
114
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* READABLE NAMES FOR THE ROLE EDITOR.
|
|
3
|
+
*
|
|
4
|
+
* Owner requirement R5, 2026-09-10: the whole thing must be user-friendly,
|
|
5
|
+
* straightforward, and not hard to understand, use or assign.
|
|
6
|
+
*
|
|
7
|
+
* The role editor showed the raw catalogue keys — `work_orders`, `SOA-mgmt`,
|
|
8
|
+
* `buildingUnitManagement`, `toilet_locations`, `bulletin-videos-mgmt` — and
|
|
9
|
+
* asked a client to build a role out of them. Production has 238 distinct role
|
|
10
|
+
* names across 390 roles, all hand-built from that list.
|
|
11
|
+
*
|
|
12
|
+
* ## Derived, not hand-listed
|
|
13
|
+
*
|
|
14
|
+
* A hand-written map of 47 names stops covering the catalogue the day a module
|
|
15
|
+
* is added to it, silently and invisibly. The rule handles forty of them;
|
|
16
|
+
* `RESOURCE_LABELS` exists only for the names the rule still gets wrong, and a
|
|
17
|
+
* test fails if it grows into a catalogue of its own.
|
|
18
|
+
*
|
|
19
|
+
* ## The key is never touched
|
|
20
|
+
*
|
|
21
|
+
* These functions are display only. Every stored value, every request body and
|
|
22
|
+
* every `resource:action` string is unchanged — a label that drifts can confuse
|
|
23
|
+
* somebody, but it cannot grant or revoke anything.
|
|
24
|
+
*
|
|
25
|
+
* Lives in `utils/` because BOTH role dialogs render the same tree and each had
|
|
26
|
+
* its own private copy of a weaker version. Two copies of a display rule is how
|
|
27
|
+
* the create dialog and the edit dialog start naming the same module
|
|
28
|
+
* differently.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/** Words that are acronyms, not words. `SOA-mgmt` must not read as "Soa". */
|
|
32
|
+
const ACRONYMS: Record<string, string> = {
|
|
33
|
+
soa: "SOA",
|
|
34
|
+
nfc: "NFC",
|
|
35
|
+
cctv: "CCTV",
|
|
36
|
+
anpr: "ANPR",
|
|
37
|
+
qr: "QR",
|
|
38
|
+
hid: "HID",
|
|
39
|
+
id: "ID",
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** Only where the rule below still reads wrong. Keep it short. */
|
|
43
|
+
export const RESOURCE_LABELS: Record<string, string> = {
|
|
44
|
+
"SOA-mgmt": "Statements of account",
|
|
45
|
+
buildingUnitManagement: "Building units",
|
|
46
|
+
"daily-occurrence-books": "Daily occurrence book",
|
|
47
|
+
"daily-occurrence-entries": "Daily occurrence entries",
|
|
48
|
+
"my-attendance": "My attendance",
|
|
49
|
+
"online-form-configuration": "Online forms",
|
|
50
|
+
"bulletin-videos-mgmt": "Bulletin videos",
|
|
51
|
+
"access-card-mgmt": "Access cards",
|
|
52
|
+
feedbacks: "Feedback",
|
|
53
|
+
roles: "Roles and permissions",
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* `work_orders` -> `Work orders`.
|
|
58
|
+
*
|
|
59
|
+
* Sentence case, not Title Case: a list of 47 Title Cased phrases is harder to
|
|
60
|
+
* scan, not easier.
|
|
61
|
+
*/
|
|
62
|
+
export function formatResourceLabel(key: string): string {
|
|
63
|
+
if (!key) return "";
|
|
64
|
+
if (RESOURCE_LABELS[key]) return RESOURCE_LABELS[key];
|
|
65
|
+
|
|
66
|
+
const words = key
|
|
67
|
+
// `buildingUnitManagement` -> `building Unit Management`
|
|
68
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
|
69
|
+
.split(/[-_\s]+/)
|
|
70
|
+
.filter(Boolean)
|
|
71
|
+
.map((word) => (word.toLowerCase() === "mgmt" ? "management" : word));
|
|
72
|
+
|
|
73
|
+
return words
|
|
74
|
+
.map((word, index) => {
|
|
75
|
+
const acronym = ACRONYMS[word.toLowerCase()];
|
|
76
|
+
if (acronym) return acronym;
|
|
77
|
+
const lower = word.toLowerCase();
|
|
78
|
+
return index === 0 ? lower.charAt(0).toUpperCase() + lower.slice(1) : lower;
|
|
79
|
+
})
|
|
80
|
+
.join(" ");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* `see-all-work-orders` -> `see all work orders`.
|
|
85
|
+
*
|
|
86
|
+
* Left lower case: it sits under a resource heading and reads as a phrase
|
|
87
|
+
* completing it, not as a title of its own. Both dialogs did
|
|
88
|
+
* `.replace(/-/g, " ")` inline; this keeps them from drifting apart, and keeps
|
|
89
|
+
* an acronym from being lower-cased into nonsense.
|
|
90
|
+
*/
|
|
91
|
+
export function formatActionLabel(action: string): string {
|
|
92
|
+
if (!action) return "";
|
|
93
|
+
return action
|
|
94
|
+
.split(/[-_\s]+/)
|
|
95
|
+
.filter(Boolean)
|
|
96
|
+
.map((word) => ACRONYMS[word.toLowerCase()] ?? word.toLowerCase())
|
|
97
|
+
.join(" ");
|
|
98
|
+
}
|