@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
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { revalidateLogic, useForm } from "@tanstack/react-form-start";
|
|
5
|
+
import { Alert, Button, Input, LoaderEllipsis, TextArea } from "@byline/ui/react";
|
|
6
|
+
import classnames from "classnames";
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import { useBylineAdminServices } from "../../../services/admin-services-context.js";
|
|
9
|
+
import create_module from "./create.module.js";
|
|
10
|
+
const createAdminRoleFormSchema = z.object({
|
|
11
|
+
name: z.string().min(1, 'Name is required').max(128, 'Name must not exceed 128 characters'),
|
|
12
|
+
machine_name: z.string().min(1, 'Machine name is required').max(128, 'Machine name must not exceed 128 characters').regex(/^[a-z0-9][a-z0-9_-]*$/, {
|
|
13
|
+
message: 'Lowercase letters, numbers, hyphens, and underscores only'
|
|
14
|
+
}),
|
|
15
|
+
description: z.string().max(2000, "Description must not exceed 2000 characters")
|
|
16
|
+
});
|
|
17
|
+
const initialValues = {
|
|
18
|
+
name: '',
|
|
19
|
+
machine_name: '',
|
|
20
|
+
description: ''
|
|
21
|
+
};
|
|
22
|
+
function normaliseText(value) {
|
|
23
|
+
return value.trim().length > 0 ? value : null;
|
|
24
|
+
}
|
|
25
|
+
function CreateAdminRole({ onClose, onSuccess }) {
|
|
26
|
+
const { createAdminRole } = useBylineAdminServices();
|
|
27
|
+
const [formError, setFormError] = useState(null);
|
|
28
|
+
const form = useForm({
|
|
29
|
+
defaultValues: initialValues,
|
|
30
|
+
validationLogic: revalidateLogic({
|
|
31
|
+
mode: 'blur',
|
|
32
|
+
modeAfterSubmission: 'change'
|
|
33
|
+
}),
|
|
34
|
+
validators: {
|
|
35
|
+
onDynamic: createAdminRoleFormSchema
|
|
36
|
+
},
|
|
37
|
+
onSubmit: async ({ value })=>{
|
|
38
|
+
setFormError(null);
|
|
39
|
+
try {
|
|
40
|
+
const created = await createAdminRole({
|
|
41
|
+
data: {
|
|
42
|
+
name: value.name.trim(),
|
|
43
|
+
machine_name: value.machine_name.trim(),
|
|
44
|
+
description: normaliseText(value.description)
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
form.reset(initialValues);
|
|
48
|
+
onSuccess?.(created);
|
|
49
|
+
} catch (err) {
|
|
50
|
+
const code = getErrorCode(err);
|
|
51
|
+
if ('admin.roles.machineNameInUse' === code) return void form.setFieldMeta('machine_name', (meta)=>({
|
|
52
|
+
...meta,
|
|
53
|
+
errorMap: {
|
|
54
|
+
...meta.errorMap,
|
|
55
|
+
onServer: 'This machine name is already in use.'
|
|
56
|
+
},
|
|
57
|
+
errors: [
|
|
58
|
+
'This machine name is already in use.'
|
|
59
|
+
]
|
|
60
|
+
}));
|
|
61
|
+
setFormError('Could not create this admin role. Please try again.');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return /*#__PURE__*/ jsx("div", {
|
|
66
|
+
className: classnames('byline-role-create-wrap', create_module.wrap),
|
|
67
|
+
children: /*#__PURE__*/ jsxs("form", {
|
|
68
|
+
noValidate: true,
|
|
69
|
+
onSubmit: (event)=>{
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
event.stopPropagation();
|
|
72
|
+
form.handleSubmit();
|
|
73
|
+
},
|
|
74
|
+
className: classnames('byline-role-create-form', create_module.form),
|
|
75
|
+
children: [
|
|
76
|
+
formError ? /*#__PURE__*/ jsx(Alert, {
|
|
77
|
+
intent: "danger",
|
|
78
|
+
children: formError
|
|
79
|
+
}) : null,
|
|
80
|
+
/*#__PURE__*/ jsx(form.Field, {
|
|
81
|
+
name: "name",
|
|
82
|
+
children: (field)=>/*#__PURE__*/ jsx(Input, {
|
|
83
|
+
label: "Name",
|
|
84
|
+
id: "new-role-name",
|
|
85
|
+
name: field.name,
|
|
86
|
+
value: field.state.value,
|
|
87
|
+
onBlur: field.handleBlur,
|
|
88
|
+
onChange: (e)=>field.handleChange(e.currentTarget.value),
|
|
89
|
+
error: field.state.meta.errors.length > 0,
|
|
90
|
+
errorText: firstError(field.state.meta.errors),
|
|
91
|
+
helpText: "Human-readable label, e.g. 'Editor'.",
|
|
92
|
+
required: true
|
|
93
|
+
})
|
|
94
|
+
}),
|
|
95
|
+
/*#__PURE__*/ jsx(form.Field, {
|
|
96
|
+
name: "machine_name",
|
|
97
|
+
children: (field)=>/*#__PURE__*/ jsx(Input, {
|
|
98
|
+
label: "Machine name",
|
|
99
|
+
id: "new-role-machine-name",
|
|
100
|
+
name: field.name,
|
|
101
|
+
value: field.state.value,
|
|
102
|
+
onBlur: field.handleBlur,
|
|
103
|
+
onChange: (e)=>field.handleChange(e.currentTarget.value),
|
|
104
|
+
error: field.state.meta.errors.length > 0,
|
|
105
|
+
errorText: firstError(field.state.meta.errors),
|
|
106
|
+
helpText: "Stable code-side handle, e.g. 'editor'. Cannot be changed later.",
|
|
107
|
+
required: true
|
|
108
|
+
})
|
|
109
|
+
}),
|
|
110
|
+
/*#__PURE__*/ jsx(form.Field, {
|
|
111
|
+
name: "description",
|
|
112
|
+
children: (field)=>/*#__PURE__*/ jsx(TextArea, {
|
|
113
|
+
label: "Description",
|
|
114
|
+
id: "new-role-description",
|
|
115
|
+
name: field.name,
|
|
116
|
+
value: field.state.value,
|
|
117
|
+
onBlur: field.handleBlur,
|
|
118
|
+
onChange: (e)=>field.handleChange(e.currentTarget.value),
|
|
119
|
+
error: field.state.meta.errors.length > 0,
|
|
120
|
+
errorText: firstError(field.state.meta.errors),
|
|
121
|
+
rows: 3
|
|
122
|
+
})
|
|
123
|
+
}),
|
|
124
|
+
/*#__PURE__*/ jsxs("div", {
|
|
125
|
+
className: classnames('byline-role-create-actions', create_module.actions),
|
|
126
|
+
children: [
|
|
127
|
+
/*#__PURE__*/ jsx(Button, {
|
|
128
|
+
type: "button",
|
|
129
|
+
intent: "secondary",
|
|
130
|
+
size: "sm",
|
|
131
|
+
onClick: onClose,
|
|
132
|
+
className: classnames('byline-role-create-action', create_module.action),
|
|
133
|
+
children: "Cancel"
|
|
134
|
+
}),
|
|
135
|
+
/*#__PURE__*/ jsx(form.Subscribe, {
|
|
136
|
+
selector: (state)=>({
|
|
137
|
+
canSubmit: state.canSubmit,
|
|
138
|
+
isSubmitting: state.isSubmitting
|
|
139
|
+
}),
|
|
140
|
+
children: ({ canSubmit, isSubmitting })=>/*#__PURE__*/ jsx(Button, {
|
|
141
|
+
size: "sm",
|
|
142
|
+
intent: "primary",
|
|
143
|
+
type: "submit",
|
|
144
|
+
disabled: !canSubmit || isSubmitting,
|
|
145
|
+
className: classnames('byline-role-create-action', create_module.action),
|
|
146
|
+
children: true === isSubmitting ? /*#__PURE__*/ jsx(LoaderEllipsis, {
|
|
147
|
+
size: 42
|
|
148
|
+
}) : 'Save'
|
|
149
|
+
})
|
|
150
|
+
})
|
|
151
|
+
]
|
|
152
|
+
})
|
|
153
|
+
]
|
|
154
|
+
})
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function firstError(errors) {
|
|
158
|
+
for (const err of errors){
|
|
159
|
+
if ('string' == typeof err) return err;
|
|
160
|
+
if (err && 'object' == typeof err && 'message' in err) {
|
|
161
|
+
const msg = err.message;
|
|
162
|
+
if ('string' == typeof msg) return msg;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function getErrorCode(err) {
|
|
167
|
+
if (err && 'object' == typeof err) {
|
|
168
|
+
const e = err;
|
|
169
|
+
if ('string' == typeof e.code) return e.code;
|
|
170
|
+
if (e.cause && 'object' == typeof e.cause && 'code' in e.cause) {
|
|
171
|
+
const cause = e.cause;
|
|
172
|
+
if ('string' == typeof cause.code) return cause.code;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
export { CreateAdminRole };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
:is(.wrap-TO0OTc, .byline-role-create-wrap) {
|
|
2
|
+
gap: var(--spacing-8);
|
|
3
|
+
padding: var(--spacing-4);
|
|
4
|
+
margin-top: var(--spacing-4);
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
display: flex;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
:is(.form-wmLTJg, .byline-role-create-form) {
|
|
10
|
+
gap: var(--spacing-16);
|
|
11
|
+
padding-top: var(--spacing-8);
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
display: flex;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
:is(.actions-mZfReT, .byline-role-create-actions) {
|
|
17
|
+
justify-content: flex-end;
|
|
18
|
+
align-items: center;
|
|
19
|
+
gap: var(--spacing-8);
|
|
20
|
+
margin-top: var(--spacing-16);
|
|
21
|
+
display: flex;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
:is(.action-yPyZD3, .byline-role-create-action) {
|
|
25
|
+
min-width: 4rem;
|
|
26
|
+
}
|
|
27
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ListRegisteredAbilitiesResponse, SetRoleAbilitiesResponse } from '../../admin-permissions/index.js';
|
|
2
|
+
import type { AdminRoleResponse } from '../index.js';
|
|
3
|
+
interface RolePermissionsProps {
|
|
4
|
+
role: AdminRoleResponse;
|
|
5
|
+
registered: ListRegisteredAbilitiesResponse;
|
|
6
|
+
initialAbilities: string[];
|
|
7
|
+
onSaved?: (response: SetRoleAbilitiesResponse) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare function RolePermissions({ role, registered, initialAbilities, onSaved, }: RolePermissionsProps): import("react").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo, useState } from "react";
|
|
4
|
+
import { Alert, Button, Checkbox, LoaderEllipsis } from "@byline/ui/react";
|
|
5
|
+
import classnames from "classnames";
|
|
6
|
+
import { useBylineAdminServices } from "../../../services/admin-services-context.js";
|
|
7
|
+
import permissions_module from "./permissions.module.js";
|
|
8
|
+
function setsEqual(a, b) {
|
|
9
|
+
if (a.size !== b.size) return false;
|
|
10
|
+
for (const item of a)if (!b.has(item)) return false;
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
function GroupSection({ group, selected, mode, saving, onToggle, onSelectAll, onClearAll }) {
|
|
14
|
+
const groupKeys = useMemo(()=>group.abilities.map((a)=>a.key), [
|
|
15
|
+
group.abilities
|
|
16
|
+
]);
|
|
17
|
+
const selectedInGroup = groupKeys.filter((key)=>selected.has(key)).length;
|
|
18
|
+
const isEdit = 'edit' === mode;
|
|
19
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
20
|
+
className: classnames('byline-role-permissions-group', permissions_module.group),
|
|
21
|
+
children: [
|
|
22
|
+
/*#__PURE__*/ jsxs("div", {
|
|
23
|
+
className: classnames('byline-role-permissions-group-head', permissions_module["group-head"]),
|
|
24
|
+
children: [
|
|
25
|
+
/*#__PURE__*/ jsxs("div", {
|
|
26
|
+
children: [
|
|
27
|
+
/*#__PURE__*/ jsx("span", {
|
|
28
|
+
className: classnames('byline-role-permissions-group-name', permissions_module["group-name"]),
|
|
29
|
+
children: group.group
|
|
30
|
+
}),
|
|
31
|
+
/*#__PURE__*/ jsxs("span", {
|
|
32
|
+
className: classnames('muted', 'byline-role-permissions-group-count', permissions_module["group-count"]),
|
|
33
|
+
children: [
|
|
34
|
+
selectedInGroup,
|
|
35
|
+
" of ",
|
|
36
|
+
group.abilities.length,
|
|
37
|
+
" ",
|
|
38
|
+
isEdit ? 'selected' : 'granted'
|
|
39
|
+
]
|
|
40
|
+
})
|
|
41
|
+
]
|
|
42
|
+
}),
|
|
43
|
+
isEdit ? /*#__PURE__*/ jsxs("div", {
|
|
44
|
+
className: classnames('byline-role-permissions-group-buttons', permissions_module["group-buttons"]),
|
|
45
|
+
children: [
|
|
46
|
+
/*#__PURE__*/ jsx(Button, {
|
|
47
|
+
size: "xs",
|
|
48
|
+
intent: "secondary",
|
|
49
|
+
type: "button",
|
|
50
|
+
disabled: saving || selectedInGroup === group.abilities.length,
|
|
51
|
+
onClick: ()=>onSelectAll(groupKeys),
|
|
52
|
+
children: "Select all"
|
|
53
|
+
}),
|
|
54
|
+
/*#__PURE__*/ jsx(Button, {
|
|
55
|
+
size: "xs",
|
|
56
|
+
intent: "secondary",
|
|
57
|
+
type: "button",
|
|
58
|
+
disabled: saving || 0 === selectedInGroup,
|
|
59
|
+
onClick: ()=>onClearAll(groupKeys),
|
|
60
|
+
children: "Clear"
|
|
61
|
+
})
|
|
62
|
+
]
|
|
63
|
+
}) : null
|
|
64
|
+
]
|
|
65
|
+
}),
|
|
66
|
+
/*#__PURE__*/ jsx("div", {
|
|
67
|
+
className: classnames('byline-role-permissions-grid', permissions_module.grid),
|
|
68
|
+
children: group.abilities.map((ability)=>/*#__PURE__*/ jsxs("div", {
|
|
69
|
+
className: classnames('byline-role-permissions-row', permissions_module.row),
|
|
70
|
+
children: [
|
|
71
|
+
/*#__PURE__*/ jsx(Checkbox, {
|
|
72
|
+
id: `ability-${ability.key}`,
|
|
73
|
+
name: `ability-${ability.key}`,
|
|
74
|
+
checked: selected.has(ability.key),
|
|
75
|
+
disabled: !isEdit || saving,
|
|
76
|
+
onCheckedChange: (checked)=>onToggle(ability.key, true === checked),
|
|
77
|
+
containerClasses: classnames('byline-role-permissions-checkbox-auto', permissions_module["checkbox-auto"]),
|
|
78
|
+
componentClasses: classnames('byline-role-permissions-checkbox-auto', permissions_module["checkbox-auto"])
|
|
79
|
+
}),
|
|
80
|
+
/*#__PURE__*/ jsxs("label", {
|
|
81
|
+
htmlFor: `ability-${ability.key}`,
|
|
82
|
+
className: classnames('byline-role-permissions-label', permissions_module.label, isEdit && [
|
|
83
|
+
'byline-role-permissions-label-edit',
|
|
84
|
+
permissions_module["label-edit"]
|
|
85
|
+
]),
|
|
86
|
+
children: [
|
|
87
|
+
/*#__PURE__*/ jsxs("div", {
|
|
88
|
+
className: classnames('byline-role-permissions-label-head', permissions_module["label-head"]),
|
|
89
|
+
children: [
|
|
90
|
+
/*#__PURE__*/ jsx("span", {
|
|
91
|
+
className: classnames('byline-role-permissions-label-name', permissions_module["label-name"]),
|
|
92
|
+
children: ability.label
|
|
93
|
+
}),
|
|
94
|
+
/*#__PURE__*/ jsx("code", {
|
|
95
|
+
className: classnames('byline-role-permissions-key', permissions_module.key),
|
|
96
|
+
children: ability.key
|
|
97
|
+
})
|
|
98
|
+
]
|
|
99
|
+
}),
|
|
100
|
+
ability.description ? /*#__PURE__*/ jsx("p", {
|
|
101
|
+
className: classnames('muted', "byline-role-permissions-description", permissions_module.description),
|
|
102
|
+
children: ability.description
|
|
103
|
+
}) : null
|
|
104
|
+
]
|
|
105
|
+
})
|
|
106
|
+
]
|
|
107
|
+
}, ability.key))
|
|
108
|
+
})
|
|
109
|
+
]
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function RolePermissions({ role, registered, initialAbilities, onSaved }) {
|
|
113
|
+
const { setRoleAbilities } = useBylineAdminServices();
|
|
114
|
+
const [mode, setMode] = useState('view');
|
|
115
|
+
const [initialSet, setInitialSet] = useState(()=>new Set(initialAbilities));
|
|
116
|
+
const [selected, setSelected] = useState(()=>new Set(initialAbilities));
|
|
117
|
+
const [saving, setSaving] = useState(false);
|
|
118
|
+
const [error, setError] = useState(null);
|
|
119
|
+
const isDirty = !setsEqual(selected, initialSet);
|
|
120
|
+
const totalSelected = selected.size;
|
|
121
|
+
function handleToggle(key, checked) {
|
|
122
|
+
if ('edit' !== mode) return;
|
|
123
|
+
setSelected((current)=>{
|
|
124
|
+
const next = new Set(current);
|
|
125
|
+
if (checked) next.add(key);
|
|
126
|
+
else next.delete(key);
|
|
127
|
+
return next;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
function handleSelectAll(groupKeys) {
|
|
131
|
+
setSelected((current)=>{
|
|
132
|
+
const next = new Set(current);
|
|
133
|
+
for (const key of groupKeys)next.add(key);
|
|
134
|
+
return next;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
function handleClearAll(groupKeys) {
|
|
138
|
+
setSelected((current)=>{
|
|
139
|
+
const next = new Set(current);
|
|
140
|
+
for (const key of groupKeys)next.delete(key);
|
|
141
|
+
return next;
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
function handleCancel() {
|
|
145
|
+
setSelected(new Set(initialSet));
|
|
146
|
+
setError(null);
|
|
147
|
+
setMode('view');
|
|
148
|
+
}
|
|
149
|
+
function handleEnterEdit() {
|
|
150
|
+
setError(null);
|
|
151
|
+
setMode('edit');
|
|
152
|
+
}
|
|
153
|
+
function handleEnterView() {
|
|
154
|
+
if (isDirty) return;
|
|
155
|
+
setError(null);
|
|
156
|
+
setMode('view');
|
|
157
|
+
}
|
|
158
|
+
async function handleSave() {
|
|
159
|
+
if (saving) return;
|
|
160
|
+
setSaving(true);
|
|
161
|
+
setError(null);
|
|
162
|
+
try {
|
|
163
|
+
const response = await setRoleAbilities({
|
|
164
|
+
data: {
|
|
165
|
+
id: role.id,
|
|
166
|
+
abilities: Array.from(selected)
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
const storedSet = new Set(response.abilities);
|
|
170
|
+
setInitialSet(storedSet);
|
|
171
|
+
setSelected(new Set(storedSet));
|
|
172
|
+
onSaved?.(response);
|
|
173
|
+
} catch (err) {
|
|
174
|
+
const code = getErrorCode(err);
|
|
175
|
+
if ('admin.permissions.roleNotFound' === code) setError('This role no longer exists.');
|
|
176
|
+
else 'admin.permissions.abilityUnregistered' === code ? setError('One or more selected abilities are no longer registered. Reload the page and try again.') : setError('Could not save permissions. Please try again.');
|
|
177
|
+
} finally{
|
|
178
|
+
setSaving(false);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const isEdit = 'edit' === mode;
|
|
182
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
183
|
+
className: classnames('byline-role-permissions-wrap', permissions_module.wrap),
|
|
184
|
+
children: [
|
|
185
|
+
/*#__PURE__*/ jsxs("div", {
|
|
186
|
+
className: classnames('byline-role-permissions-toolbar', permissions_module.toolbar),
|
|
187
|
+
children: [
|
|
188
|
+
/*#__PURE__*/ jsx(ModeToggle, {
|
|
189
|
+
mode: mode,
|
|
190
|
+
dirty: isDirty,
|
|
191
|
+
saving: saving,
|
|
192
|
+
onView: handleEnterView,
|
|
193
|
+
onEdit: handleEnterEdit
|
|
194
|
+
}),
|
|
195
|
+
/*#__PURE__*/ jsxs("p", {
|
|
196
|
+
className: classnames('muted', 'byline-role-permissions-counter', permissions_module.counter),
|
|
197
|
+
children: [
|
|
198
|
+
/*#__PURE__*/ jsx("span", {
|
|
199
|
+
className: classnames('byline-role-permissions-counter-num', permissions_module["counter-num"]),
|
|
200
|
+
children: totalSelected
|
|
201
|
+
}),
|
|
202
|
+
' ',
|
|
203
|
+
"of",
|
|
204
|
+
' ',
|
|
205
|
+
/*#__PURE__*/ jsx("span", {
|
|
206
|
+
className: classnames('byline-role-permissions-counter-num', permissions_module["counter-num"]),
|
|
207
|
+
children: registered.total
|
|
208
|
+
}),
|
|
209
|
+
' ',
|
|
210
|
+
isEdit ? 'selected' : 'granted',
|
|
211
|
+
" for ",
|
|
212
|
+
role.name
|
|
213
|
+
]
|
|
214
|
+
}),
|
|
215
|
+
isEdit && isDirty ? /*#__PURE__*/ jsxs("div", {
|
|
216
|
+
className: classnames('byline-role-permissions-actions', permissions_module.actions),
|
|
217
|
+
children: [
|
|
218
|
+
/*#__PURE__*/ jsx(Button, {
|
|
219
|
+
type: "button",
|
|
220
|
+
intent: "secondary",
|
|
221
|
+
size: "xs",
|
|
222
|
+
onClick: handleCancel,
|
|
223
|
+
disabled: saving,
|
|
224
|
+
className: classnames('byline-role-permissions-action', permissions_module.action),
|
|
225
|
+
children: "Cancel"
|
|
226
|
+
}),
|
|
227
|
+
/*#__PURE__*/ jsx(Button, {
|
|
228
|
+
type: "button",
|
|
229
|
+
intent: "primary",
|
|
230
|
+
size: "xs",
|
|
231
|
+
onClick: ()=>void handleSave(),
|
|
232
|
+
disabled: saving,
|
|
233
|
+
className: classnames('byline-role-permissions-action', permissions_module.action),
|
|
234
|
+
children: saving ? /*#__PURE__*/ jsx(LoaderEllipsis, {
|
|
235
|
+
size: 30
|
|
236
|
+
}) : 'Save'
|
|
237
|
+
})
|
|
238
|
+
]
|
|
239
|
+
}) : null
|
|
240
|
+
]
|
|
241
|
+
}),
|
|
242
|
+
error ? /*#__PURE__*/ jsx(Alert, {
|
|
243
|
+
intent: "danger",
|
|
244
|
+
children: error
|
|
245
|
+
}) : null,
|
|
246
|
+
/*#__PURE__*/ jsx("div", {
|
|
247
|
+
className: classnames('byline-role-permissions-groups', permissions_module.groups),
|
|
248
|
+
children: registered.groups.map((group)=>/*#__PURE__*/ jsx(GroupSection, {
|
|
249
|
+
group: group,
|
|
250
|
+
selected: selected,
|
|
251
|
+
mode: mode,
|
|
252
|
+
saving: saving,
|
|
253
|
+
onToggle: handleToggle,
|
|
254
|
+
onSelectAll: handleSelectAll,
|
|
255
|
+
onClearAll: handleClearAll
|
|
256
|
+
}, group.group))
|
|
257
|
+
})
|
|
258
|
+
]
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
function ModeToggle({ mode, dirty, saving, onView, onEdit }) {
|
|
262
|
+
const isView = 'view' === mode;
|
|
263
|
+
const isEdit = 'edit' === mode;
|
|
264
|
+
const viewDisabled = dirty || saving;
|
|
265
|
+
const editDisabled = saving;
|
|
266
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
267
|
+
role: "group",
|
|
268
|
+
"aria-label": "Permissions mode",
|
|
269
|
+
className: classnames('byline-role-permissions-mode-toggle', permissions_module["mode-toggle"]),
|
|
270
|
+
children: [
|
|
271
|
+
/*#__PURE__*/ jsx("button", {
|
|
272
|
+
type: "button",
|
|
273
|
+
onClick: onView,
|
|
274
|
+
disabled: viewDisabled,
|
|
275
|
+
className: classnames('byline-role-permissions-mode-button', permissions_module["mode-button"], isView && [
|
|
276
|
+
'byline-role-permissions-mode-button-active',
|
|
277
|
+
permissions_module["mode-button-active"]
|
|
278
|
+
], viewDisabled && !isView && [
|
|
279
|
+
'byline-role-permissions-mode-button-disabled',
|
|
280
|
+
permissions_module["mode-button-disabled"]
|
|
281
|
+
]),
|
|
282
|
+
children: "View"
|
|
283
|
+
}),
|
|
284
|
+
/*#__PURE__*/ jsx("button", {
|
|
285
|
+
type: "button",
|
|
286
|
+
onClick: onEdit,
|
|
287
|
+
disabled: editDisabled,
|
|
288
|
+
className: classnames('byline-role-permissions-mode-button', 'byline-role-permissions-mode-button-divider', permissions_module["mode-button"], permissions_module["mode-button-divider"], isEdit && [
|
|
289
|
+
'byline-role-permissions-mode-button-active',
|
|
290
|
+
permissions_module["mode-button-active"]
|
|
291
|
+
], editDisabled && !isEdit && [
|
|
292
|
+
'byline-role-permissions-mode-button-disabled',
|
|
293
|
+
permissions_module["mode-button-disabled"]
|
|
294
|
+
]),
|
|
295
|
+
children: "Edit"
|
|
296
|
+
})
|
|
297
|
+
]
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
function getErrorCode(err) {
|
|
301
|
+
return 'string' == typeof err?.code ? err.code : null;
|
|
302
|
+
}
|
|
303
|
+
export { RolePermissions };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import "./permissions_module.css";
|
|
2
|
+
const permissions_module = {
|
|
3
|
+
wrap: "wrap-oHhxZn",
|
|
4
|
+
toolbar: "toolbar-xiFHRx",
|
|
5
|
+
counter: "counter-pkbHZT",
|
|
6
|
+
"counter-num": "counter-num-zDSQWA",
|
|
7
|
+
counterNum: "counter-num-zDSQWA",
|
|
8
|
+
actions: "actions-TSS9AS",
|
|
9
|
+
action: "action-jzyool",
|
|
10
|
+
"checkbox-auto": "checkbox-auto-TFunEY",
|
|
11
|
+
checkboxAuto: "checkbox-auto-TFunEY",
|
|
12
|
+
groups: "groups-agis2F",
|
|
13
|
+
group: "group-Xf1YG0",
|
|
14
|
+
"group-head": "group-head-IUhwe9",
|
|
15
|
+
groupHead: "group-head-IUhwe9",
|
|
16
|
+
"group-name": "group-name-jAKMI7",
|
|
17
|
+
groupName: "group-name-jAKMI7",
|
|
18
|
+
"group-count": "group-count-BQDjxo",
|
|
19
|
+
groupCount: "group-count-BQDjxo",
|
|
20
|
+
"group-buttons": "group-buttons-KZVdZK",
|
|
21
|
+
groupButtons: "group-buttons-KZVdZK",
|
|
22
|
+
grid: "grid-tLxHtG",
|
|
23
|
+
row: "row-Q7NujV",
|
|
24
|
+
label: "label-wOoMvK",
|
|
25
|
+
"label-edit": "label-edit-oRTY7d",
|
|
26
|
+
labelEdit: "label-edit-oRTY7d",
|
|
27
|
+
"label-head": "label-head-nm1MZV",
|
|
28
|
+
labelHead: "label-head-nm1MZV",
|
|
29
|
+
"label-name": "label-name-c9gt0V",
|
|
30
|
+
labelName: "label-name-c9gt0V",
|
|
31
|
+
key: "key-ZIoxQA",
|
|
32
|
+
description: "description-FHyeNa",
|
|
33
|
+
"mode-toggle": "mode-toggle-rfVYTa",
|
|
34
|
+
modeToggle: "mode-toggle-rfVYTa",
|
|
35
|
+
"mode-button": "mode-button-y37cUe",
|
|
36
|
+
modeButton: "mode-button-y37cUe",
|
|
37
|
+
"mode-button-active": "mode-button-active-O9hDFq",
|
|
38
|
+
modeButtonActive: "mode-button-active-O9hDFq",
|
|
39
|
+
"mode-button-divider": "mode-button-divider-i7CEW9",
|
|
40
|
+
modeButtonDivider: "mode-button-divider-i7CEW9",
|
|
41
|
+
"mode-button-disabled": "mode-button-disabled-i9SxhV",
|
|
42
|
+
modeButtonDisabled: "mode-button-disabled-i9SxhV"
|
|
43
|
+
};
|
|
44
|
+
export default permissions_module;
|