@7365admin1/layer-common 4.3.1 → 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 +10 -4
- package/components/RolePermissionMain.vue +37 -4
- package/package.json +1 -1
- package/utils/org-modules.ts +74 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
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
|
+
|
|
3
9
|
## 4.3.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -854,11 +860,11 @@
|
|
|
854
860
|
`utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
|
|
855
861
|
own rule from two endpoints the console already calls, unprojected:
|
|
856
862
|
|
|
857
|
-
|
|
858
|
-
|
|
863
|
+
GET /api/members/user/:user/app/admin the Seven365 staff membership
|
|
864
|
+
GET /api/roles/id/:role that membership's role document
|
|
859
865
|
|
|
860
|
-
|
|
861
|
-
|
|
866
|
+
owner = member.type === "admin" && role.type === "admin" && role.default === true
|
|
867
|
+
staff = member.type === "admin" && role.type === "admin"
|
|
862
868
|
|
|
863
869
|
`role.default` is the marker because it is the only property of a platform
|
|
864
870
|
staff role no API caller can set - `role.controller.ts` validates create and
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
<v-dialog v-model="createDialog" width="500" persistent>
|
|
97
97
|
<RolePermissionFormCreate
|
|
98
98
|
@cancel="createDialog = false"
|
|
99
|
-
: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);
|
|
@@ -425,7 +458,7 @@ const roleId = ref("");
|
|
|
425
458
|
* editor and the server's own checks are untouched.
|
|
426
459
|
*/
|
|
427
460
|
const permissionCatalogueSize = computed(() =>
|
|
428
|
-
Object.values(
|
|
461
|
+
Object.values(offeredPermissions.value ?? {}).reduce(
|
|
429
462
|
(total: number, actions: any) =>
|
|
430
463
|
total + Object.keys(actions ?? {}).length,
|
|
431
464
|
0
|
|
@@ -506,8 +539,8 @@ function filterPermissions(
|
|
|
506
539
|
|
|
507
540
|
const Permissions = computed(() => {
|
|
508
541
|
return edit.value
|
|
509
|
-
?
|
|
510
|
-
: filterPermissions(
|
|
542
|
+
? offeredPermissions.value
|
|
543
|
+
: filterPermissions(offeredPermissions.value, originalPermissions.value);
|
|
511
544
|
});
|
|
512
545
|
|
|
513
546
|
function successfulUpdate() {
|
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
|
+
"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
|
+
}
|