@7365admin1/layer-common 4.2.18 → 4.2.20
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
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# @iservice365/layer-common
|
|
2
2
|
|
|
3
|
+
## 4.2.20
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 24250ee: Web permission gate follows the estate rule for an empty role list
|
|
8
|
+
|
|
9
|
+
`usePermission().hasPermission` asked `holdsPermission` — a plain string-membership
|
|
10
|
+
test — so a role stored with `permissions: []` was refused everything. `core`
|
|
11
|
+
(`consoleRoleAllowsAll`) and the resident app both read an empty list as "all", so
|
|
12
|
+
one role document meant two different things depending on which client read it.
|
|
13
|
+
|
|
14
|
+
Adds `grantsPermission(held, key)` and points the gate at it: empty means all,
|
|
15
|
+
`"*"` means all, a non-empty list is enforced, and every shipped spelling of a
|
|
16
|
+
grant stays equivalent. `holdsPermission` is unchanged and still refuses an empty
|
|
17
|
+
list — the role editor asks it about a half-built draft, where empty means
|
|
18
|
+
"nothing ticked yet", and swapping the two there would render every box ticked
|
|
19
|
+
and leave an admin unable to tick or untick anything.
|
|
20
|
+
|
|
21
|
+
No stored role, member or user document is written.
|
|
22
|
+
|
|
23
|
+
## 4.2.19
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- 8196fa9: Add the `service-provider-mgmt` resource to the pest-control and pool-mgmt role catalogues
|
|
28
|
+
|
|
29
|
+
Both apps have a Service Providers page (`ServiceProviderMain`, same component
|
|
30
|
+
landscape uses) but `usePestControlPermission` and `usePoolMaintenancePermission`
|
|
31
|
+
carried no `service-provider-mgmt` resource, so the Roles & Permissions editor
|
|
32
|
+
could never grant it to a non-`"*"` role. Landscape already had this resource;
|
|
33
|
+
the same entry (`serviceProviderPermissions` from `useCommonPermissions`) is now
|
|
34
|
+
added to both, identical spelling and actions.
|
|
35
|
+
|
|
36
|
+
Widen only — no existing permission string is removed or re-spelled. The page's
|
|
37
|
+
live gate (`useServiceProviderPermission`, used inside `ServiceProviderMain`)
|
|
38
|
+
is unchanged: it already reads `service-provider-mgmt` off the role directly and
|
|
39
|
+
does not depend on either app's catalogue, so behaviour for every existing role
|
|
40
|
+
is unaffected. Pinned by `test/shared-role-catalogues.test.mjs`
|
|
41
|
+
(mechanical-electrical, which has no Service Providers page, is untouched and
|
|
42
|
+
still pins 15 resources; pest-control and pool-mgmt now pin 16).
|
|
43
|
+
|
|
3
44
|
## 4.2.18
|
|
4
45
|
|
|
5
46
|
### Patch Changes
|
|
@@ -685,11 +726,11 @@
|
|
|
685
726
|
`utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
|
|
686
727
|
own rule from two endpoints the console already calls, unprojected:
|
|
687
728
|
|
|
688
|
-
|
|
689
|
-
|
|
729
|
+
GET /api/members/user/:user/app/admin the Seven365 staff membership
|
|
730
|
+
GET /api/roles/id/:role that membership's role document
|
|
690
731
|
|
|
691
|
-
|
|
692
|
-
|
|
732
|
+
owner = member.type === "admin" && role.type === "admin" && role.default === true
|
|
733
|
+
staff = member.type === "admin" && role.type === "admin"
|
|
693
734
|
|
|
694
735
|
`role.default` is the marker because it is the only property of a platform
|
|
695
736
|
staff role no API caller can set - `role.controller.ts` validates create and
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { grantsPermission } from "../utils/permission-spellings";
|
|
2
2
|
|
|
3
3
|
export default function usePermission() {
|
|
4
4
|
// Permission-Based Access Control with Dynamic Role Creation
|
|
@@ -27,16 +27,24 @@ export default function usePermission() {
|
|
|
27
27
|
): boolean {
|
|
28
28
|
const permissionKey = `${resource}:${action}`;
|
|
29
29
|
|
|
30
|
-
//
|
|
30
|
+
// Does the user's SAVED role grant this? -- `grantsPermission`, never
|
|
31
|
+
// `holdsPermission`.
|
|
31
32
|
//
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
|
|
33
|
+
// Two things are folded in here and both are widening only:
|
|
34
|
+
//
|
|
35
|
+
// 1. Spelling. The same grant is stored under more than one spelling -- the
|
|
36
|
+
// role editor writes `workOrder:see-all-work-orders` (81 roles) but a
|
|
37
|
+
// minority of roles hold `work-orders:see-all-work-orders` (6). An exact
|
|
38
|
+
// test answered "no" for those roles while the console showed the grant.
|
|
39
|
+
// camelCase stays canonical and nothing stored is rewritten.
|
|
40
|
+
// 2. The estate rule. An empty list and `["*"]` both mean everything, as
|
|
41
|
+
// they already do in `core` (`consoleRoleAllowsAll`) and the resident
|
|
42
|
+
// app. This gate was the last place in the estate reading an empty list
|
|
43
|
+
// as "nothing", so one role document meant two different things.
|
|
44
|
+
//
|
|
45
|
+
// The role EDITOR stays on `holdsPermission` -- it asks about a draft, and
|
|
46
|
+
// empty there means "nothing ticked yet". See that file's comments.
|
|
47
|
+
if (!grantsPermission(user.permissions, permissionKey)) {
|
|
40
48
|
return false;
|
|
41
49
|
}
|
|
42
50
|
|
|
@@ -23,6 +23,7 @@ export default function usePestControlPermission() {
|
|
|
23
23
|
feedbackPermissions,
|
|
24
24
|
workOrderPermissions,
|
|
25
25
|
bulletinBoardPermissions,
|
|
26
|
+
serviceProviderPermissions,
|
|
26
27
|
|
|
27
28
|
} = useCommonPermissions();
|
|
28
29
|
const permissions: TPermissions = {
|
|
@@ -32,6 +33,7 @@ export default function usePestControlPermission() {
|
|
|
32
33
|
feedbacks: feedbackPermissions,
|
|
33
34
|
work_orders: workOrderPermissions,
|
|
34
35
|
"bulletin-board": bulletinBoardPermissions,
|
|
36
|
+
"service-provider-mgmt": serviceProviderPermissions,
|
|
35
37
|
|
|
36
38
|
"site-settings": {
|
|
37
39
|
"can-view-site-settings": {
|
|
@@ -23,7 +23,8 @@ export default function usePoolMaintenancePermission() {
|
|
|
23
23
|
feedbackPermissions,
|
|
24
24
|
workOrderPermissions,
|
|
25
25
|
bulletinBoardPermissions,
|
|
26
|
-
|
|
26
|
+
serviceProviderPermissions,
|
|
27
|
+
|
|
27
28
|
} = useCommonPermissions();
|
|
28
29
|
const permissions: TPermissions = {
|
|
29
30
|
members: memberPermissions,
|
|
@@ -32,7 +33,8 @@ export default function usePoolMaintenancePermission() {
|
|
|
32
33
|
feedbacks: feedbackPermissions,
|
|
33
34
|
work_orders: workOrderPermissions,
|
|
34
35
|
"bulletin-board": bulletinBoardPermissions,
|
|
35
|
-
|
|
36
|
+
"service-provider-mgmt": serviceProviderPermissions,
|
|
37
|
+
|
|
36
38
|
"site-settings": {
|
|
37
39
|
"can-view-site-settings": {
|
|
38
40
|
check: true,
|
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.2.
|
|
5
|
+
"version": "4.2.20",
|
|
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.",
|
|
@@ -62,7 +62,19 @@ export function permissionSpellings(value: string): readonly string[] {
|
|
|
62
62
|
return SPELLINGS.get(value) ?? [value];
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* Does this permission list CONTAIN `value`, under any shipped spelling? — the
|
|
67
|
+
* DRAFT MEMBERSHIP PREDICATE.
|
|
68
|
+
*
|
|
69
|
+
* A plain string-membership test and nothing more. An empty list contains
|
|
70
|
+
* nothing, so this answers `false` for it. That is correct here and is relied
|
|
71
|
+
* on: the role editor asks this about a half-built draft, where empty means
|
|
72
|
+
* "nothing ticked yet".
|
|
73
|
+
*
|
|
74
|
+
* This is NOT the allow/deny gate. A saved role's EFFECTIVE grants follow the
|
|
75
|
+
* estate rule (empty and `"*"` both mean everything) — that is
|
|
76
|
+
* `grantsPermission` at the bottom of this file. Do not merge the two.
|
|
77
|
+
*/
|
|
66
78
|
export function holdsPermission(
|
|
67
79
|
held: readonly string[] | undefined | null,
|
|
68
80
|
value: string,
|
|
@@ -85,3 +97,35 @@ export function withoutPermission(
|
|
|
85
97
|
const spellings = permissionSpellings(value);
|
|
86
98
|
return held.filter((item) => !spellings.includes(item));
|
|
87
99
|
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Does a STORED role's permission list grant `value`? — the ALLOW/DENY GATE.
|
|
103
|
+
*
|
|
104
|
+
* This is the estate rule, and it is deliberately NOT the same question as
|
|
105
|
+
* `holdsPermission` above. Use this one, and only this one, when the list you
|
|
106
|
+
* hold is a role that has been SAVED:
|
|
107
|
+
*
|
|
108
|
+
* - an EMPTY list means everything. `core`'s `createDefaultUser()` seeds a
|
|
109
|
+
* role with `permissions: []`, not `["*"]`, so a plain membership test
|
|
110
|
+
* refuses accounts the estate has always admitted.
|
|
111
|
+
* - `"*"` means everything, the short-circuit it has everywhere else.
|
|
112
|
+
* - a NON-EMPTY list is enforced, under any shipped spelling of the grant.
|
|
113
|
+
*
|
|
114
|
+
* Matches `core`'s `consoleRoleAllowsAll` and the resident app's
|
|
115
|
+
* `hasPermission`, so one role document means the same thing on the API, on
|
|
116
|
+
* mobile and in the web console.
|
|
117
|
+
*
|
|
118
|
+
* DO NOT reach for this from the role editor. The editor asks its question
|
|
119
|
+
* about a half-built DRAFT list, where "empty" means "nothing ticked yet" and
|
|
120
|
+
* must answer `false` — that is `holdsPermission`, and swapping the two there
|
|
121
|
+
* renders every box ticked, makes "Deselect all" spring back, and leaves an
|
|
122
|
+
* admin unable to tick or untick anything.
|
|
123
|
+
*/
|
|
124
|
+
export function grantsPermission(
|
|
125
|
+
held: readonly string[] | undefined | null,
|
|
126
|
+
value: string,
|
|
127
|
+
): boolean {
|
|
128
|
+
if (!held?.length) return true;
|
|
129
|
+
if (held.includes("*")) return true;
|
|
130
|
+
return holdsPermission(held, value);
|
|
131
|
+
}
|