@byline/admin 2.4.0 → 2.4.2
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/dist/abilities.js +5 -24
- package/dist/index.js +8 -30
- package/dist/lib/assert-admin-actor.js +13 -74
- package/dist/lib/create-command.js +6 -16
- package/dist/modules/admin-account/commands.js +35 -24
- package/dist/modules/admin-account/components/change-password.d.ts +8 -0
- package/dist/modules/admin-account/components/change-password.js +192 -0
- package/dist/modules/admin-account/components/change-password.module.js +8 -0
- package/dist/modules/admin-account/components/change-password_module.css +27 -0
- package/dist/modules/admin-account/components/container.d.ts +29 -0
- package/dist/modules/admin-account/components/container.js +298 -0
- package/dist/modules/admin-account/components/container.module.js +28 -0
- package/dist/modules/admin-account/components/container_module.css +106 -0
- package/dist/modules/admin-account/components/update.d.ts +8 -0
- package/dist/modules/admin-account/components/update.js +207 -0
- package/dist/modules/admin-account/components/update.module.js +8 -0
- package/dist/modules/admin-account/components/update_module.css +27 -0
- package/dist/modules/admin-account/errors.js +14 -45
- package/dist/modules/admin-account/index.js +4 -34
- package/dist/modules/admin-account/schemas.js +25 -59
- package/dist/modules/admin-account/service.js +56 -61
- package/dist/modules/admin-permissions/abilities.js +6 -24
- package/dist/modules/admin-permissions/commands.js +42 -28
- package/dist/modules/admin-permissions/components/inspector.d.ts +4 -0
- package/dist/modules/admin-permissions/components/inspector.js +284 -0
- package/dist/modules/admin-permissions/components/inspector.module.js +56 -0
- package/dist/modules/admin-permissions/components/inspector_module.css +238 -0
- package/dist/modules/admin-permissions/dto.js +3 -16
- package/dist/modules/admin-permissions/errors.js +14 -27
- package/dist/modules/admin-permissions/index.js +6 -26
- package/dist/modules/admin-permissions/repository.js +1 -8
- package/dist/modules/admin-permissions/schemas.js +33 -70
- package/dist/modules/admin-permissions/service.js +88 -92
- package/dist/modules/admin-roles/abilities.js +8 -30
- package/dist/modules/admin-roles/commands.js +89 -55
- package/dist/modules/admin-roles/components/create.d.ts +7 -0
- package/dist/modules/admin-roles/components/create.js +177 -0
- package/dist/modules/admin-roles/components/create.module.js +8 -0
- package/dist/modules/admin-roles/components/create_module.css +27 -0
- package/dist/modules/admin-roles/components/permissions.d.ts +10 -0
- package/dist/modules/admin-roles/components/permissions.js +303 -0
- package/dist/modules/admin-roles/components/permissions.module.js +44 -0
- package/dist/modules/admin-roles/components/permissions_module.css +192 -0
- package/dist/modules/admin-roles/components/update.d.ts +8 -0
- package/dist/modules/admin-roles/components/update.js +166 -0
- package/dist/modules/admin-roles/components/update.module.js +8 -0
- package/dist/modules/admin-roles/components/update_module.css +27 -0
- package/dist/modules/admin-roles/dto.js +3 -16
- package/dist/modules/admin-roles/errors.js +16 -40
- package/dist/modules/admin-roles/index.js +6 -26
- package/dist/modules/admin-roles/repository.js +1 -8
- package/dist/modules/admin-roles/schemas.js +41 -71
- package/dist/modules/admin-roles/service.js +79 -82
- package/dist/modules/admin-users/abilities.js +9 -38
- package/dist/modules/admin-users/commands.js +92 -50
- package/dist/modules/admin-users/components/create.d.ts +8 -0
- package/dist/modules/admin-users/components/create.js +268 -0
- package/dist/modules/admin-users/components/create.module.js +10 -0
- package/dist/modules/admin-users/components/create_module.css +45 -0
- package/dist/modules/admin-users/components/roles.d.ts +11 -0
- package/dist/modules/admin-users/components/roles.js +148 -0
- package/dist/modules/admin-users/components/roles.module.js +18 -0
- package/dist/modules/admin-users/components/roles_module.css +75 -0
- package/dist/modules/admin-users/components/set-password.d.ts +8 -0
- package/dist/modules/admin-users/components/set-password.js +170 -0
- package/dist/modules/admin-users/components/set-password.module.js +9 -0
- package/dist/modules/admin-users/components/set-password_module.css +31 -0
- package/dist/modules/admin-users/components/update.d.ts +8 -0
- package/dist/modules/admin-users/components/update.js +254 -0
- package/dist/modules/admin-users/components/update.module.js +9 -0
- package/dist/modules/admin-users/components/update_module.css +34 -0
- package/dist/modules/admin-users/dto.js +3 -18
- package/dist/modules/admin-users/errors.js +17 -43
- package/dist/modules/admin-users/index.js +7 -27
- package/dist/modules/admin-users/repository.js +1 -8
- package/dist/modules/admin-users/schemas.js +44 -75
- package/dist/modules/admin-users/seed-super-admin.js +9 -34
- package/dist/modules/admin-users/service.js +76 -91
- package/dist/modules/auth/components/sign-in-form.d.ts +12 -0
- package/dist/modules/auth/components/sign-in-form.js +115 -0
- package/dist/modules/auth/components/sign-in-form.module.js +12 -0
- package/dist/modules/auth/components/sign-in-form_module.css +41 -0
- package/dist/modules/auth/index.js +3 -24
- package/dist/modules/auth/jwt-session-provider.js +179 -149
- package/dist/modules/auth/password.js +11 -53
- package/dist/modules/auth/phc.js +21 -54
- package/dist/modules/auth/refresh-tokens-repository.js +1 -8
- package/dist/modules/auth/resolve-actor.js +6 -28
- package/dist/services/admin-services-context.d.ts +16 -0
- package/dist/services/admin-services-context.js +13 -0
- package/dist/services/admin-services-types.d.ts +129 -0
- package/dist/services/admin-services-types.js +1 -0
- package/dist/store.js +1 -8
- package/dist/vendor/noble-argon2/_blake.js +277 -45
- package/dist/vendor/noble-argon2/_md.js +81 -136
- package/dist/vendor/noble-argon2/_u64.js +65 -67
- package/dist/vendor/noble-argon2/argon2.js +181 -342
- package/dist/vendor/noble-argon2/blake2.js +252 -327
- package/dist/vendor/noble-argon2/utils.js +110 -490
- package/dist/vendor/noble-argon2/utils.js.LICENSE.txt +1 -0
- package/package.json +89 -10
- package/src/abilities.ts +32 -0
- package/src/declarations.d.ts +4 -0
- package/src/index.ts +39 -0
- package/src/lib/assert-admin-actor.ts +90 -0
- package/src/lib/create-command.ts +109 -0
- package/src/modules/admin-account/commands.ts +76 -0
- package/src/modules/admin-account/components/change-password.module.css +40 -0
- package/src/modules/admin-account/components/change-password.tsx +232 -0
- package/src/modules/admin-account/components/container.module.css +158 -0
- package/src/modules/admin-account/components/container.tsx +229 -0
- package/src/modules/admin-account/components/update.module.css +40 -0
- package/src/modules/admin-account/components/update.tsx +263 -0
- package/src/modules/admin-account/errors.ts +75 -0
- package/src/modules/admin-account/index.ts +60 -0
- package/src/modules/admin-account/schemas.ts +84 -0
- package/src/modules/admin-account/service.ts +92 -0
- package/src/modules/admin-permissions/abilities.ts +46 -0
- package/src/modules/admin-permissions/commands.ts +103 -0
- package/src/modules/admin-permissions/components/inspector.module.css +326 -0
- package/src/modules/admin-permissions/components/inspector.tsx +298 -0
- package/src/modules/admin-permissions/dto.ts +28 -0
- package/src/modules/admin-permissions/errors.ts +57 -0
- package/src/modules/admin-permissions/index.ts +72 -0
- package/src/modules/admin-permissions/repository.ts +49 -0
- package/src/modules/admin-permissions/schemas.ts +128 -0
- package/src/modules/admin-permissions/service.ts +137 -0
- package/src/modules/admin-roles/abilities.ts +62 -0
- package/src/modules/admin-roles/commands.ts +161 -0
- package/src/modules/admin-roles/components/create.module.css +40 -0
- package/src/modules/admin-roles/components/create.tsx +218 -0
- package/src/modules/admin-roles/components/permissions.module.css +279 -0
- package/src/modules/admin-roles/components/permissions.tsx +396 -0
- package/src/modules/admin-roles/components/update.module.css +40 -0
- package/src/modules/admin-roles/components/update.tsx +218 -0
- package/src/modules/admin-roles/dto.ts +30 -0
- package/src/modules/admin-roles/errors.ts +76 -0
- package/src/modules/admin-roles/index.ts +81 -0
- package/src/modules/admin-roles/repository.ts +96 -0
- package/src/modules/admin-roles/schemas.ts +139 -0
- package/src/modules/admin-roles/service.ts +136 -0
- package/src/modules/admin-users/abilities.ts +76 -0
- package/src/modules/admin-users/commands.ts +157 -0
- package/src/modules/admin-users/components/create.module.css +63 -0
- package/src/modules/admin-users/components/create.tsx +323 -0
- package/src/modules/admin-users/components/roles.module.css +119 -0
- package/src/modules/admin-users/components/roles.tsx +172 -0
- package/src/modules/admin-users/components/set-password.module.css +46 -0
- package/src/modules/admin-users/components/set-password.tsx +199 -0
- package/src/modules/admin-users/components/update.module.css +49 -0
- package/src/modules/admin-users/components/update.tsx +328 -0
- package/src/modules/admin-users/dto.ts +39 -0
- package/src/modules/admin-users/errors.ts +84 -0
- package/src/modules/admin-users/index.ts +91 -0
- package/src/modules/admin-users/repository.ts +161 -0
- package/src/modules/admin-users/schemas.ts +168 -0
- package/src/modules/admin-users/seed-super-admin.ts +102 -0
- package/src/modules/admin-users/service.ts +166 -0
- package/src/modules/auth/components/sign-in-form.module.css +62 -0
- package/src/modules/auth/components/sign-in-form.tsx +132 -0
- package/src/modules/auth/index.ts +31 -0
- package/src/modules/auth/jwt-session-provider.ts +301 -0
- package/src/modules/auth/password.ts +94 -0
- package/src/modules/auth/phc.ts +121 -0
- package/src/modules/auth/refresh-tokens-repository.ts +74 -0
- package/src/modules/auth/resolve-actor.ts +42 -0
- package/src/services/admin-services-context.tsx +52 -0
- package/src/services/admin-services-types.ts +177 -0
- package/src/store.ts +32 -0
- package/src/vendor/noble-argon2/LICENSE +21 -0
- package/src/vendor/noble-argon2/README.md +87 -0
- package/src/vendor/noble-argon2/_blake.ts +58 -0
- package/src/vendor/noble-argon2/_md.ts +223 -0
- package/src/vendor/noble-argon2/_u64.ts +118 -0
- package/src/vendor/noble-argon2/argon2.ts +668 -0
- package/src/vendor/noble-argon2/blake2.ts +583 -0
- package/src/vendor/noble-argon2/utils.ts +849 -0
|
@@ -1,26 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* `@byline/admin/admin-permissions` — ability grants against roles plus
|
|
10
|
-
* the read-only inspector view.
|
|
11
|
-
*
|
|
12
|
-
* Backs the `byline_admin_permissions` table. Ability keys are
|
|
13
|
-
* registered at `initBylineCore()` time through the `AbilityRegistry`
|
|
14
|
-
* from `@byline/auth`; this module owns the per-role grant data and the
|
|
15
|
-
* inspector that surfaces it.
|
|
16
|
-
*
|
|
17
|
-
* The editor surface (`getRoleAbilities` / `setRoleAbilities`) is
|
|
18
|
-
* deliberately out of scope on this first ship — it lands with Phase B
|
|
19
|
-
* and mounts on the admin-roles role detail page.
|
|
20
|
-
*/
|
|
21
|
-
export { ADMIN_PERMISSIONS_ABILITIES, registerAdminPermissionsAbilities, } from './abilities.js';
|
|
22
|
-
export { getRoleAbilitiesCommand, listRegisteredAbilitiesCommand, setRoleAbilitiesCommand, whoHasAbilityCommand, } from './commands.js';
|
|
23
|
-
export { toAbilityDescriptor } from './dto.js';
|
|
24
|
-
export { AdminPermissionsError, AdminPermissionsErrorCodes, ERR_ADMIN_PERMISSIONS_ABILITY_UNREGISTERED, ERR_ADMIN_PERMISSIONS_ROLE_NOT_FOUND, } from './errors.js';
|
|
25
|
-
export { abilityDescriptorResponseSchema, abilityGroupResponseSchema, abilityHolderRoleSchema, abilityHolderUserSchema, getRoleAbilitiesRequestSchema, getRoleAbilitiesResponseSchema, listRegisteredAbilitiesRequestSchema, listRegisteredAbilitiesResponseSchema, setRoleAbilitiesRequestSchema, setRoleAbilitiesResponseSchema, whoHasAbilityRequestSchema, whoHasAbilityResponseSchema, } from './schemas.js';
|
|
26
|
-
export { AdminPermissionsService } from './service.js';
|
|
1
|
+
export { ADMIN_PERMISSIONS_ABILITIES, registerAdminPermissionsAbilities } from "./abilities.js";
|
|
2
|
+
export { getRoleAbilitiesCommand, listRegisteredAbilitiesCommand, setRoleAbilitiesCommand, whoHasAbilityCommand } from "./commands.js";
|
|
3
|
+
export { toAbilityDescriptor } from "./dto.js";
|
|
4
|
+
export { AdminPermissionsError, AdminPermissionsErrorCodes, ERR_ADMIN_PERMISSIONS_ABILITY_UNREGISTERED, ERR_ADMIN_PERMISSIONS_ROLE_NOT_FOUND } from "./errors.js";
|
|
5
|
+
export { abilityDescriptorResponseSchema, abilityGroupResponseSchema, abilityHolderRoleSchema, abilityHolderUserSchema, getRoleAbilitiesRequestSchema, getRoleAbilitiesResponseSchema, listRegisteredAbilitiesRequestSchema, listRegisteredAbilitiesResponseSchema, setRoleAbilitiesRequestSchema, setRoleAbilitiesResponseSchema, whoHasAbilityRequestSchema, whoHasAbilityResponseSchema } from "./schemas.js";
|
|
6
|
+
export { AdminPermissionsService } from "./service.js";
|
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* This Source Code is subject to the terms of the Mozilla Public
|
|
3
|
-
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
-
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) Infonomic Company Limited
|
|
7
|
-
*/
|
|
8
|
-
export {};
|
|
1
|
+
export { };
|
|
@@ -1,98 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
-
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) Infonomic Company Limited
|
|
7
|
-
*/
|
|
8
|
-
import { uuidSchema } from '@byline/core/validation';
|
|
9
|
-
import { z } from 'zod';
|
|
10
|
-
/**
|
|
11
|
-
* Zod request/response schemas for the admin-permissions inspector.
|
|
12
|
-
*
|
|
13
|
-
* The inspector ships two endpoints:
|
|
14
|
-
*
|
|
15
|
-
* - `listRegisteredAbilities` — flat list + grouped buckets straight
|
|
16
|
-
* out of the `AbilityRegistry`. No DB read.
|
|
17
|
-
* - `whoHasAbility` — for a given ability key, the list of roles that
|
|
18
|
-
* grant it and the distinct list of admin users transitively
|
|
19
|
-
* holding it. Two DB joins.
|
|
20
|
-
*
|
|
21
|
-
* Phase B will add `getRoleAbilities` / `setRoleAbilities` for the
|
|
22
|
-
* per-role editor on the admin-roles detail page; both are deliberately
|
|
23
|
-
* out of scope here.
|
|
24
|
-
*/
|
|
1
|
+
import { uuidSchema } from "@byline/core/validation";
|
|
2
|
+
import { z } from "zod";
|
|
25
3
|
const abilityKeySchema = z.string().min(1).max(128);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
export const listRegisteredAbilitiesRequestSchema = z.object({}).optional();
|
|
30
|
-
export const whoHasAbilityRequestSchema = z.object({
|
|
31
|
-
ability: abilityKeySchema,
|
|
4
|
+
const listRegisteredAbilitiesRequestSchema = z.object({}).optional();
|
|
5
|
+
const whoHasAbilityRequestSchema = z.object({
|
|
6
|
+
ability: abilityKeySchema
|
|
32
7
|
});
|
|
33
|
-
|
|
34
|
-
id: uuidSchema
|
|
8
|
+
const getRoleAbilitiesRequestSchema = z.object({
|
|
9
|
+
id: uuidSchema
|
|
35
10
|
});
|
|
36
|
-
|
|
11
|
+
const setRoleAbilitiesRequestSchema = z.object({
|
|
37
12
|
id: uuidSchema,
|
|
38
|
-
abilities: z.array(abilityKeySchema)
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
13
|
+
abilities: z.array(abilityKeySchema)
|
|
14
|
+
});
|
|
15
|
+
const abilitySourceSchema = z["enum"]([
|
|
16
|
+
'collection',
|
|
17
|
+
'plugin',
|
|
18
|
+
'core',
|
|
19
|
+
'admin'
|
|
20
|
+
]).nullable();
|
|
21
|
+
const abilityDescriptorResponseSchema = z.object({
|
|
45
22
|
key: z.string(),
|
|
46
23
|
label: z.string(),
|
|
47
24
|
description: z.string().nullable(),
|
|
48
25
|
group: z.string(),
|
|
49
|
-
source: abilitySourceSchema
|
|
26
|
+
source: abilitySourceSchema
|
|
50
27
|
});
|
|
51
|
-
|
|
28
|
+
const abilityGroupResponseSchema = z.object({
|
|
52
29
|
group: z.string(),
|
|
53
|
-
abilities: z.array(abilityDescriptorResponseSchema)
|
|
30
|
+
abilities: z.array(abilityDescriptorResponseSchema)
|
|
54
31
|
});
|
|
55
|
-
|
|
56
|
-
* Inspector list payload. Returns both the flat list and the grouped
|
|
57
|
-
* buckets so the UI can render either shape without re-bucketing.
|
|
58
|
-
*/
|
|
59
|
-
export const listRegisteredAbilitiesResponseSchema = z.object({
|
|
32
|
+
const listRegisteredAbilitiesResponseSchema = z.object({
|
|
60
33
|
abilities: z.array(abilityDescriptorResponseSchema),
|
|
61
34
|
groups: z.array(abilityGroupResponseSchema),
|
|
62
|
-
total: z.number().int().min(0)
|
|
35
|
+
total: z.number().int().min(0)
|
|
63
36
|
});
|
|
64
|
-
|
|
65
|
-
* Who-has-ability matrix entry. Roles and users are surfaced in the
|
|
66
|
-
* same response so the inline-expand row in the inspector renders in
|
|
67
|
-
* one round-trip.
|
|
68
|
-
*/
|
|
69
|
-
export const abilityHolderRoleSchema = z.object({
|
|
37
|
+
const abilityHolderRoleSchema = z.object({
|
|
70
38
|
id: z.string(),
|
|
71
39
|
name: z.string(),
|
|
72
|
-
machine_name: z.string()
|
|
40
|
+
machine_name: z.string()
|
|
73
41
|
});
|
|
74
|
-
|
|
42
|
+
const abilityHolderUserSchema = z.object({
|
|
75
43
|
id: z.string(),
|
|
76
44
|
email: z.string(),
|
|
77
45
|
given_name: z.string().nullable(),
|
|
78
|
-
family_name: z.string().nullable()
|
|
46
|
+
family_name: z.string().nullable()
|
|
79
47
|
});
|
|
80
|
-
|
|
48
|
+
const whoHasAbilityResponseSchema = z.object({
|
|
81
49
|
ability: z.string(),
|
|
82
50
|
roles: z.array(abilityHolderRoleSchema),
|
|
83
|
-
users: z.array(abilityHolderUserSchema)
|
|
51
|
+
users: z.array(abilityHolderUserSchema)
|
|
84
52
|
});
|
|
85
|
-
|
|
86
|
-
* Editor payloads. `roleId` is echoed back on both responses so the
|
|
87
|
-
* caller can match async writes against the role they were editing
|
|
88
|
-
* without holding the id separately. `abilities` is the authoritative
|
|
89
|
-
* stored set after the write.
|
|
90
|
-
*/
|
|
91
|
-
export const getRoleAbilitiesResponseSchema = z.object({
|
|
53
|
+
const getRoleAbilitiesResponseSchema = z.object({
|
|
92
54
|
roleId: z.string(),
|
|
93
|
-
abilities: z.array(z.string())
|
|
55
|
+
abilities: z.array(z.string())
|
|
94
56
|
});
|
|
95
|
-
|
|
57
|
+
const setRoleAbilitiesResponseSchema = z.object({
|
|
96
58
|
roleId: z.string(),
|
|
97
|
-
abilities: z.array(z.string())
|
|
59
|
+
abilities: z.array(z.string())
|
|
98
60
|
});
|
|
61
|
+
export { abilityDescriptorResponseSchema, abilityGroupResponseSchema, abilityHolderRoleSchema, abilityHolderUserSchema, getRoleAbilitiesRequestSchema, getRoleAbilitiesResponseSchema, listRegisteredAbilitiesRequestSchema, listRegisteredAbilitiesResponseSchema, setRoleAbilitiesRequestSchema, setRoleAbilitiesResponseSchema, whoHasAbilityRequestSchema, whoHasAbilityResponseSchema };
|
|
@@ -1,113 +1,109 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* 1. **Enumerate registered abilities.** Pure registry read — no DB
|
|
16
|
-
* access. The registry is populated at `initBylineCore()` time
|
|
17
|
-
* by collection auto-registration plus subsystem registrars
|
|
18
|
-
* (`registerAdminAbilities`).
|
|
19
|
-
* 2. **Resolve the who-has matrix.** For a given ability key, list
|
|
20
|
-
* the roles that grant it and the distinct admin users
|
|
21
|
-
* transitively holding it. Backed by two single-query joins on
|
|
22
|
-
* the permissions repository, then resolved against the roles
|
|
23
|
-
* and users repositories so the inspector can render names
|
|
24
|
-
* without further round-trips.
|
|
25
|
-
*
|
|
26
|
-
* The editor surface (`getRoleAbilities` / `setRoleAbilities`) is
|
|
27
|
-
* deliberately not on this service yet — it lands with Phase B and
|
|
28
|
-
* will live alongside these methods.
|
|
29
|
-
*/
|
|
30
|
-
export class AdminPermissionsService {
|
|
31
|
-
#store;
|
|
32
|
-
#abilities;
|
|
33
|
-
constructor(deps) {
|
|
34
|
-
this.#store = deps.store;
|
|
35
|
-
this.#abilities = deps.abilities;
|
|
1
|
+
import { toAbilityDescriptor } from "./dto.js";
|
|
2
|
+
import { ERR_ADMIN_PERMISSIONS_ABILITY_UNREGISTERED, ERR_ADMIN_PERMISSIONS_ROLE_NOT_FOUND } from "./errors.js";
|
|
3
|
+
function _check_private_redeclaration(obj, privateCollection) {
|
|
4
|
+
if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
5
|
+
}
|
|
6
|
+
function _class_apply_descriptor_get(receiver, descriptor) {
|
|
7
|
+
if (descriptor.get) return descriptor.get.call(receiver);
|
|
8
|
+
return descriptor.value;
|
|
9
|
+
}
|
|
10
|
+
function _class_apply_descriptor_set(receiver, descriptor, value) {
|
|
11
|
+
if (descriptor.set) descriptor.set.call(receiver, value);
|
|
12
|
+
else {
|
|
13
|
+
if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
|
|
14
|
+
descriptor.value = value;
|
|
36
15
|
}
|
|
16
|
+
}
|
|
17
|
+
function _class_extract_field_descriptor(receiver, privateMap, action) {
|
|
18
|
+
if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
19
|
+
return privateMap.get(receiver);
|
|
20
|
+
}
|
|
21
|
+
function _class_private_field_get(receiver, privateMap) {
|
|
22
|
+
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
|
|
23
|
+
return _class_apply_descriptor_get(receiver, descriptor);
|
|
24
|
+
}
|
|
25
|
+
function _class_private_field_init(obj, privateMap, value) {
|
|
26
|
+
_check_private_redeclaration(obj, privateMap);
|
|
27
|
+
privateMap.set(obj, value);
|
|
28
|
+
}
|
|
29
|
+
function _class_private_field_set(receiver, privateMap, value) {
|
|
30
|
+
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
|
|
31
|
+
_class_apply_descriptor_set(receiver, descriptor, value);
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
var _store = /*#__PURE__*/ new WeakMap(), _abilities = /*#__PURE__*/ new WeakMap();
|
|
35
|
+
class AdminPermissionsService {
|
|
37
36
|
listRegisteredAbilities() {
|
|
38
|
-
const flat = this
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const groups = Array.from(grouped.entries(), ([group, abilities]) => ({
|
|
45
|
-
group,
|
|
46
|
-
abilities: abilities.map(toAbilityDescriptor),
|
|
47
|
-
}));
|
|
37
|
+
const flat = _class_private_field_get(this, _abilities).list().map(toAbilityDescriptor);
|
|
38
|
+
const grouped = _class_private_field_get(this, _abilities).byGroup();
|
|
39
|
+
const groups = Array.from(grouped.entries(), ([group, abilities])=>({
|
|
40
|
+
group,
|
|
41
|
+
abilities: abilities.map(toAbilityDescriptor)
|
|
42
|
+
}));
|
|
48
43
|
return {
|
|
49
44
|
abilities: flat,
|
|
50
45
|
groups,
|
|
51
|
-
total: flat.length
|
|
46
|
+
total: flat.length
|
|
52
47
|
};
|
|
53
48
|
}
|
|
54
49
|
async getRoleAbilities(request) {
|
|
55
|
-
const role = await this
|
|
56
|
-
if (!role)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
50
|
+
const role = await _class_private_field_get(this, _store).adminRoles.getById(request.id);
|
|
51
|
+
if (!role) throw ERR_ADMIN_PERMISSIONS_ROLE_NOT_FOUND();
|
|
52
|
+
const abilities = await _class_private_field_get(this, _store).adminPermissions.listAbilities(request.id);
|
|
53
|
+
return {
|
|
54
|
+
roleId: request.id,
|
|
55
|
+
abilities
|
|
56
|
+
};
|
|
60
57
|
}
|
|
61
58
|
async setRoleAbilities(request) {
|
|
62
|
-
const role = await this
|
|
63
|
-
if (!role)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
// Wholesale-replace inside a transaction (handled by the repo).
|
|
76
|
-
await this.#store.adminPermissions.setAbilities(request.id, request.abilities);
|
|
77
|
-
// Return the freshly-stored set so the client can reset its dirty
|
|
78
|
-
// state without a second round-trip — also defends against drift if
|
|
79
|
-
// the repo dedupes or reorders.
|
|
80
|
-
const stored = await this.#store.adminPermissions.listAbilities(request.id);
|
|
81
|
-
return { roleId: request.id, abilities: stored };
|
|
59
|
+
const role = await _class_private_field_get(this, _store).adminRoles.getById(request.id);
|
|
60
|
+
if (!role) throw ERR_ADMIN_PERMISSIONS_ROLE_NOT_FOUND();
|
|
61
|
+
const unknown = request.abilities.filter((key)=>!_class_private_field_get(this, _abilities).has(key));
|
|
62
|
+
if (unknown.length > 0) throw ERR_ADMIN_PERMISSIONS_ABILITY_UNREGISTERED({
|
|
63
|
+
message: `Unregistered abilities: ${unknown.join(', ')}`
|
|
64
|
+
});
|
|
65
|
+
await _class_private_field_get(this, _store).adminPermissions.setAbilities(request.id, request.abilities);
|
|
66
|
+
const stored = await _class_private_field_get(this, _store).adminPermissions.listAbilities(request.id);
|
|
67
|
+
return {
|
|
68
|
+
roleId: request.id,
|
|
69
|
+
abilities: stored
|
|
70
|
+
};
|
|
82
71
|
}
|
|
83
72
|
async whoHasAbility(request) {
|
|
84
|
-
// Run the two inverse joins in parallel — they read the same table
|
|
85
|
-
// through different join paths but neither blocks the other.
|
|
86
73
|
const [roleIds, userIds] = await Promise.all([
|
|
87
|
-
this
|
|
88
|
-
this
|
|
74
|
+
_class_private_field_get(this, _store).adminPermissions.listRolesForAbility(request.ability),
|
|
75
|
+
_class_private_field_get(this, _store).adminPermissions.listUsersForAbility(request.ability)
|
|
89
76
|
]);
|
|
90
|
-
// Resolve role + user metadata in parallel batches. We accept the
|
|
91
|
-
// N round-trips here because admin role and user counts are small
|
|
92
|
-
// by design; if they grow we add `getByIds(ids[])` repo methods
|
|
93
|
-
// later.
|
|
94
77
|
const [roles, users] = await Promise.all([
|
|
95
|
-
Promise.all(roleIds.map((id)
|
|
96
|
-
Promise.all(userIds.map((id)
|
|
78
|
+
Promise.all(roleIds.map((id)=>_class_private_field_get(this, _store).adminRoles.getById(id))),
|
|
79
|
+
Promise.all(userIds.map((id)=>_class_private_field_get(this, _store).adminUsers.getById(id)))
|
|
97
80
|
]);
|
|
98
81
|
return {
|
|
99
82
|
ability: request.ability,
|
|
100
|
-
roles: roles
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
83
|
+
roles: roles.filter((r)=>null != r).map((r)=>({
|
|
84
|
+
id: r.id,
|
|
85
|
+
name: r.name,
|
|
86
|
+
machine_name: r.machine_name
|
|
87
|
+
})),
|
|
88
|
+
users: users.filter((u)=>null != u).map((u)=>({
|
|
89
|
+
id: u.id,
|
|
90
|
+
email: u.email,
|
|
91
|
+
given_name: u.given_name,
|
|
92
|
+
family_name: u.family_name
|
|
93
|
+
}))
|
|
111
94
|
};
|
|
112
95
|
}
|
|
96
|
+
constructor(deps){
|
|
97
|
+
_class_private_field_init(this, _store, {
|
|
98
|
+
writable: true,
|
|
99
|
+
value: void 0
|
|
100
|
+
});
|
|
101
|
+
_class_private_field_init(this, _abilities, {
|
|
102
|
+
writable: true,
|
|
103
|
+
value: void 0
|
|
104
|
+
});
|
|
105
|
+
_class_private_field_set(this, _store, deps.store);
|
|
106
|
+
_class_private_field_set(this, _abilities, deps.abilities);
|
|
107
|
+
}
|
|
113
108
|
}
|
|
109
|
+
export { AdminPermissionsService };
|
|
@@ -1,55 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
* This Source Code is subject to the terms of the Mozilla Public
|
|
3
|
-
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
-
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) Infonomic Company Limited
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Ability keys for the admin-roles module.
|
|
10
|
-
*
|
|
11
|
-
* Reorder is intentionally **rolled into `update`** — same trust level
|
|
12
|
-
* (mutating role identity), and splitting it would force a redundant
|
|
13
|
-
* `reorder` permission alongside `update` for every role-managing role.
|
|
14
|
-
*
|
|
15
|
-
* Per-role ability grants are managed by the sibling
|
|
16
|
-
* `@byline/admin/admin-permissions` module and have their own ability
|
|
17
|
-
* keys there.
|
|
18
|
-
*/
|
|
19
|
-
export const ADMIN_ROLES_ABILITIES = {
|
|
1
|
+
const ADMIN_ROLES_ABILITIES = {
|
|
20
2
|
read: 'admin.roles.read',
|
|
21
3
|
create: 'admin.roles.create',
|
|
22
4
|
update: 'admin.roles.update',
|
|
23
|
-
delete: 'admin.roles.delete'
|
|
5
|
+
delete: 'admin.roles.delete'
|
|
24
6
|
};
|
|
25
|
-
|
|
26
|
-
* Register every admin-roles ability with the framework's `AbilityRegistry`.
|
|
27
|
-
* Called from `registerAdminAbilities(registry)` at package level, which
|
|
28
|
-
* the webapp wires into `initBylineCore()`.
|
|
29
|
-
*/
|
|
30
|
-
export function registerAdminRolesAbilities(registry) {
|
|
7
|
+
function registerAdminRolesAbilities(registry) {
|
|
31
8
|
registry.register({
|
|
32
9
|
key: ADMIN_ROLES_ABILITIES.read,
|
|
33
10
|
label: 'Read admin roles',
|
|
34
11
|
group: 'admin.roles',
|
|
35
|
-
source: 'admin'
|
|
12
|
+
source: 'admin'
|
|
36
13
|
});
|
|
37
14
|
registry.register({
|
|
38
15
|
key: ADMIN_ROLES_ABILITIES.create,
|
|
39
16
|
label: 'Create admin roles',
|
|
40
17
|
group: 'admin.roles',
|
|
41
|
-
source: 'admin'
|
|
18
|
+
source: 'admin'
|
|
42
19
|
});
|
|
43
20
|
registry.register({
|
|
44
21
|
key: ADMIN_ROLES_ABILITIES.update,
|
|
45
22
|
label: 'Update or reorder admin roles',
|
|
46
23
|
group: 'admin.roles',
|
|
47
|
-
source: 'admin'
|
|
24
|
+
source: 'admin'
|
|
48
25
|
});
|
|
49
26
|
registry.register({
|
|
50
27
|
key: ADMIN_ROLES_ABILITIES.delete,
|
|
51
28
|
label: 'Delete admin roles',
|
|
52
29
|
group: 'admin.roles',
|
|
53
|
-
source: 'admin'
|
|
30
|
+
source: 'admin'
|
|
54
31
|
});
|
|
55
32
|
}
|
|
33
|
+
export { ADMIN_ROLES_ABILITIES, registerAdminRolesAbilities };
|
|
@@ -1,75 +1,109 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* Copyright (c) Infonomic Company Limited
|
|
7
|
-
*/
|
|
8
|
-
import { createCommand } from '../../lib/create-command.js';
|
|
9
|
-
import { ADMIN_USERS_ABILITIES } from '../admin-users/abilities.js';
|
|
10
|
-
import { ADMIN_ROLES_ABILITIES } from './abilities.js';
|
|
11
|
-
import { adminRoleListResponseSchema, adminRoleResponseSchema, createAdminRoleRequestSchema, deleteAdminRoleRequestSchema, getAdminRoleRequestSchema, getRolesForUserRequestSchema, listAdminRolesRequestSchema, okResponseSchema, reorderAdminRolesRequestSchema, setRolesForUserRequestSchema, updateAdminRoleRequestSchema, userRolesResponseSchema, } from './schemas.js';
|
|
12
|
-
import { AdminRolesService } from './service.js';
|
|
1
|
+
import { createCommand } from "../../lib/create-command.js";
|
|
2
|
+
import { ADMIN_USERS_ABILITIES } from "../admin-users/abilities.js";
|
|
3
|
+
import { ADMIN_ROLES_ABILITIES } from "./abilities.js";
|
|
4
|
+
import { adminRoleListResponseSchema, adminRoleResponseSchema, createAdminRoleRequestSchema, deleteAdminRoleRequestSchema, getAdminRoleRequestSchema, getRolesForUserRequestSchema, listAdminRolesRequestSchema, okResponseSchema, reorderAdminRolesRequestSchema, setRolesForUserRequestSchema, updateAdminRoleRequestSchema, userRolesResponseSchema } from "./schemas.js";
|
|
5
|
+
import { AdminRolesService } from "./service.js";
|
|
13
6
|
function serviceOf(deps) {
|
|
14
|
-
return new AdminRolesService({
|
|
7
|
+
return new AdminRolesService({
|
|
8
|
+
store: deps.store
|
|
9
|
+
});
|
|
15
10
|
}
|
|
16
|
-
|
|
11
|
+
const listAdminRolesCommand = createCommand({
|
|
17
12
|
method: 'listAdminRoles',
|
|
18
|
-
auth: {
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
auth: {
|
|
14
|
+
ability: ADMIN_ROLES_ABILITIES.read
|
|
15
|
+
},
|
|
16
|
+
schemas: {
|
|
17
|
+
input: listAdminRolesRequestSchema,
|
|
18
|
+
output: adminRoleListResponseSchema
|
|
19
|
+
},
|
|
20
|
+
handler: ({ deps })=>serviceOf(deps).listRoles()
|
|
21
21
|
});
|
|
22
|
-
|
|
22
|
+
const getAdminRoleCommand = createCommand({
|
|
23
23
|
method: 'getAdminRole',
|
|
24
|
-
auth: {
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
auth: {
|
|
25
|
+
ability: ADMIN_ROLES_ABILITIES.read
|
|
26
|
+
},
|
|
27
|
+
schemas: {
|
|
28
|
+
input: getAdminRoleRequestSchema,
|
|
29
|
+
output: adminRoleResponseSchema
|
|
30
|
+
},
|
|
31
|
+
handler: ({ input, deps })=>serviceOf(deps).getRole(input)
|
|
27
32
|
});
|
|
28
|
-
|
|
33
|
+
const createAdminRoleCommand = createCommand({
|
|
29
34
|
method: 'createAdminRole',
|
|
30
|
-
auth: {
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
auth: {
|
|
36
|
+
ability: ADMIN_ROLES_ABILITIES.create
|
|
37
|
+
},
|
|
38
|
+
schemas: {
|
|
39
|
+
input: createAdminRoleRequestSchema,
|
|
40
|
+
output: adminRoleResponseSchema
|
|
41
|
+
},
|
|
42
|
+
handler: ({ input, deps })=>serviceOf(deps).createRole(input)
|
|
33
43
|
});
|
|
34
|
-
|
|
44
|
+
const updateAdminRoleCommand = createCommand({
|
|
35
45
|
method: 'updateAdminRole',
|
|
36
|
-
auth: {
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
auth: {
|
|
47
|
+
ability: ADMIN_ROLES_ABILITIES.update
|
|
48
|
+
},
|
|
49
|
+
schemas: {
|
|
50
|
+
input: updateAdminRoleRequestSchema,
|
|
51
|
+
output: adminRoleResponseSchema
|
|
52
|
+
},
|
|
53
|
+
handler: ({ input, deps })=>serviceOf(deps).updateRole(input)
|
|
39
54
|
});
|
|
40
|
-
|
|
55
|
+
const deleteAdminRoleCommand = createCommand({
|
|
41
56
|
method: 'deleteAdminRole',
|
|
42
|
-
auth: {
|
|
43
|
-
|
|
44
|
-
handler: async ({ input, deps }) => {
|
|
45
|
-
await serviceOf(deps).deleteRole(input);
|
|
46
|
-
return { ok: true };
|
|
57
|
+
auth: {
|
|
58
|
+
ability: ADMIN_ROLES_ABILITIES["delete"]
|
|
47
59
|
},
|
|
60
|
+
schemas: {
|
|
61
|
+
input: deleteAdminRoleRequestSchema,
|
|
62
|
+
output: okResponseSchema
|
|
63
|
+
},
|
|
64
|
+
handler: async ({ input, deps })=>{
|
|
65
|
+
await serviceOf(deps).deleteRole(input);
|
|
66
|
+
return {
|
|
67
|
+
ok: true
|
|
68
|
+
};
|
|
69
|
+
}
|
|
48
70
|
});
|
|
49
|
-
|
|
71
|
+
const reorderAdminRolesCommand = createCommand({
|
|
50
72
|
method: 'reorderAdminRoles',
|
|
51
|
-
auth: {
|
|
52
|
-
|
|
53
|
-
handler: async ({ input, deps }) => {
|
|
54
|
-
await serviceOf(deps).reorderRoles(input);
|
|
55
|
-
return { ok: true };
|
|
73
|
+
auth: {
|
|
74
|
+
ability: ADMIN_ROLES_ABILITIES.update
|
|
56
75
|
},
|
|
76
|
+
schemas: {
|
|
77
|
+
input: reorderAdminRolesRequestSchema,
|
|
78
|
+
output: okResponseSchema
|
|
79
|
+
},
|
|
80
|
+
handler: async ({ input, deps })=>{
|
|
81
|
+
await serviceOf(deps).reorderRoles(input);
|
|
82
|
+
return {
|
|
83
|
+
ok: true
|
|
84
|
+
};
|
|
85
|
+
}
|
|
57
86
|
});
|
|
58
|
-
|
|
87
|
+
const getRolesForUserCommand = createCommand({
|
|
59
88
|
method: 'getRolesForUser',
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
schemas: {
|
|
64
|
-
|
|
89
|
+
auth: {
|
|
90
|
+
ability: ADMIN_USERS_ABILITIES.read
|
|
91
|
+
},
|
|
92
|
+
schemas: {
|
|
93
|
+
input: getRolesForUserRequestSchema,
|
|
94
|
+
output: userRolesResponseSchema
|
|
95
|
+
},
|
|
96
|
+
handler: ({ input, deps })=>serviceOf(deps).getRolesForUser(input)
|
|
65
97
|
});
|
|
66
|
-
|
|
98
|
+
const setRolesForUserCommand = createCommand({
|
|
67
99
|
method: 'setRolesForUser',
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
100
|
+
auth: {
|
|
101
|
+
ability: ADMIN_USERS_ABILITIES.update
|
|
102
|
+
},
|
|
103
|
+
schemas: {
|
|
104
|
+
input: setRolesForUserRequestSchema,
|
|
105
|
+
output: userRolesResponseSchema
|
|
106
|
+
},
|
|
107
|
+
handler: ({ input, deps })=>serviceOf(deps).setRolesForUser(input)
|
|
75
108
|
});
|
|
109
|
+
export { createAdminRoleCommand, deleteAdminRoleCommand, getAdminRoleCommand, getRolesForUserCommand, listAdminRolesCommand, reorderAdminRolesCommand, setRolesForUserCommand, updateAdminRoleCommand };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AdminRoleResponse } from '../index.js';
|
|
2
|
+
interface CreateAdminRoleProps {
|
|
3
|
+
onClose?: () => void;
|
|
4
|
+
onSuccess?: (role: AdminRoleResponse) => void;
|
|
5
|
+
}
|
|
6
|
+
export declare function CreateAdminRole({ onClose, onSuccess }: CreateAdminRoleProps): import("react").JSX.Element;
|
|
7
|
+
export {};
|