@jini-ai/user-management 0.2.0 → 0.3.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 +43 -0
- package/dist/admin/people.rules.js +2 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +1 -0
- package/dist/core/principal-kind-policy.d.ts +30 -0
- package/dist/core/principal-kind-policy.js +28 -0
- package/dist/core/types.d.ts +7 -2
- package/dist/react/index.d.ts +4 -0
- package/dist/react/index.js +2 -0
- package/dist/react/members/Members.d.ts +28 -1
- package/dist/react/members/Members.js +14 -10
- package/dist/react/members/hooks/use-members.hooks.d.ts +43 -1
- package/dist/react/members/hooks/use-members.hooks.js +37 -9
- package/dist/react/members/rules.d.ts +31 -4
- package/dist/react/members/rules.js +17 -5
- package/dist/react/models.d.ts +3 -0
- package/dist/react/users/Users.d.ts +105 -6
- package/dist/react/users/Users.js +105 -43
- package/dist/react/users/hooks/use-reset-password-fields.hooks.d.ts +33 -1
- package/dist/react/users/hooks/use-reset-password-fields.hooks.js +16 -1
- package/dist/react/users/hooks/use-users.hooks.d.ts +120 -3
- package/dist/react/users/hooks/use-users.hooks.js +192 -23
- package/dist/react/users/rules.d.ts +115 -8
- package/dist/react/users/rules.js +109 -6
- package/dist/server/admin-crud-service.js +4 -1
- package/dist/server/authorize.d.ts +9 -6
- package/dist/server/authorize.js +11 -3
- package/dist/server/permission-migrations.d.ts +35 -15
- package/dist/server/permission-migrations.js +16 -16
- package/dist/server/seed.js +6 -1
- package/package.json +15 -10
- package/dist/react/roles/Roles.d.ts +0 -100
- package/dist/react/roles/Roles.hooks.d.ts +0 -17
- package/dist/react/roles/Roles.hooks.js +0 -40
- package/dist/react/roles/Roles.js +0 -150
- package/dist/react/roles/hooks/use-roles.hooks.d.ts +0 -80
- package/dist/react/roles/hooks/use-roles.hooks.js +0 -303
- package/dist/react/roles/rules.d.ts +0 -35
- package/dist/react/roles/rules.js +0 -31
- package/dist/react/roles/text.d.ts +0 -27
- package/dist/react/roles/text.js +0 -13
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import type { Translate } from "@jini-ai/ui/panel-kit";
|
|
2
|
-
import { type FormEvent } from "react";
|
|
3
|
-
import type { AdminPolicy, AdminPolicyPermission, AdminRole } from "../models.js";
|
|
4
|
-
import { useRoles, type RolesDependencies, type PendingPermissionRemove } from "./hooks/use-roles.hooks.js";
|
|
5
|
-
import { type RolesTabId } from "./Roles.hooks.js";
|
|
6
|
-
export interface RolesProps extends RolesDependencies {
|
|
7
|
-
onTabChange: (required: {
|
|
8
|
-
tabId: RolesTabId;
|
|
9
|
-
}) => void;
|
|
10
|
-
usersHref: string;
|
|
11
|
-
tabId?: string | null | undefined;
|
|
12
|
-
useRolesHook?: typeof useRoles | undefined;
|
|
13
|
-
}
|
|
14
|
-
export interface RoleCreateFormController {
|
|
15
|
-
name: string;
|
|
16
|
-
setName: (name: string) => void;
|
|
17
|
-
saving: boolean;
|
|
18
|
-
error: string | null;
|
|
19
|
-
submit: (e: FormEvent) => Promise<void>;
|
|
20
|
-
}
|
|
21
|
-
export interface RoleRowController {
|
|
22
|
-
editingId: string | null;
|
|
23
|
-
setEditingId: (roleId: string | null) => void;
|
|
24
|
-
draftName: string;
|
|
25
|
-
setDraftName: (name: string) => void;
|
|
26
|
-
startRename: (role: AdminRole) => void;
|
|
27
|
-
saveRename: (required: {
|
|
28
|
-
roleId: string;
|
|
29
|
-
}) => Promise<void>;
|
|
30
|
-
savingId: string | null;
|
|
31
|
-
requestDelete: (role: AdminRole | null) => void;
|
|
32
|
-
}
|
|
33
|
-
export interface RolesSectionProps {
|
|
34
|
-
roles: AdminRole[];
|
|
35
|
-
create: RoleCreateFormController;
|
|
36
|
-
row: RoleRowController;
|
|
37
|
-
t: (key: string) => string;
|
|
38
|
-
translate: Translate;
|
|
39
|
-
}
|
|
40
|
-
export declare function RolesSection({ roles, create, row, t, translate }: RolesSectionProps): import("react").JSX.Element;
|
|
41
|
-
export interface PolicyRowController {
|
|
42
|
-
editingId: string | null;
|
|
43
|
-
setEditingId: (policyId: string | null) => void;
|
|
44
|
-
draftName: string;
|
|
45
|
-
setDraftName: (name: string) => void;
|
|
46
|
-
draftDescription: string;
|
|
47
|
-
setDraftDescription: (description: string) => void;
|
|
48
|
-
startRename: (policy: AdminPolicy) => void;
|
|
49
|
-
saveRename: (required: {
|
|
50
|
-
policyId: string;
|
|
51
|
-
}) => Promise<void>;
|
|
52
|
-
savingId: string | null;
|
|
53
|
-
requestDelete: (policy: AdminPolicy | null) => void;
|
|
54
|
-
}
|
|
55
|
-
export interface PolicyPermissionController {
|
|
56
|
-
openForPolicyId: string | null;
|
|
57
|
-
permission: string;
|
|
58
|
-
setPermission: (permission: string) => void;
|
|
59
|
-
resourceType: string;
|
|
60
|
-
setResourceType: (resourceType: string) => void;
|
|
61
|
-
toggleForm: (required: {
|
|
62
|
-
policyId: string;
|
|
63
|
-
}) => void;
|
|
64
|
-
write: (required: {
|
|
65
|
-
policyId: string;
|
|
66
|
-
}) => Promise<void>;
|
|
67
|
-
rows: AdminPolicyPermission[];
|
|
68
|
-
loading: boolean;
|
|
69
|
-
removingId: string | null;
|
|
70
|
-
requestRemove: (target: PendingPermissionRemove) => void;
|
|
71
|
-
}
|
|
72
|
-
export interface PolicyRowProps {
|
|
73
|
-
policy: AdminPolicy;
|
|
74
|
-
row: PolicyRowController;
|
|
75
|
-
permission: PolicyPermissionController;
|
|
76
|
-
agentBase: string;
|
|
77
|
-
t: (key: string) => string;
|
|
78
|
-
translate: Translate;
|
|
79
|
-
}
|
|
80
|
-
export declare function PolicyRow({ policy, row, permission, agentBase, t, translate }: PolicyRowProps): import("react").JSX.Element;
|
|
81
|
-
export interface PolicyCreateFormController {
|
|
82
|
-
name: string;
|
|
83
|
-
setName: (name: string) => void;
|
|
84
|
-
description: string;
|
|
85
|
-
setDescription: (description: string) => void;
|
|
86
|
-
saving: boolean;
|
|
87
|
-
error: string | null;
|
|
88
|
-
submit: (e: FormEvent) => Promise<void>;
|
|
89
|
-
}
|
|
90
|
-
export interface PoliciesSectionProps {
|
|
91
|
-
policies: AdminPolicy[];
|
|
92
|
-
create: PolicyCreateFormController;
|
|
93
|
-
row: PolicyRowController;
|
|
94
|
-
permission: PolicyPermissionController;
|
|
95
|
-
t: (key: string) => string;
|
|
96
|
-
translate: Translate;
|
|
97
|
-
}
|
|
98
|
-
export declare function PoliciesSection({ policies, create, row, permission, t, translate }: PoliciesSectionProps): import("react").JSX.Element;
|
|
99
|
-
export declare function Roles({ tabId, useRolesHook, port, translate: injectedTranslate, queryScope, onTabChange, usersHref }: RolesProps): import("react").JSX.Element;
|
|
100
|
-
//# sourceMappingURL=Roles.d.ts.map
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { TabBarTab } from "@jini-ai/ui/tab-strip";
|
|
2
|
-
import type { Translate } from "@jini-ai/ui/panel-kit";
|
|
3
|
-
export declare function RolesIcon({ size }: {
|
|
4
|
-
size?: number;
|
|
5
|
-
}): import("react").JSX.Element;
|
|
6
|
-
export declare function PoliciesIcon({ size }: {
|
|
7
|
-
size?: number;
|
|
8
|
-
}): import("react").JSX.Element;
|
|
9
|
-
export declare const ROLES_TAB_IDS: readonly ["roles", "policies"];
|
|
10
|
-
export type RolesTabId = (typeof ROLES_TAB_IDS)[number];
|
|
11
|
-
export declare function resolveRolesTabId({ tabId }: {
|
|
12
|
-
tabId: string | null | undefined;
|
|
13
|
-
}): RolesTabId;
|
|
14
|
-
export declare function resolveRolesTabs({ translate: t }: {
|
|
15
|
-
translate: Translate;
|
|
16
|
-
}): TabBarTab[];
|
|
17
|
-
//# sourceMappingURL=Roles.hooks.d.ts.map
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { resolveActiveTabId } from "@jini-ai/ui/panel-kit";
|
|
3
|
-
const LINE_ICON = {
|
|
4
|
-
viewBox: "0 0 24 24",
|
|
5
|
-
fill: "none",
|
|
6
|
-
stroke: "currentColor",
|
|
7
|
-
strokeWidth: 1.5,
|
|
8
|
-
strokeLinecap: "round",
|
|
9
|
-
strokeLinejoin: "round",
|
|
10
|
-
"aria-hidden": true,
|
|
11
|
-
};
|
|
12
|
-
export function RolesIcon({ size = 16 }) {
|
|
13
|
-
return (_jsxs("svg", { ...LINE_ICON, width: size, height: size, children: [_jsx("circle", { cx: "12", cy: "8", r: "3.5" }), _jsx("path", { d: "M5 20c0-3.3 3.1-6 7-6s7 2.7 7 6" })] }));
|
|
14
|
-
}
|
|
15
|
-
export function PoliciesIcon({ size = 16 }) {
|
|
16
|
-
return (_jsxs("svg", { ...LINE_ICON, width: size, height: size, children: [_jsx("path", { d: "M12 3l7 2.5v6c0 4-3 7.4-7 8.5-4-1.1-7-4.5-7-8.5v-6z" }), _jsx("path", { d: "M9.5 11.5h5M9.5 14.5h3" })] }));
|
|
17
|
-
}
|
|
18
|
-
export const ROLES_TAB_IDS = ["roles", "policies"];
|
|
19
|
-
export function resolveRolesTabId({ tabId }) {
|
|
20
|
-
return resolveActiveTabId({ tabId, validIds: ROLES_TAB_IDS, defaultId: "roles" });
|
|
21
|
-
}
|
|
22
|
-
export function resolveRolesTabs({ translate: t }) {
|
|
23
|
-
return [
|
|
24
|
-
{
|
|
25
|
-
id: "roles",
|
|
26
|
-
label: t("Roles"),
|
|
27
|
-
icon: _jsx(RolesIcon, {}),
|
|
28
|
-
handle: "roles-tab-roles",
|
|
29
|
-
handleLabel: t("Switch to the Roles tab — list, create, rename and delete the roles a person can be assigned"),
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
id: "policies",
|
|
33
|
-
label: t("Policies"),
|
|
34
|
-
icon: _jsx(PoliciesIcon, {}),
|
|
35
|
-
handle: "roles-tab-policies",
|
|
36
|
-
handleLabel: t("Switch to the Policies tab — list and create policies, and add or remove the individual permissions on each one"),
|
|
37
|
-
},
|
|
38
|
-
];
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=Roles.hooks.js.map
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { rolesDescriptionParts, roleDeleteBodyParts, policyDeleteBodyParts, permissionRemoveBodyParts } from "./text.js";
|
|
3
|
-
import { Fragment } from "react";
|
|
4
|
-
import { DataTable, RowMenu, ConfirmDialog } from "@jini-ai/admin/react";
|
|
5
|
-
import { agentHandle } from "@jini-ai/agentic";
|
|
6
|
-
import { buildAgentListHandles } from "@jini-ai/ui/panel-kit";
|
|
7
|
-
import { TabBar } from "@jini-ai/ui/tab-strip";
|
|
8
|
-
import { roleMenuItems, policyMenuItems } from "./rules.js";
|
|
9
|
-
import { useRoles } from "./hooks/use-roles.hooks.js";
|
|
10
|
-
import { resolveRolesTabId, resolveRolesTabs } from "./Roles.hooks.js";
|
|
11
|
-
export function RolesSection({ roles, create, row, t, translate }) {
|
|
12
|
-
const roleMenuHandles = buildAgentListHandles({ prefix: "roles-row", ids: roles.map((role) => role.id) });
|
|
13
|
-
return (_jsxs(_Fragment, { children: [_jsx("h2", { className: "visually-hidden", children: t("Roles") }), _jsxs("form", { onSubmit: create.submit, className: "notice integrations-form form-measure", children: [create.error ? _jsx("span", { className: "save-error", children: create.error }) : null, _jsxs("label", { children: [t("Role name"), _jsx("input", { value: create.name, onChange: (e) => create.setName(e.target.value), required: true, ...agentHandle({ handle: "roles-create-name" }, { role: "field", label: t("New role's name") }) })] }), _jsx("button", { type: "submit", disabled: create.saving || !create.name, ...agentHandle({ handle: "roles-create-submit" }, { role: "button", label: t("Create this new role") }), children: create.saving ? t("Creating…") : t("Create role") })] }), _jsx(DataTable, { rows: roles, rowKey: (role) => role.id, empty: _jsx("div", { className: "card", children: _jsx("div", { className: "empty-state", children: _jsx("p", { children: t("No roles yet.") }) }) }), columns: [
|
|
14
|
-
{
|
|
15
|
-
key: "name",
|
|
16
|
-
header: t("Name"),
|
|
17
|
-
cell: (role, index) => row.editingId === role.id ? (_jsx("input", { value: row.draftName, onChange: (e) => row.setDraftName(e.target.value), ...agentHandle({ handle: `${roleMenuHandles[index]}-rename-name` }, { role: "field", label: t("This role's new name") }) })) : (role.name),
|
|
18
|
-
},
|
|
19
|
-
{ key: "type", header: t("Type"), cell: (role) => (role.isBuiltin ? t("Built-in") : t("Custom")) },
|
|
20
|
-
{
|
|
21
|
-
key: "actions",
|
|
22
|
-
header: t("More"),
|
|
23
|
-
cell: (role, index) => role.isBuiltin ? (_jsx("span", { className: "muted-cell", children: "\u2014" })) : row.editingId === role.id ? (_jsxs("span", { className: "editor-actions", children: [_jsx("button", { type: "button", disabled: row.savingId === role.id, onClick: () => row.saveRename({ roleId: role.id }), ...agentHandle({ handle: `${roleMenuHandles[index]}-save` }, { role: "button", label: t(`Save this role's new name`) }), children: row.savingId === role.id ? t("Saving…") : t("Save") }), _jsx("button", { type: "button", onClick: () => row.setEditingId(null), ...agentHandle({ handle: `${roleMenuHandles[index]}-cancel` }, { role: "button", label: t("Cancel renaming this role") }), children: t("Cancel") })] })) : (_jsx(RowMenu, { triggerLabel: `${t("Actions for role")} "${role.name}"`, agentHandle: `${roleMenuHandles[index]}-menu`, items: roleMenuItems({ role, handlers: { onRename: row.startRename, onDelete: row.requestDelete }, translate }) })),
|
|
24
|
-
},
|
|
25
|
-
] })] }));
|
|
26
|
-
}
|
|
27
|
-
function PolicyRowActions({ policy, row, permission, agentBase, t, translate }) {
|
|
28
|
-
if (policy.isBuiltin || policy.isFrozen)
|
|
29
|
-
return _jsx("span", { className: "muted-cell", children: "\u2014" });
|
|
30
|
-
if (row.editingId === policy.id) {
|
|
31
|
-
return (_jsxs("span", { className: "editor-actions", children: [_jsx("button", { type: "button", disabled: row.savingId === policy.id, onClick: () => row.saveRename({ policyId: policy.id }), ...agentHandle({ handle: `${agentBase}-save` }, { role: "button", label: t("Save this policy's new name and description") }), children: row.savingId === policy.id ? t("Saving…") : t("Save") }), _jsx("button", { type: "button", onClick: () => row.setEditingId(null), ...agentHandle({ handle: `${agentBase}-cancel` }, { role: "button", label: t("Cancel renaming this policy") }), children: t("Cancel") })] }));
|
|
32
|
-
}
|
|
33
|
-
return (_jsx(RowMenu, { triggerLabel: `${t("Actions for policy")} "${policy.name}"`, agentHandle: `${agentBase}-menu`, items: policyMenuItems({
|
|
34
|
-
policy,
|
|
35
|
-
permissionPolicyId: permission.openForPolicyId,
|
|
36
|
-
handlers: {
|
|
37
|
-
onRename: row.startRename,
|
|
38
|
-
onTogglePermissionForm: permission.toggleForm,
|
|
39
|
-
onDelete: row.requestDelete,
|
|
40
|
-
},
|
|
41
|
-
translate,
|
|
42
|
-
}) }));
|
|
43
|
-
}
|
|
44
|
-
function PolicyPermissionList({ policyId, permission, t }) {
|
|
45
|
-
if (permission.loading)
|
|
46
|
-
return _jsx("p", { className: "muted-cell", children: t("Loading permissions…") });
|
|
47
|
-
if (permission.rows.length === 0)
|
|
48
|
-
return _jsx("p", { className: "muted-cell", children: t("No permissions yet.") });
|
|
49
|
-
const removeHandles = buildAgentListHandles({
|
|
50
|
-
prefix: `policy-permission-remove-${policyId}`,
|
|
51
|
-
ids: permission.rows.map((row) => row.id),
|
|
52
|
-
});
|
|
53
|
-
return (_jsx("ul", { className: "permission-list", children: permission.rows.map((row, index) => (_jsxs("li", { children: [_jsx("code", { children: row.permission }), row.resourceType ? _jsxs("span", { className: "muted-cell", children: [" (", row.resourceType, ")"] }) : null, _jsx("button", { type: "button", disabled: permission.removingId === row.id, "aria-label": `${t("Remove permission")} ${row.permission}`, onClick: () => permission.requestRemove({ policyId, row }), ...agentHandle({ handle: removeHandles[index] }, { role: "button", label: t(`Remove the "${row.permission}" permission from this policy`) }), children: permission.removingId === row.id ? t("Removing…") : t("Remove") })] }, row.id))) }));
|
|
54
|
-
}
|
|
55
|
-
function PolicyPermissionForm({ policyId, savingId, permission, t }) {
|
|
56
|
-
const formHandleBase = buildAgentListHandles({ prefix: "policy-permission-form", ids: [policyId] })[0];
|
|
57
|
-
return (_jsx("tr", { children: _jsx("td", { colSpan: 4, children: _jsxs("div", { className: "notice integrations-form", children: [_jsx("p", { children: t("Current permissions") }), _jsx(PolicyPermissionList, { policyId: policyId, permission: permission, t: t }), _jsxs("label", { children: [t("Permission"), _jsxs("span", { className: "editor-actions permission-form-fields", children: [_jsx("input", { value: permission.permission, onChange: (e) => permission.setPermission(e.target.value), placeholder: t("e.g. content.write"), ...agentHandle({ handle: `${formHandleBase}-permission` }, { role: "field", label: t("Permission string to grant, e.g. content.write") }) }), _jsx("input", { value: permission.resourceType, onChange: (e) => permission.setResourceType(e.target.value), placeholder: t("resource type (optional)"), ...agentHandle({ handle: `${formHandleBase}-resource-type` }, { role: "field", label: t("Optional resource type this permission is scoped to") }) }), _jsx("button", { type: "button", disabled: !permission.permission || savingId === policyId, onClick: () => permission.write({ policyId }), ...agentHandle({ handle: `${formHandleBase}-add` }, { role: "button", label: t("Add this permission to the policy") }), children: savingId === policyId ? t("Saving…") : t("Add") })] })] })] }) }) }));
|
|
58
|
-
}
|
|
59
|
-
export function PolicyRow({ policy, row, permission, agentBase, t, translate }) {
|
|
60
|
-
const renaming = row.editingId === policy.id;
|
|
61
|
-
return (_jsxs(_Fragment, { children: [_jsxs("tr", { children: [_jsx("td", { children: renaming ? (_jsx("input", { value: row.draftName, onChange: (e) => row.setDraftName(e.target.value), ...agentHandle({ handle: `${agentBase}-rename-name` }, { role: "field", label: t("This policy's new name") }) })) : (policy.name) }), _jsx("td", { children: renaming ? (_jsx("input", { value: row.draftDescription, onChange: (e) => row.setDraftDescription(e.target.value), ...agentHandle({ handle: `${agentBase}-rename-description` }, { role: "field", label: t("This policy's new description") }) })) : (policy.description ?? _jsx("span", { className: "muted-cell", children: "\u2014" })) }), _jsxs("td", { children: [policy.isBuiltin ? t("Built-in") : t("Custom"), policy.isFrozen ? ` ${t("(frozen)")}` : ""] }), _jsx("td", { children: _jsx(PolicyRowActions, { policy: policy, row: row, permission: permission, agentBase: agentBase, t: t, translate: translate }) })] }), permission.openForPolicyId === policy.id ? (_jsx(PolicyPermissionForm, { policyId: policy.id, savingId: row.savingId, permission: permission, t: t })) : null] }));
|
|
62
|
-
}
|
|
63
|
-
export function PoliciesSection({ policies, create, row, permission, t, translate }) {
|
|
64
|
-
const policyMenuBases = buildAgentListHandles({ prefix: "policies-row", ids: policies.map((policy) => policy.id) });
|
|
65
|
-
return (_jsxs(_Fragment, { children: [_jsx("h2", { className: "visually-hidden", children: t("Policies") }), _jsxs("form", { onSubmit: create.submit, className: "notice integrations-form form-measure", children: [create.error ? _jsx("span", { className: "save-error", children: create.error }) : null, _jsxs("label", { children: [t("Policy name"), _jsx("input", { value: create.name, onChange: (e) => create.setName(e.target.value), required: true, ...agentHandle({ handle: "policies-create-name" }, { role: "field", label: t("New policy's name") }) })] }), _jsxs("label", { children: [t("Description (optional)"), _jsx("input", { value: create.description, onChange: (e) => create.setDescription(e.target.value), ...agentHandle({ handle: "policies-create-description" }, { role: "field", label: t("New policy's optional description") }) })] }), _jsx("button", { type: "submit", disabled: create.saving || !create.name, ...agentHandle({ handle: "policies-create-submit" }, { role: "button", label: t("Create this new policy") }), children: create.saving ? t("Creating…") : t("Create policy") })] }), policies.length === 0 ? (_jsx("div", { className: "card", children: _jsx("div", { className: "empty-state", children: _jsx("p", { children: t("No policies yet.") }) }) })) : (_jsx("div", { className: "table-scroll", children: _jsxs("table", { className: "list-table", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: t("Name") }), _jsx("th", { children: t("Description") }), _jsx("th", { children: t("Type") }), _jsx("th", { children: t("More") })] }) }), _jsx("tbody", { children: policies.map((policy, index) => (_jsx(Fragment, { children: _jsx(PolicyRow, { policy: policy, row: row, permission: permission, agentBase: policyMenuBases[index], t: t, translate: translate }) }, policy.id))) })] }) }))] }));
|
|
66
|
-
}
|
|
67
|
-
function RoleDeleteDialog({ pendingRoleDelete, setPendingRoleDelete, rowSavingId, onDeleteRole, t, translate }) {
|
|
68
|
-
const { prefix, suffix } = roleDeleteBodyParts({ translate });
|
|
69
|
-
return (_jsx(ConfirmDialog, { cancelLabel: t("Cancel"), open: pendingRoleDelete !== null, agentHandle: "roles-delete-role", title: t("Delete role?"), body: pendingRoleDelete ? (_jsxs("p", { children: [prefix, pendingRoleDelete.name, suffix] })) : null, confirmLabel: t("Delete"), destructive: true, pending: pendingRoleDelete !== null && rowSavingId === pendingRoleDelete.id, onConfirm: onDeleteRole, onCancel: () => setPendingRoleDelete(null) }));
|
|
70
|
-
}
|
|
71
|
-
function PolicyDeleteDialog({ pendingPolicyDelete, setPendingPolicyDelete, rowSavingId, onDeletePolicy, t, translate }) {
|
|
72
|
-
const { prefix, suffix } = policyDeleteBodyParts({ translate });
|
|
73
|
-
return (_jsx(ConfirmDialog, { cancelLabel: t("Cancel"), open: pendingPolicyDelete !== null, agentHandle: "roles-delete-policy", title: t("Delete policy?"), body: pendingPolicyDelete ? (_jsxs("p", { children: [prefix, pendingPolicyDelete.name, suffix] })) : null, confirmLabel: t("Delete"), destructive: true, pending: pendingPolicyDelete !== null && rowSavingId === pendingPolicyDelete.id, onConfirm: onDeletePolicy, onCancel: () => setPendingPolicyDelete(null) }));
|
|
74
|
-
}
|
|
75
|
-
function PermissionRemoveDialog({ pendingPermissionRemove, setPendingPermissionRemove, removingPermissionId, onConfirmRemovePermission, t, translate, }) {
|
|
76
|
-
const { prefix, suffix } = permissionRemoveBodyParts({ translate });
|
|
77
|
-
const pending = pendingPermissionRemove;
|
|
78
|
-
return (_jsx(ConfirmDialog, { cancelLabel: t("Cancel"), open: pending !== null, agentHandle: "roles-remove-permission", title: t("Remove permission?"), body: pending ? (_jsxs("p", { children: [prefix, _jsx("code", { children: pending.row.permission }), pending.row.resourceType ? ` (${pending.row.resourceType})` : "", suffix] })) : null, confirmLabel: t("Remove"), tone: "warning", pending: pending !== null && removingPermissionId === pending.row.id, onConfirm: onConfirmRemovePermission, onCancel: () => setPendingPermissionRemove(null) }));
|
|
79
|
-
}
|
|
80
|
-
function RolesTab({ controller }) {
|
|
81
|
-
const c = controller;
|
|
82
|
-
return (_jsx(RolesSection, { roles: c.roles ?? [], create: {
|
|
83
|
-
name: c.roleName,
|
|
84
|
-
setName: c.setRoleName,
|
|
85
|
-
saving: c.roleSaving,
|
|
86
|
-
error: c.roleError,
|
|
87
|
-
submit: c.onCreateRole,
|
|
88
|
-
}, row: {
|
|
89
|
-
editingId: c.editingRoleId,
|
|
90
|
-
setEditingId: c.setEditingRoleId,
|
|
91
|
-
draftName: c.editingRoleName,
|
|
92
|
-
setDraftName: c.setEditingRoleName,
|
|
93
|
-
startRename: c.startEditRole,
|
|
94
|
-
saveRename: c.onSaveRole,
|
|
95
|
-
savingId: c.rowSavingId,
|
|
96
|
-
requestDelete: c.setPendingRoleDelete,
|
|
97
|
-
}, t: c.t, translate: c.translate }));
|
|
98
|
-
}
|
|
99
|
-
function PoliciesTab({ controller }) {
|
|
100
|
-
const c = controller;
|
|
101
|
-
return (_jsx(PoliciesSection, { policies: c.policies ?? [], create: {
|
|
102
|
-
name: c.policyName,
|
|
103
|
-
setName: c.setPolicyName,
|
|
104
|
-
description: c.policyDescription,
|
|
105
|
-
setDescription: c.setPolicyDescription,
|
|
106
|
-
saving: c.policySaving,
|
|
107
|
-
error: c.policyError,
|
|
108
|
-
submit: c.onCreatePolicy,
|
|
109
|
-
}, row: {
|
|
110
|
-
editingId: c.editingPolicyId,
|
|
111
|
-
setEditingId: c.setEditingPolicyId,
|
|
112
|
-
draftName: c.editingPolicyName,
|
|
113
|
-
setDraftName: c.setEditingPolicyName,
|
|
114
|
-
draftDescription: c.editingPolicyDescription,
|
|
115
|
-
setDraftDescription: c.setEditingPolicyDescription,
|
|
116
|
-
startRename: c.startEditPolicy,
|
|
117
|
-
saveRename: c.onSavePolicy,
|
|
118
|
-
savingId: c.rowSavingId,
|
|
119
|
-
requestDelete: c.setPendingPolicyDelete,
|
|
120
|
-
}, permission: {
|
|
121
|
-
openForPolicyId: c.permissionPolicyId,
|
|
122
|
-
permission: c.permissionInput,
|
|
123
|
-
setPermission: c.setPermissionInput,
|
|
124
|
-
resourceType: c.resourceTypeInput,
|
|
125
|
-
setResourceType: c.setResourceTypeInput,
|
|
126
|
-
toggleForm: c.togglePermissionForm,
|
|
127
|
-
write: c.onWritePermission,
|
|
128
|
-
rows: c.permissionRows,
|
|
129
|
-
loading: c.permissionsLoading,
|
|
130
|
-
removingId: c.removingPermissionId,
|
|
131
|
-
requestRemove: c.setPendingPermissionRemove,
|
|
132
|
-
}, t: c.t, translate: c.translate }));
|
|
133
|
-
}
|
|
134
|
-
function rolesTabPanel(activeTabId, controller) {
|
|
135
|
-
if (activeTabId === "policies")
|
|
136
|
-
return _jsx(PoliciesTab, { controller: controller });
|
|
137
|
-
return _jsx(RolesTab, { controller: controller });
|
|
138
|
-
}
|
|
139
|
-
export function Roles({ tabId, useRolesHook = useRoles, port, translate: injectedTranslate, queryScope, onTabChange, usersHref }) {
|
|
140
|
-
const controller = useRolesHook({ port, translate: injectedTranslate, queryScope });
|
|
141
|
-
const { roles, policies, error, rowError, rowSavingId, pendingRoleDelete, setPendingRoleDelete, onDeleteRole, pendingPolicyDelete, setPendingPolicyDelete, onDeletePolicy, pendingPermissionRemove, setPendingPermissionRemove, removingPermissionId, onConfirmRemovePermission, t, translate, } = controller;
|
|
142
|
-
const { prefix: descriptionPrefix, linkLabel: descriptionLinkLabel, suffix: descriptionSuffix } = rolesDescriptionParts({ translate });
|
|
143
|
-
if (error)
|
|
144
|
-
return _jsx("div", { className: "notice error", children: error });
|
|
145
|
-
if (!roles || !policies)
|
|
146
|
-
return _jsx("div", { className: "notice", children: t("Loading roles & permissions…") });
|
|
147
|
-
const activeTabId = resolveRolesTabId({ tabId });
|
|
148
|
-
return (_jsxs("div", { className: "page", children: [_jsx("div", { className: "page-header", children: _jsxs("div", { className: "page-header-text", children: [_jsx("p", { className: "page-kicker", children: t("People") }), _jsx("h1", { className: "page-title", children: t("Roles & Permissions") }), _jsxs("p", { className: "page-description", children: [descriptionPrefix, _jsx("a", { href: usersHref, children: descriptionLinkLabel }), descriptionSuffix] })] }) }), rowError ? _jsx("div", { className: "notice error", children: rowError }) : null, _jsx(TabBar, { ariaLabel: t("Roles & Permissions"), tabs: resolveRolesTabs({ translate: t }), activeId: activeTabId, onChange: (next) => onTabChange({ tabId: resolveRolesTabId({ tabId: next }) }), containerHandle: "roles-tab-bar" }), rolesTabPanel(activeTabId, controller), _jsx(RoleDeleteDialog, { pendingRoleDelete: pendingRoleDelete, setPendingRoleDelete: setPendingRoleDelete, rowSavingId: rowSavingId, t: t, translate: translate, onDeleteRole: onDeleteRole }), _jsx(PolicyDeleteDialog, { pendingPolicyDelete: pendingPolicyDelete, setPendingPolicyDelete: setPendingPolicyDelete, rowSavingId: rowSavingId, t: t, translate: translate, onDeletePolicy: onDeletePolicy }), _jsx(PermissionRemoveDialog, { pendingPermissionRemove: pendingPermissionRemove, setPendingPermissionRemove: setPendingPermissionRemove, removingPermissionId: removingPermissionId, onConfirmRemovePermission: onConfirmRemovePermission, t: t, translate: translate })] }));
|
|
149
|
-
}
|
|
150
|
-
//# sourceMappingURL=Roles.js.map
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import type { Translate } from "@jini-ai/ui/panel-kit";
|
|
2
|
-
import { type AdminPolicy, type AdminPolicyPermission, type AdminRole } from "../../models.js";
|
|
3
|
-
import type { RolesPort } from "../../ports.js";
|
|
4
|
-
export interface PendingPermissionRemove {
|
|
5
|
-
policyId: string;
|
|
6
|
-
row: AdminPolicyPermission;
|
|
7
|
-
}
|
|
8
|
-
export interface RolesController {
|
|
9
|
-
roles: AdminRole[] | null;
|
|
10
|
-
policies: AdminPolicy[] | null;
|
|
11
|
-
error: string | null;
|
|
12
|
-
rowError: string | null;
|
|
13
|
-
roleName: string;
|
|
14
|
-
setRoleName: (name: string) => void;
|
|
15
|
-
roleSaving: boolean;
|
|
16
|
-
roleError: string | null;
|
|
17
|
-
onCreateRole: (e: React.FormEvent) => Promise<void>;
|
|
18
|
-
policyName: string;
|
|
19
|
-
setPolicyName: (name: string) => void;
|
|
20
|
-
policyDescription: string;
|
|
21
|
-
setPolicyDescription: (description: string) => void;
|
|
22
|
-
policySaving: boolean;
|
|
23
|
-
policyError: string | null;
|
|
24
|
-
onCreatePolicy: (e: React.FormEvent) => Promise<void>;
|
|
25
|
-
editingRoleId: string | null;
|
|
26
|
-
setEditingRoleId: (roleId: string | null) => void;
|
|
27
|
-
editingRoleName: string;
|
|
28
|
-
setEditingRoleName: (name: string) => void;
|
|
29
|
-
startEditRole: (role: AdminRole) => void;
|
|
30
|
-
onSaveRole: (required: {
|
|
31
|
-
roleId: string;
|
|
32
|
-
}) => Promise<void>;
|
|
33
|
-
editingPolicyId: string | null;
|
|
34
|
-
setEditingPolicyId: (policyId: string | null) => void;
|
|
35
|
-
editingPolicyName: string;
|
|
36
|
-
setEditingPolicyName: (name: string) => void;
|
|
37
|
-
editingPolicyDescription: string;
|
|
38
|
-
setEditingPolicyDescription: (description: string) => void;
|
|
39
|
-
startEditPolicy: (policy: AdminPolicy) => void;
|
|
40
|
-
onSavePolicy: (required: {
|
|
41
|
-
policyId: string;
|
|
42
|
-
}) => Promise<void>;
|
|
43
|
-
rowSavingId: string | null;
|
|
44
|
-
permissionPolicyId: string | null;
|
|
45
|
-
permissionInput: string;
|
|
46
|
-
setPermissionInput: (permission: string) => void;
|
|
47
|
-
resourceTypeInput: string;
|
|
48
|
-
setResourceTypeInput: (resourceType: string) => void;
|
|
49
|
-
togglePermissionForm: (required: {
|
|
50
|
-
policyId: string;
|
|
51
|
-
}) => void;
|
|
52
|
-
onWritePermission: (required: {
|
|
53
|
-
policyId: string;
|
|
54
|
-
}) => Promise<void>;
|
|
55
|
-
permissionRows: AdminPolicyPermission[];
|
|
56
|
-
permissionsLoading: boolean;
|
|
57
|
-
removingPermissionId: string | null;
|
|
58
|
-
onRemovePermission: (required: {
|
|
59
|
-
policyId: string;
|
|
60
|
-
policyPermissionId: string;
|
|
61
|
-
}) => Promise<void>;
|
|
62
|
-
pendingPermissionRemove: PendingPermissionRemove | null;
|
|
63
|
-
setPendingPermissionRemove: (target: PendingPermissionRemove | null) => void;
|
|
64
|
-
onConfirmRemovePermission: () => Promise<void>;
|
|
65
|
-
pendingRoleDelete: AdminRole | null;
|
|
66
|
-
setPendingRoleDelete: (role: AdminRole | null) => void;
|
|
67
|
-
onDeleteRole: () => Promise<void>;
|
|
68
|
-
pendingPolicyDelete: AdminPolicy | null;
|
|
69
|
-
setPendingPolicyDelete: (policy: AdminPolicy | null) => void;
|
|
70
|
-
onDeletePolicy: () => Promise<void>;
|
|
71
|
-
t: (key: string) => string;
|
|
72
|
-
translate: Translate;
|
|
73
|
-
}
|
|
74
|
-
export interface RolesDependencies {
|
|
75
|
-
port: RolesPort;
|
|
76
|
-
translate: Translate;
|
|
77
|
-
queryScope: string;
|
|
78
|
-
}
|
|
79
|
-
export declare function useRoles(deps: RolesDependencies): RolesController;
|
|
80
|
-
//# sourceMappingURL=use-roles.hooks.d.ts.map
|