@7365admin1/layer-common 4.12.3 → 4.13.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 +16 -4
- package/assets/css/screens.css +15 -0
- package/components/InvitationClientForm.vue +119 -24
- package/components/RolePermissionMain.vue +35 -7
- package/composables/useUser.ts +6 -2
- package/package.json +2 -2
- package/utils/client-invite-modules.ts +67 -2
- package/utils/org-modules.ts +58 -1
- package/utils/permission-labels.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @iservice365/layer-common
|
|
2
2
|
|
|
3
|
+
## 4.13.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b3563db: Invite Client takes one application per invitation, its dialog scrolls so every module, the owner role and Submit are reachable, and Feedback is offered once (both spellings sent together). Screen modals shown outside a v-dialog now scroll their body.
|
|
8
|
+
|
|
9
|
+
## 4.13.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- ec3c570: Invite Client: for a new client, Seven365 now sets the owner's role permissions per application next to the modules (all permissions of the ticked modules ticked by default, only those offered) and sends them as `permissions`. Role editors (`RolePermissionMain`) offer only what that owner role allows for its application; new `ownerGrant` / `catalogueForOwnerGrant` in `utils/org-modules`. The form's site value is now actually sent.
|
|
14
|
+
|
|
3
15
|
## 4.12.3
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -1101,11 +1113,11 @@
|
|
|
1101
1113
|
`utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
|
|
1102
1114
|
own rule from two endpoints the console already calls, unprojected:
|
|
1103
1115
|
|
|
1104
|
-
|
|
1105
|
-
|
|
1116
|
+
GET /api/members/user/:user/app/admin the Seven365 staff membership
|
|
1117
|
+
GET /api/roles/id/:role that membership's role document
|
|
1106
1118
|
|
|
1107
|
-
|
|
1108
|
-
|
|
1119
|
+
owner = member.type === "admin" && role.type === "admin" && role.default === true
|
|
1120
|
+
staff = member.type === "admin" && role.type === "admin"
|
|
1109
1121
|
|
|
1110
1122
|
`role.default` is the marker because it is the only property of a platform
|
|
1111
1123
|
staff role no API caller can set - `role.controller.ts` validates create and
|
package/assets/css/screens.css
CHANGED
|
@@ -246,6 +246,19 @@
|
|
|
246
246
|
box-shadow: var(--shadow-modal) !important;
|
|
247
247
|
background: var(--card) !important;
|
|
248
248
|
max-height: calc(100vh - 32px);
|
|
249
|
+
/*
|
|
250
|
+
* A column, so the body below can take what is left and scroll. Inside a
|
|
251
|
+
* `v-dialog` Vuetify already makes the card a column; a card shown in a
|
|
252
|
+
* plain overlay (Client list's Invite Client) did not, so its body grew past
|
|
253
|
+
* the max-height, the card clipped it, and Submit was unreachable.
|
|
254
|
+
*/
|
|
255
|
+
display: flex;
|
|
256
|
+
flex-direction: column;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
.screen-modal > .v-card-title,
|
|
260
|
+
.screen-modal > .screen-modal__footer {
|
|
261
|
+
flex-shrink: 0;
|
|
249
262
|
}
|
|
250
263
|
|
|
251
264
|
.screen-modal .v-card-title {
|
|
@@ -258,6 +271,8 @@
|
|
|
258
271
|
|
|
259
272
|
.screen-modal__body {
|
|
260
273
|
overflow-y: auto;
|
|
274
|
+
flex: 1 1 auto;
|
|
275
|
+
min-height: 0;
|
|
261
276
|
font-size: var(--fs-cell);
|
|
262
277
|
}
|
|
263
278
|
|
|
@@ -21,17 +21,18 @@
|
|
|
21
21
|
</div>
|
|
22
22
|
</v-col>
|
|
23
23
|
|
|
24
|
-
<!--
|
|
24
|
+
<!--
|
|
25
|
+
ONE APPLICATION PER INVITATION (owner, 2026-09-15: "you should not
|
|
26
|
+
allowing to choose multiple application during the invite"). The
|
|
27
|
+
modules and the owner role below belong to that one application.
|
|
28
|
+
-->
|
|
25
29
|
<v-col v-if="APP" cols="12" class="mt-2">
|
|
26
30
|
<InputLabel title="App" required />
|
|
27
31
|
<v-autocomplete
|
|
28
|
-
|
|
32
|
+
:model-value="invite.app[0] ?? null"
|
|
29
33
|
:items="apps"
|
|
30
34
|
item-title="title"
|
|
31
35
|
item-value="value"
|
|
32
|
-
multiple
|
|
33
|
-
chips
|
|
34
|
-
closable-chips
|
|
35
36
|
class="filter-field"
|
|
36
37
|
density="comfortable"
|
|
37
38
|
:rules="[requiredRule]"
|
|
@@ -42,16 +43,6 @@
|
|
|
42
43
|
v-bind="itemProps"
|
|
43
44
|
:disabled="item.raw.disabled"
|
|
44
45
|
>
|
|
45
|
-
<template #prepend>
|
|
46
|
-
<v-checkbox-btn
|
|
47
|
-
:model-value="invite.app.includes(item.raw.value)"
|
|
48
|
-
:disabled="item.raw.disabled"
|
|
49
|
-
color="primary"
|
|
50
|
-
class="filter-field"
|
|
51
|
-
density="comfortable"
|
|
52
|
-
/>
|
|
53
|
-
</template>
|
|
54
|
-
|
|
55
46
|
<template #title>
|
|
56
47
|
<span :class="item.raw.disabled ? 'text-disabled' : ''">
|
|
57
48
|
{{ item.raw.title }}
|
|
@@ -78,9 +69,8 @@
|
|
|
78
69
|
<div v-for="app in invite.app" :key="`modules-${app}`" class="mb-4">
|
|
79
70
|
<InputLabel :title="`Modules for ${appTitle(app)}`" required />
|
|
80
71
|
<p class="text-caption text-medium-emphasis mb-2">
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
details.
|
|
72
|
+
Only the modules ticked here are available to this client. You
|
|
73
|
+
can change this later on the client's details.
|
|
84
74
|
</p>
|
|
85
75
|
<div v-for="group in inviteModuleGroups(app)" :key="`${app}-${group.key}`" class="mb-2">
|
|
86
76
|
<div class="text-subtitle-2">{{ group.label }}</div>
|
|
@@ -107,6 +97,49 @@
|
|
|
107
97
|
</v-col>
|
|
108
98
|
</v-row>
|
|
109
99
|
</div>
|
|
100
|
+
|
|
101
|
+
<!--
|
|
102
|
+
THE OWNER ROLE (owner, 2026-09-15): Seven365 chooses the
|
|
103
|
+
client owner's permissions with the modules. Only permissions
|
|
104
|
+
of ticked modules are offered, all ticked to start.
|
|
105
|
+
-->
|
|
106
|
+
<div class="mt-4" data-test="invite-owner-role">
|
|
107
|
+
<InputLabel :title="`Owner role for ${appTitle(app)}`" required />
|
|
108
|
+
<p class="text-caption text-medium-emphasis mb-2">
|
|
109
|
+
The client's owner gets exactly the permissions ticked here in
|
|
110
|
+
{{ appTitle(app) }}. They can only give their own staff roles
|
|
111
|
+
within these. Unticking a module above removes its permissions.
|
|
112
|
+
</p>
|
|
113
|
+
<v-expansion-panels multiple variant="accordion">
|
|
114
|
+
<v-expansion-panel
|
|
115
|
+
v-for="(actions, resource) in roleCatalogue(app)"
|
|
116
|
+
:key="`${app}-role-${resource}`"
|
|
117
|
+
>
|
|
118
|
+
<v-expansion-panel-title>
|
|
119
|
+
<span class="text-body-2">{{ formatResourceLabel(String(resource)) }}</span>
|
|
120
|
+
<v-spacer />
|
|
121
|
+
<span class="text-caption text-medium-emphasis mr-2">
|
|
122
|
+
{{ heldCount(app, String(resource)) }} / {{ Object.keys(actions || {}).length }}
|
|
123
|
+
</span>
|
|
124
|
+
</v-expansion-panel-title>
|
|
125
|
+
<v-expansion-panel-text>
|
|
126
|
+
<v-checkbox
|
|
127
|
+
v-for="(meta, action) in actions"
|
|
128
|
+
:key="`${app}-${resource}-${action}`"
|
|
129
|
+
:model-value="isHeld(app, `${resource}:${action}`)"
|
|
130
|
+
:label="meta?.description || formatResourceLabel(String(action))"
|
|
131
|
+
density="compact"
|
|
132
|
+
hide-details
|
|
133
|
+
color="primary"
|
|
134
|
+
@update:model-value="setHeld(app, `${resource}:${action}`, !!$event)"
|
|
135
|
+
/>
|
|
136
|
+
</v-expansion-panel-text>
|
|
137
|
+
</v-expansion-panel>
|
|
138
|
+
</v-expansion-panels>
|
|
139
|
+
<div v-if="!ownerPermissions(app).length" class="text-caption text-error mt-2">
|
|
140
|
+
Tick at least one permission for the owner.
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
110
143
|
</div>
|
|
111
144
|
</v-col>
|
|
112
145
|
|
|
@@ -168,7 +201,7 @@
|
|
|
168
201
|
block
|
|
169
202
|
variant="flat"
|
|
170
203
|
class="text-none screen-btn-primary"
|
|
171
|
-
:disabled="!validForm"
|
|
204
|
+
:disabled="!validForm || !ownerRoleComplete"
|
|
172
205
|
:loading="loading.submittingForm"
|
|
173
206
|
@click="submit"
|
|
174
207
|
>
|
|
@@ -189,7 +222,7 @@ import useUser from '../composables/useUser'
|
|
|
189
222
|
import useUtils from '../composables/useUtils'
|
|
190
223
|
import useOrg from '../composables/useOrg'
|
|
191
224
|
import useMember from '../composables/useMember'
|
|
192
|
-
import { inviteModuleGroups } from '../utils/client-invite-modules'
|
|
225
|
+
import { catalogueStrings, inviteModuleGroups, inviteModuleKeys, inviteRoleCatalogue } from '../utils/client-invite-modules'
|
|
193
226
|
import { ALWAYS_ALLOWED_MODULES } from '../utils/org-modules'
|
|
194
227
|
import { formatResourceLabel } from '../utils/permission-labels'
|
|
195
228
|
|
|
@@ -369,11 +402,71 @@ function syncModules(chosen: string[]) {
|
|
|
369
402
|
|
|
370
403
|
syncModules(invite.value.app)
|
|
371
404
|
|
|
405
|
+
/* ================= NEW CLIENT: OWNER ROLE ================= */
|
|
406
|
+
/*
|
|
407
|
+
* What Seven365 UNTICKED, per application. The owner's permissions are every
|
|
408
|
+
* permission the ticked modules offer minus these, so ticking a module back on
|
|
409
|
+
* brings its permissions back ticked, and unticking one drops them.
|
|
410
|
+
*/
|
|
411
|
+
const uncheckedByApp = ref<Record<string, string[]>>({})
|
|
412
|
+
|
|
413
|
+
// Built once per change of the chosen apps or modules, not once per checkbox.
|
|
414
|
+
const roleCatalogues = computed(() =>
|
|
415
|
+
Object.fromEntries(
|
|
416
|
+
invite.value.app.map(app => [
|
|
417
|
+
app,
|
|
418
|
+
inviteRoleCatalogue(app, [...ALWAYS_ALLOWED_MODULES, ...(modulesByApp.value[app] ?? [])]),
|
|
419
|
+
])
|
|
420
|
+
)
|
|
421
|
+
)
|
|
422
|
+
|
|
423
|
+
function roleCatalogue(app: string) {
|
|
424
|
+
return roleCatalogues.value[app] ?? {}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
const ownerPermissionsByApp = computed(() =>
|
|
428
|
+
Object.fromEntries(
|
|
429
|
+
invite.value.app.map(app => {
|
|
430
|
+
const unchecked = uncheckedByApp.value[app] ?? []
|
|
431
|
+
return [app, catalogueStrings(roleCatalogue(app)).filter(p => !unchecked.includes(p))]
|
|
432
|
+
})
|
|
433
|
+
)
|
|
434
|
+
)
|
|
435
|
+
|
|
436
|
+
function ownerPermissions(app: string): string[] {
|
|
437
|
+
return ownerPermissionsByApp.value[app] ?? []
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function isHeld(app: string, permission: string) {
|
|
441
|
+
return !(uncheckedByApp.value[app] ?? []).includes(permission)
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function heldCount(app: string, resource: string) {
|
|
445
|
+
return ownerPermissions(app).filter(p => p.startsWith(`${resource}:`)).length
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function setHeld(app: string, permission: string, held: boolean) {
|
|
449
|
+
const unchecked = new Set(uncheckedByApp.value[app] ?? [])
|
|
450
|
+
if (held) unchecked.delete(permission)
|
|
451
|
+
else unchecked.add(permission)
|
|
452
|
+
uncheckedByApp.value = { ...uncheckedByApp.value, [app]: [...unchecked] }
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// An empty list means EVERYTHING to the permission model, so none ticked cannot be sent.
|
|
456
|
+
const ownerRoleComplete = computed(() =>
|
|
457
|
+
!newClient.value || invite.value.app.every(app => ownerPermissions(app).length > 0)
|
|
458
|
+
)
|
|
459
|
+
|
|
372
460
|
/* ================= EVENTS ================= */
|
|
373
|
-
async function handleUpdateApp(value: string
|
|
461
|
+
async function handleUpdateApp(value: string | null) {
|
|
462
|
+
const chosen = value ? [value] : []
|
|
463
|
+
invite.value.app = chosen
|
|
374
464
|
invite.value.role = ""
|
|
375
465
|
invite.value.site = ""
|
|
376
|
-
|
|
466
|
+
// A different application starts again: all its modules and permissions ticked.
|
|
467
|
+
modulesByApp.value = {}
|
|
468
|
+
uncheckedByApp.value = {}
|
|
469
|
+
syncModules(chosen)
|
|
377
470
|
await refreshRoles()
|
|
378
471
|
}
|
|
379
472
|
|
|
@@ -461,15 +554,17 @@ async function submit() {
|
|
|
461
554
|
modules: [
|
|
462
555
|
...new Set([
|
|
463
556
|
...ALWAYS_ALLOWED_MODULES,
|
|
464
|
-
...(modulesByApp.value[app] ?? inviteModuleGroups(app).flatMap(group => group.modules)),
|
|
557
|
+
...inviteModuleKeys(modulesByApp.value[app] ?? inviteModuleGroups(app).flatMap(group => group.modules)),
|
|
465
558
|
]),
|
|
466
559
|
],
|
|
560
|
+
permissions: ownerPermissions(app),
|
|
467
561
|
}
|
|
468
562
|
: { role: invite.value.role }),
|
|
469
563
|
|
|
470
564
|
org: org.value?._id,
|
|
471
565
|
|
|
472
|
-
siteId
|
|
566
|
+
// `inviteUserClient` reads `site`; `siteId` was silently dropped.
|
|
567
|
+
site: invite.value.site,
|
|
473
568
|
siteName: invite.value.siteName,
|
|
474
569
|
})
|
|
475
570
|
}
|
|
@@ -205,7 +205,9 @@ import { showSiteField } from "../utils/role";
|
|
|
205
205
|
import { holdsPermission } from "../utils/permission-spellings";
|
|
206
206
|
import {
|
|
207
207
|
catalogueForOrg,
|
|
208
|
+
catalogueForOwnerGrant,
|
|
208
209
|
effectiveModules,
|
|
210
|
+
ownerGrant,
|
|
209
211
|
siteModulesForOrg,
|
|
210
212
|
} from "../utils/org-modules";
|
|
211
213
|
|
|
@@ -360,15 +362,41 @@ const { data: siteForModules } = useLazyAsyncData(
|
|
|
360
362
|
{ watch: [() => props.siteId] }
|
|
361
363
|
);
|
|
362
364
|
|
|
365
|
+
/*
|
|
366
|
+
* THE OWNER ROLE SEVEN365 CHOSE (owner, 2026-09-15). A client invited with a
|
|
367
|
+
* chosen owner role can only give its own application's roles within it - the
|
|
368
|
+
* server refuses anything wider (core `boundRoleToOwnerGrant`), so the editor
|
|
369
|
+
* offers only that. Fetched only when the organisation records such a role and
|
|
370
|
+
* this editor edits roles of that application; fails open like the lists above.
|
|
371
|
+
*/
|
|
372
|
+
const grantRoleId = computed(() => {
|
|
373
|
+
const org = orgForModules.value as any;
|
|
374
|
+
return org?.invitedRole && org?.nature === props.type ? String(org.invitedRole) : "";
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
const { getRoleById: _getGrantRole } = useRole();
|
|
378
|
+
|
|
379
|
+
const { data: grantRole } = useLazyAsyncData(
|
|
380
|
+
`owner-grant-${props.orgId}-${props.type}`,
|
|
381
|
+
() =>
|
|
382
|
+
grantRoleId.value
|
|
383
|
+
? _getGrantRole(grantRoleId.value).catch(() => null)
|
|
384
|
+
: Promise.resolve(null),
|
|
385
|
+
{ watch: [grantRoleId] }
|
|
386
|
+
);
|
|
387
|
+
|
|
363
388
|
/** `props.permissions`, narrowed to what this client - and this site - was given. */
|
|
364
389
|
const offeredPermissions = computed(() =>
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
(
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
390
|
+
catalogueForOwnerGrant(
|
|
391
|
+
catalogueForOrg(
|
|
392
|
+
props.permissions ?? {},
|
|
393
|
+
effectiveModules(
|
|
394
|
+
(orgForModules.value as any)?.modules,
|
|
395
|
+
// Only the site's OWN organisation is narrowed by it (owner Q1).
|
|
396
|
+
siteModulesForOrg(siteForModules.value as any, props.orgId)
|
|
397
|
+
)
|
|
398
|
+
),
|
|
399
|
+
ownerGrant(orgForModules.value as any, grantRole.value as any, props.type)
|
|
372
400
|
)
|
|
373
401
|
);
|
|
374
402
|
|
package/composables/useUser.ts
CHANGED
|
@@ -22,7 +22,8 @@ export default function useUser() {
|
|
|
22
22
|
org = '',
|
|
23
23
|
site = '',
|
|
24
24
|
siteName = '',
|
|
25
|
-
modules
|
|
25
|
+
modules,
|
|
26
|
+
permissions
|
|
26
27
|
}: {
|
|
27
28
|
email?: string
|
|
28
29
|
app?: string[]
|
|
@@ -33,6 +34,8 @@ export default function useUser() {
|
|
|
33
34
|
siteName?: string
|
|
34
35
|
/** A new client's modules (Seven365 staff only). */
|
|
35
36
|
modules?: string[]
|
|
37
|
+
/** That client owner's permissions in the application (with modules only). */
|
|
38
|
+
permissions?: string[]
|
|
36
39
|
} = {}) {
|
|
37
40
|
return useNuxtApp().$api<Record<string, any>>('/api/auth/invite/user', {
|
|
38
41
|
method: 'POST',
|
|
@@ -44,7 +47,8 @@ export default function useUser() {
|
|
|
44
47
|
org,
|
|
45
48
|
...(site && { siteId: site }),
|
|
46
49
|
...(siteName && { siteName }),
|
|
47
|
-
...(modules && { modules })
|
|
50
|
+
...(modules && { modules }),
|
|
51
|
+
...(permissions && { permissions })
|
|
48
52
|
}
|
|
49
53
|
})
|
|
50
54
|
}
|
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.13.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.",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"build": "nuxt build .playground",
|
|
37
37
|
"generate": "nuxt generate .playground",
|
|
38
38
|
"preview": "nuxt preview .playground",
|
|
39
|
-
"test": "esbuild composables/useVisitorSocket.ts --format=esm --outfile=test/.build/useVisitorSocket.mjs --log-level=error && esbuild composables/usePlateToastWindow.ts --format=esm --outfile=test/.build/usePlateToastWindow.mjs --log-level=error && node --experimental-strip-types --test \"test/*.test.mjs\" && yarn test:units",
|
|
39
|
+
"test": "esbuild composables/useVisitorSocket.ts --format=esm --outfile=test/.build/useVisitorSocket.mjs --log-level=error && esbuild composables/usePlateToastWindow.ts --format=esm --outfile=test/.build/usePlateToastWindow.mjs --log-level=error && esbuild utils/client-invite-modules.ts --bundle --platform=node --format=esm --outfile=test/.build/client-invite-modules.mjs --log-level=error && node --experimental-strip-types --test \"test/*.test.mjs\" && yarn test:units",
|
|
40
40
|
"test:units": "node --experimental-strip-types --test \"utils/*.test.ts\"",
|
|
41
41
|
"release": "yarn run build && changeset publish"
|
|
42
42
|
},
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PERMISSIONS } from "../constants/permissions";
|
|
2
|
-
import { applicationModules, groupModulesByApplication } from "./module-applications";
|
|
2
|
+
import { APPLICATIONS, applicationModules, groupModulesByApplication } from "./module-applications";
|
|
3
|
+
import { catalogueForOrg, spellingsOf } from "./org-modules";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* THE MODULES A NEW CLIENT IS OFFERED ON "INVITE CLIENT".
|
|
@@ -50,7 +51,71 @@ export function inviteModuleGroups(nature: string): ModuleGroup[] {
|
|
|
50
51
|
const applications = Object.hasOwn(NATURE_APPLICATIONS, nature) ? NATURE_APPLICATIONS[nature] : null;
|
|
51
52
|
|
|
52
53
|
const shown = applications ? groups.filter((group) => applications.includes(group.key)) : groups;
|
|
53
|
-
|
|
54
|
+
const all = ungrouped.length
|
|
54
55
|
? [...shown, { key: "other", label: "Not tied to a service application", modules: ungrouped }]
|
|
55
56
|
: shown;
|
|
57
|
+
|
|
58
|
+
/*
|
|
59
|
+
* One module, one checkbox. Security's catalogue carries both `feedbacks`
|
|
60
|
+
* and the legacy `feedback`, which the server treats as ONE module (core
|
|
61
|
+
* `SPELLING_GROUPS`: ticking either spelling allows both) - so two boxes both
|
|
62
|
+
* read "Feedback", and unticking one while the other stayed ticked hid
|
|
63
|
+
* nothing. The first spelling shown stands for the module; `inviteModuleKeys`
|
|
64
|
+
* sends every spelling of each ticked one.
|
|
65
|
+
*/
|
|
66
|
+
const seen = new Set<string>();
|
|
67
|
+
return all.map((group) => ({
|
|
68
|
+
...group,
|
|
69
|
+
modules: group.modules.filter((key) => {
|
|
70
|
+
const id = spellingsOf(key)[0];
|
|
71
|
+
if (seen.has(id)) return false;
|
|
72
|
+
seen.add(id);
|
|
73
|
+
return true;
|
|
74
|
+
}),
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The module keys to send for the ticked checkboxes: every spelling of each. */
|
|
79
|
+
export function inviteModuleKeys(ticked: readonly string[]): string[] {
|
|
80
|
+
return [...new Set(ticked.flatMap((key) => spellingsOf(key)))];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** `{ resource: { action: { description } } }` - every `use*Permission` shape. */
|
|
84
|
+
export type RoleCatalogue = Record<string, Record<string, { description?: string }>>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* THE CLIENT OWNER'S ROLE, CHOSEN WITH THE MODULES (owner, 2026-09-15).
|
|
88
|
+
*
|
|
89
|
+
* *"There is no option for Seven365 to choose the modules, applications and
|
|
90
|
+
* roles that they will access."* The permissions offered are the application's
|
|
91
|
+
* own role catalogue - the one its role editor uses - narrowed to the ticked
|
|
92
|
+
* modules exactly as the client's own editor narrows it (`catalogueForOrg`), so
|
|
93
|
+
* the owner can never be given, or later give, a permission of a module the
|
|
94
|
+
* client does not have. The server re-checks the same rule.
|
|
95
|
+
*/
|
|
96
|
+
export function inviteRoleCatalogue(nature: string, modules: readonly string[]): RoleCatalogue {
|
|
97
|
+
const applications = Object.hasOwn(NATURE_APPLICATIONS, nature) ? NATURE_APPLICATIONS[nature] : null;
|
|
98
|
+
const merged: RoleCatalogue = {};
|
|
99
|
+
|
|
100
|
+
for (const application of APPLICATIONS) {
|
|
101
|
+
if (applications && !applications.includes(application.key)) continue;
|
|
102
|
+
let permissions: RoleCatalogue = {};
|
|
103
|
+
try {
|
|
104
|
+
permissions = ((application.composable as () => { permissions?: RoleCatalogue })().permissions ?? {}) as RoleCatalogue;
|
|
105
|
+
} catch {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
for (const [resource, actions] of Object.entries(permissions)) {
|
|
109
|
+
merged[resource] = { ...merged[resource], ...actions };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return catalogueForOrg(merged, modules);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Every `resource:action` string a catalogue offers. */
|
|
117
|
+
export function catalogueStrings(catalogue: RoleCatalogue): string[] {
|
|
118
|
+
return Object.entries(catalogue).flatMap(([resource, actions]) =>
|
|
119
|
+
Object.keys(actions ?? {}).map((action) => `${resource}:${action}`),
|
|
120
|
+
);
|
|
56
121
|
}
|
package/utils/org-modules.ts
CHANGED
|
@@ -95,7 +95,8 @@ export const MODULE_SPELLING_GROUPS: readonly (readonly string[])[] = (() => {
|
|
|
95
95
|
return Object.freeze([...groups.values()].map((group) => Object.freeze([...group])));
|
|
96
96
|
})();
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
/** Every spelling of this module, `key` included. */
|
|
99
|
+
export function spellingsOf(key: string): readonly string[] {
|
|
99
100
|
return MODULE_SPELLING_GROUPS.find((group) => group.includes(key)) ?? [key];
|
|
100
101
|
}
|
|
101
102
|
|
|
@@ -216,3 +217,59 @@ export function siteModulesForOrg(
|
|
|
216
217
|
function isKey(value: unknown): value is string {
|
|
217
218
|
return typeof value === "string" && value.trim().length > 0;
|
|
218
219
|
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* TIER ONE-AND-A-HALF: THE PERMISSIONS SEVEN365 CHOSE FOR THE CLIENT'S OWNER.
|
|
223
|
+
*
|
|
224
|
+
* Owner, 2026-09-15: Seven365 chooses the modules AND the owner's role on Invite
|
|
225
|
+
* Client, and the client gives staff only within that. The client half of core
|
|
226
|
+
* `module-ceiling.util ownerGrantCeiling` / `org-modules.util boundToOwnerGrant`,
|
|
227
|
+
* same shape test: the organisation's `invitedRole` is its OWN default role of
|
|
228
|
+
* its own nature holding an enumerated list, and only roles of that nature are
|
|
229
|
+
* capped. Anything else - every client invited before this - returns `null`.
|
|
230
|
+
*/
|
|
231
|
+
export function ownerGrant(
|
|
232
|
+
org: { _id?: unknown; nature?: unknown; invitedRole?: unknown } | null | undefined,
|
|
233
|
+
grantRole: { _id?: unknown; org?: unknown; type?: unknown; default?: unknown; permissions?: unknown } | null | undefined,
|
|
234
|
+
type: string | null | undefined,
|
|
235
|
+
): string[] | null {
|
|
236
|
+
if (!org?.invitedRole || !grantRole || !type || org.nature !== type) return null;
|
|
237
|
+
const permissions = grantRole.permissions;
|
|
238
|
+
const chosen =
|
|
239
|
+
String(grantRole._id ?? "") === String(org.invitedRole) &&
|
|
240
|
+
String(grantRole.org ?? "") === String(org._id ?? "") &&
|
|
241
|
+
grantRole.default === true &&
|
|
242
|
+
grantRole.type === org.nature &&
|
|
243
|
+
Array.isArray(permissions) &&
|
|
244
|
+
permissions.length > 0 &&
|
|
245
|
+
!permissions.includes("*");
|
|
246
|
+
return chosen ? (permissions as unknown[]).map(String) : null;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Narrow a `{ resource: { action } }` catalogue to that grant. Running the
|
|
251
|
+
* organisation (`ALWAYS_ALLOWED_MODULES`) is never narrowed, matching the
|
|
252
|
+
* server. No grant: the catalogue is returned unchanged.
|
|
253
|
+
*/
|
|
254
|
+
export function catalogueForOwnerGrant<T extends Record<string, unknown>>(
|
|
255
|
+
catalogue: T,
|
|
256
|
+
grant: readonly string[] | null | undefined,
|
|
257
|
+
): T {
|
|
258
|
+
if (!grant || !catalogue || typeof catalogue !== "object") return catalogue;
|
|
259
|
+
|
|
260
|
+
const narrowed: Record<string, unknown> = {};
|
|
261
|
+
for (const [resource, actions] of Object.entries(catalogue)) {
|
|
262
|
+
if (ALWAYS_ALLOWED_MODULES.includes(resource)) {
|
|
263
|
+
narrowed[resource] = actions;
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
if (!actions || typeof actions !== "object") continue;
|
|
267
|
+
const kept = Object.fromEntries(
|
|
268
|
+
Object.entries(actions as Record<string, unknown>).filter(([action]) =>
|
|
269
|
+
grant.includes(`${resource}:${action}`),
|
|
270
|
+
),
|
|
271
|
+
);
|
|
272
|
+
if (Object.keys(kept).length) narrowed[resource] = kept;
|
|
273
|
+
}
|
|
274
|
+
return narrowed as T;
|
|
275
|
+
}
|
|
@@ -50,6 +50,8 @@ export const RESOURCE_LABELS: Record<string, string> = {
|
|
|
50
50
|
"bulletin-videos-mgmt": "Bulletin videos",
|
|
51
51
|
"access-card-mgmt": "Access cards",
|
|
52
52
|
feedbacks: "Feedback",
|
|
53
|
+
// The legacy singular resource: its own permission, same module (see `feedbacks`).
|
|
54
|
+
feedback: "Feedback (older app permission)",
|
|
53
55
|
roles: "Roles and permissions",
|
|
54
56
|
};
|
|
55
57
|
|