@contember/create 2.2.0-alpha.1 → 2.2.0-alpha.10
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/CLAUDE.md +22 -0
- package/dist/development/run.cjs +7 -7
- package/dist/development/run.cjs.map +1 -1
- package/dist/development/run.js +8 -8
- package/dist/development/run.js.map +1 -1
- package/dist/development/src/commands/WorkspaceCreateCommand.cjs +27 -13
- package/dist/development/src/commands/WorkspaceCreateCommand.cjs.map +1 -1
- package/dist/development/src/commands/WorkspaceCreateCommand.js +28 -14
- package/dist/development/src/commands/WorkspaceCreateCommand.js.map +1 -1
- package/dist/development/src/lib/TemplateInstaller.cjs +72 -60
- package/dist/development/src/lib/TemplateInstaller.cjs.map +1 -1
- package/dist/development/src/lib/TemplateInstaller.js +72 -60
- package/dist/development/src/lib/TemplateInstaller.js.map +1 -1
- package/dist/production/run.cjs +7 -7
- package/dist/production/run.cjs.map +1 -1
- package/dist/production/run.js +8 -8
- package/dist/production/run.js.map +1 -1
- package/dist/production/src/commands/WorkspaceCreateCommand.cjs +27 -13
- package/dist/production/src/commands/WorkspaceCreateCommand.cjs.map +1 -1
- package/dist/production/src/commands/WorkspaceCreateCommand.js +28 -14
- package/dist/production/src/commands/WorkspaceCreateCommand.js.map +1 -1
- package/dist/production/src/lib/TemplateInstaller.cjs +72 -60
- package/dist/production/src/lib/TemplateInstaller.cjs.map +1 -1
- package/dist/production/src/lib/TemplateInstaller.js +72 -60
- package/dist/production/src/lib/TemplateInstaller.js.map +1 -1
- package/dist/types/commands/WorkspaceCreateCommand.d.ts +15 -3
- package/dist/types/commands/WorkspaceCreateCommand.d.ts.map +1 -1
- package/dist/types/lib/FileSystem.d.ts.map +1 -1
- package/dist/types/lib/TemplateInstaller.d.ts +9 -1
- package/dist/types/lib/TemplateInstaller.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/resources/templates/default/README.md +3 -1
- package/resources/templates/default/admin/app/components/navigation.tsx +95 -8
- package/resources/templates/default/admin/app/pages/tenant.tsx +328 -77
- package/resources/templates/default/admin/entrypoint/components/login.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/magicLink.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/magicLinkSent.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/passwordReset.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/resetRequest.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/resetRequestSuccess.tsx +1 -1
- package/resources/templates/default/admin/lib/tenant/config/auth-policy-list.tsx +86 -0
- package/resources/templates/default/admin/lib/tenant/config/common.tsx +71 -0
- package/resources/templates/default/admin/lib/tenant/config/identity-provider-list.tsx +113 -0
- package/resources/templates/default/admin/lib/tenant/config/index.ts +5 -0
- package/resources/templates/default/admin/lib/tenant/config/mail-template-list.tsx +108 -0
- package/resources/templates/default/admin/lib/tenant/config/tenant-config-view.tsx +182 -0
- package/resources/templates/default/admin/lib/tenant/dict.ts +450 -4
- package/resources/templates/default/admin/lib/tenant/errors.ts +10 -0
- package/resources/templates/default/admin/lib/tenant/forms/add-project-member.tsx +57 -0
- package/resources/templates/default/admin/lib/tenant/forms/change-my-profile.tsx +40 -0
- package/resources/templates/default/admin/lib/tenant/forms/change-profile.tsx +55 -0
- package/resources/templates/default/admin/lib/tenant/forms/common.tsx +9 -2
- package/resources/templates/default/admin/lib/tenant/forms/create-global-api-key.tsx +69 -0
- package/resources/templates/default/admin/lib/tenant/forms/global-roles-control.tsx +113 -0
- package/resources/templates/default/admin/lib/tenant/forms/index.ts +11 -0
- package/resources/templates/default/admin/lib/tenant/forms/invite.tsx +42 -4
- package/resources/templates/default/admin/lib/tenant/forms/login.tsx +4 -10
- package/resources/templates/default/admin/lib/tenant/forms/memberships-control.tsx +3 -1
- package/resources/templates/default/admin/lib/tenant/forms/mfa-code-fields.tsx +81 -0
- package/resources/templates/default/admin/lib/tenant/forms/passwordless-signin.tsx +4 -10
- package/resources/templates/default/admin/lib/tenant/forms/set-person-password.tsx +58 -0
- package/resources/templates/default/admin/lib/tenant/forms/set-project-secret.tsx +59 -0
- package/resources/templates/default/admin/lib/tenant/forms/sign-up.tsx +73 -0
- package/resources/templates/default/admin/lib/tenant/hooks/index.ts +2 -0
- package/resources/templates/default/admin/lib/tenant/idp/identity-provider-connections.tsx +124 -0
- package/resources/templates/default/admin/lib/tenant/idp/index.ts +1 -0
- package/resources/templates/default/admin/lib/tenant/index.ts +7 -0
- package/resources/templates/default/admin/lib/tenant/listing/api-key-list.tsx +160 -22
- package/resources/templates/default/admin/lib/tenant/listing/auth-log-list.tsx +179 -0
- package/resources/templates/default/admin/lib/tenant/listing/global-api-key-list.tsx +149 -0
- package/resources/templates/default/admin/lib/tenant/listing/index.ts +7 -0
- package/resources/templates/default/admin/lib/tenant/listing/member-delete-dialog.tsx +1 -1
- package/resources/templates/default/admin/lib/tenant/listing/member-list.tsx +20 -11
- package/resources/templates/default/admin/lib/tenant/listing/mfa.tsx +29 -0
- package/resources/templates/default/admin/lib/tenant/listing/person-actions.tsx +179 -0
- package/resources/templates/default/admin/lib/tenant/listing/person-detail.tsx +141 -0
- package/resources/templates/default/admin/lib/tenant/listing/person-list.tsx +13 -2
- package/resources/templates/default/admin/lib/tenant/listing/persons-list.tsx +128 -0
- package/resources/templates/default/admin/lib/tenant/listing/project-secret-list.tsx +82 -0
- package/resources/templates/default/admin/lib/tenant/otp/backup-codes.tsx +81 -0
- package/resources/templates/default/admin/lib/tenant/otp/email-otp-setup.tsx +133 -0
- package/resources/templates/default/admin/lib/tenant/otp/index.ts +2 -0
- package/resources/templates/default/admin/lib/tenant/security/index.ts +2 -0
- package/resources/templates/default/admin/lib/tenant/security/passwordless-toggle.tsx +63 -0
- package/resources/templates/default/admin/lib/tenant/security/session-list.tsx +143 -0
- package/resources/templates/default/admin/package.json +1 -0
- package/resources/templates/default/docker/object-storage/README.md +13 -0
- package/resources/templates/default/docker/object-storage/identities.json +13 -0
- package/resources/templates/default/docker-compose.yaml +29 -7
- package/src/commands/WorkspaceCreateCommand.ts +42 -14
- package/src/lib/TemplateInstaller.ts +87 -69
- package/src/run.ts +8 -7
- package/tests/cases/unit/create-process.test.ts +66 -0
- package/tests/cases/unit/template-installer-cleanup.test.ts +150 -0
- package/tests/cases/unit/workspace-create.test.ts +81 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { ReactNode, useState } from 'react'
|
|
3
|
+
import {
|
|
4
|
+
AlertDialog,
|
|
5
|
+
AlertDialogAction,
|
|
6
|
+
AlertDialogCancel,
|
|
7
|
+
AlertDialogContent,
|
|
8
|
+
AlertDialogFooter,
|
|
9
|
+
AlertDialogHeader,
|
|
10
|
+
AlertDialogTitle,
|
|
11
|
+
AlertDialogTrigger,
|
|
12
|
+
Button,
|
|
13
|
+
Loader,
|
|
14
|
+
Table,
|
|
15
|
+
TableCell,
|
|
16
|
+
TableHead,
|
|
17
|
+
TableHeader,
|
|
18
|
+
TableRow,
|
|
19
|
+
ToastContent,
|
|
20
|
+
useShowToast,
|
|
21
|
+
} from '~/lib'
|
|
22
|
+
import { BanIcon, RefreshCwIcon } from 'lucide-react'
|
|
23
|
+
import { toFormErrorCode, useDisableApiKeyMutation, useGlobalApiKeysQuery, useTenantQueryLoader } from '@contember/react-client-tenant'
|
|
24
|
+
import { dict } from '../dict.js'
|
|
25
|
+
import { actionErrorMessage } from '../errors.js'
|
|
26
|
+
|
|
27
|
+
const formatDateTime = (value?: string | null): ReactNode => {
|
|
28
|
+
if (!value) {
|
|
29
|
+
return <span className="text-gray-400 italic">{dict.tenant.globalApiKeyList.never}</span>
|
|
30
|
+
}
|
|
31
|
+
return new Date(value).toLocaleString()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface GlobalApiKeyListController {
|
|
35
|
+
refresh: () => void
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface GlobalApiKeyListProps {
|
|
39
|
+
controller?: { current?: GlobalApiKeyListController }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const GlobalApiKeyList = ({ controller }: GlobalApiKeyListProps) => {
|
|
43
|
+
const [query, { refresh }] = useTenantQueryLoader(useGlobalApiKeysQuery(), {})
|
|
44
|
+
if (controller) {
|
|
45
|
+
controller.current = { refresh }
|
|
46
|
+
}
|
|
47
|
+
const showToast = useShowToast()
|
|
48
|
+
|
|
49
|
+
const onDisabled = () => {
|
|
50
|
+
refresh()
|
|
51
|
+
showToast(<ToastContent>{dict.tenant.globalApiKeyList.disableSuccess}</ToastContent>, { type: 'success' })
|
|
52
|
+
}
|
|
53
|
+
const onDisableError = (code: string) => {
|
|
54
|
+
showToast(<ToastContent>{actionErrorMessage(code, dict.tenant.globalApiKeyList.disableFailed)}</ToastContent>, { type: 'error' })
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (query.state === 'error') {
|
|
58
|
+
return <div className="text-destructive italic">{dict.tenant.globalApiKeyList.failedToLoadData}</div>
|
|
59
|
+
}
|
|
60
|
+
return (
|
|
61
|
+
<div className="relative">
|
|
62
|
+
{query.state !== 'success' && <Loader position="absolute" />}
|
|
63
|
+
<Table>
|
|
64
|
+
<TableHeader>
|
|
65
|
+
<TableRow>
|
|
66
|
+
<TableHead>{dict.tenant.globalApiKeyList.description}</TableHead>
|
|
67
|
+
<TableHead>{dict.tenant.globalApiKeyList.roles}</TableHead>
|
|
68
|
+
<TableHead>{dict.tenant.globalApiKeyList.status}</TableHead>
|
|
69
|
+
<TableHead>{dict.tenant.globalApiKeyList.created}</TableHead>
|
|
70
|
+
<TableHead>{dict.tenant.globalApiKeyList.lastUsed}</TableHead>
|
|
71
|
+
<TableHead>{dict.tenant.globalApiKeyList.expires}</TableHead>
|
|
72
|
+
<TableHead className="w-24">
|
|
73
|
+
<div className="flex gap-2 items-center">
|
|
74
|
+
<span>{dict.tenant.globalApiKeyList.action}</span>
|
|
75
|
+
<Button variant="outline" onClick={refresh} className="ml-auto" size="sm">
|
|
76
|
+
<RefreshCwIcon className="w-3 h-3" />
|
|
77
|
+
</Button>
|
|
78
|
+
</div>
|
|
79
|
+
</TableHead>
|
|
80
|
+
</TableRow>
|
|
81
|
+
</TableHeader>
|
|
82
|
+
{'data' in query && query.data.length === 0 && (
|
|
83
|
+
<TableRow>
|
|
84
|
+
<TableCell colSpan={7}>{dict.tenant.globalApiKeyList.noResults}</TableCell>
|
|
85
|
+
</TableRow>
|
|
86
|
+
)}
|
|
87
|
+
{'data' in query && query.data.map(apiKey => (
|
|
88
|
+
<TableRow key={apiKey.id}>
|
|
89
|
+
<TableCell>{apiKey.description ?? dict.tenant.globalApiKeyList.unnamed}</TableCell>
|
|
90
|
+
<TableCell>
|
|
91
|
+
{apiKey.identity.roles?.length ? apiKey.identity.roles.join(', ') : dict.tenant.globalApiKeyList.noRoles}
|
|
92
|
+
</TableCell>
|
|
93
|
+
<TableCell>
|
|
94
|
+
{apiKey.enabled === false
|
|
95
|
+
? <span className="text-destructive">{dict.tenant.globalApiKeyList.disabled}</span>
|
|
96
|
+
: dict.tenant.globalApiKeyList.enabled}
|
|
97
|
+
</TableCell>
|
|
98
|
+
<TableCell className="whitespace-nowrap">{formatDateTime(apiKey.createdAt)}</TableCell>
|
|
99
|
+
<TableCell className="whitespace-nowrap">{formatDateTime(apiKey.lastUsedAt)}</TableCell>
|
|
100
|
+
<TableCell className="whitespace-nowrap">{formatDateTime(apiKey.expiresAt)}</TableCell>
|
|
101
|
+
<TableCell className="whitespace-nowrap">
|
|
102
|
+
{apiKey.enabled !== false && <DisableApiKeyDialog apiKeyId={apiKey.id} onSuccess={onDisabled} onError={onDisableError} />}
|
|
103
|
+
</TableCell>
|
|
104
|
+
</TableRow>
|
|
105
|
+
))}
|
|
106
|
+
</Table>
|
|
107
|
+
</div>
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const DisableApiKeyDialog = ({ apiKeyId, onSuccess, onError }: { apiKeyId: string; onSuccess: () => void; onError: (code: string) => void }) => {
|
|
112
|
+
const disableApiKey = useDisableApiKeyMutation()
|
|
113
|
+
const [open, setOpen] = useState(false)
|
|
114
|
+
const onConfirm = async () => {
|
|
115
|
+
try {
|
|
116
|
+
const result = await disableApiKey({ id: apiKeyId })
|
|
117
|
+
setOpen(false)
|
|
118
|
+
if (result.ok) {
|
|
119
|
+
onSuccess()
|
|
120
|
+
} else {
|
|
121
|
+
onError('UNKNOWN_ERROR')
|
|
122
|
+
}
|
|
123
|
+
} catch (e) {
|
|
124
|
+
// A denied mutation throws; without this the dialog would just hang on an unhandled rejection.
|
|
125
|
+
setOpen(false)
|
|
126
|
+
onError(toFormErrorCode(e))
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return (
|
|
130
|
+
<AlertDialog open={open} onOpenChange={setOpen}>
|
|
131
|
+
<AlertDialogTrigger asChild>
|
|
132
|
+
<Button variant="destructive">
|
|
133
|
+
<BanIcon className="w-3 h-3" />
|
|
134
|
+
</Button>
|
|
135
|
+
</AlertDialogTrigger>
|
|
136
|
+
<AlertDialogContent>
|
|
137
|
+
<AlertDialogHeader>
|
|
138
|
+
<AlertDialogTitle>{dict.tenant.globalApiKeyList.disableConfirmation}</AlertDialogTitle>
|
|
139
|
+
</AlertDialogHeader>
|
|
140
|
+
<AlertDialogFooter>
|
|
141
|
+
<AlertDialogCancel>{dict.tenant.globalApiKeyList.cancel}</AlertDialogCancel>
|
|
142
|
+
<AlertDialogAction asChild>
|
|
143
|
+
<Button variant="destructive" onClick={onConfirm}>{dict.tenant.globalApiKeyList.disable}</Button>
|
|
144
|
+
</AlertDialogAction>
|
|
145
|
+
</AlertDialogFooter>
|
|
146
|
+
</AlertDialogContent>
|
|
147
|
+
</AlertDialog>
|
|
148
|
+
)
|
|
149
|
+
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
export * from './api-key-list.js'
|
|
2
|
+
export * from './auth-log-list.js'
|
|
3
|
+
export * from './global-api-key-list.js'
|
|
2
4
|
export * from './member-delete-dialog.js'
|
|
3
5
|
export * from './member-list.js'
|
|
6
|
+
export * from './mfa.js'
|
|
7
|
+
export * from './person-actions.js'
|
|
8
|
+
export * from './person-detail.js'
|
|
4
9
|
export * from './person-list.js'
|
|
10
|
+
export * from './persons-list.js'
|
|
11
|
+
export * from './project-secret-list.js'
|
|
@@ -20,7 +20,7 @@ export interface MemberDeleteProps {
|
|
|
20
20
|
identityId: string
|
|
21
21
|
projectSlug: string
|
|
22
22
|
onSuccess: () => void
|
|
23
|
-
onError: (
|
|
23
|
+
onError: (args: { code: string }) => void
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export const MemberDeleteDialog = ({ onError, title, identityId, onSuccess, projectSlug }: MemberDeleteProps) => {
|
|
@@ -10,6 +10,7 @@ import { useProjectSlug } from '@contember/react-client'
|
|
|
10
10
|
import { UpdateProjectMemberForm } from '@contember/interface'
|
|
11
11
|
import { ToastContent, useShowToast } from '~/lib'
|
|
12
12
|
import { dict } from '../dict.js'
|
|
13
|
+
import { actionErrorMessage } from '../errors.js'
|
|
13
14
|
import { MemberDeleteDialog } from './member-delete-dialog.js'
|
|
14
15
|
import { Dialog, DialogContent, DialogTrigger } from '~/lib'
|
|
15
16
|
import { RolesConfig, UpdateProjectMemberFormFields } from '../forms/index.js'
|
|
@@ -27,13 +28,17 @@ export interface MemberListProps {
|
|
|
27
28
|
tableHeaders: string[]
|
|
28
29
|
controller?: { current?: MemberListController }
|
|
29
30
|
roles?: RolesConfig
|
|
31
|
+
canUpdateMember?: boolean
|
|
32
|
+
canRemoveMember?: boolean
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
export interface MemberListController {
|
|
33
36
|
refresh: () => void
|
|
34
37
|
}
|
|
35
38
|
|
|
36
|
-
export const MemberList = (
|
|
39
|
+
export const MemberList = (
|
|
40
|
+
{ filter, labels, tableColumns, controller, tableHeaders, roles, canUpdateMember, canRemoveMember }: MemberListProps,
|
|
41
|
+
) => {
|
|
37
42
|
const projectSlug = useProjectSlug()!
|
|
38
43
|
const [page, setPage] = useState(0)
|
|
39
44
|
|
|
@@ -52,8 +57,8 @@ export const MemberList = ({ filter, labels, tableColumns, controller, tableHead
|
|
|
52
57
|
refresh()
|
|
53
58
|
showToast(<ToastContent>{labels.deleted}</ToastContent>, { type: 'success' })
|
|
54
59
|
}
|
|
55
|
-
const onDeleteError = () => {
|
|
56
|
-
showToast(<ToastContent>{labels.deleteFailed}</ToastContent>, { type: 'error' })
|
|
60
|
+
const onDeleteError = ({ code }: { code: string }) => {
|
|
61
|
+
showToast(<ToastContent>{actionErrorMessage(code, labels.deleteFailed)}</ToastContent>, { type: 'error' })
|
|
57
62
|
}
|
|
58
63
|
|
|
59
64
|
switch (query.state) {
|
|
@@ -95,14 +100,18 @@ export const MemberList = ({ filter, labels, tableColumns, controller, tableHead
|
|
|
95
100
|
{tableColumns(it)}
|
|
96
101
|
<TableCell key="role">{it.memberships.map((m: any) => m.role).join(', ')}</TableCell>
|
|
97
102
|
<TableCell className="space-x-2 whitespace-nowrap">
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
{canRemoveMember !== false && (
|
|
104
|
+
<MemberDeleteDialog
|
|
105
|
+
identityId={it.identity.id}
|
|
106
|
+
projectSlug={projectSlug}
|
|
107
|
+
onSuccess={onDeleteMember}
|
|
108
|
+
onError={onDeleteError}
|
|
109
|
+
title={labels.deleteConfirmation}
|
|
110
|
+
/>
|
|
111
|
+
)}
|
|
112
|
+
{canUpdateMember !== false && (
|
|
113
|
+
<EditMembershipDialog projectSlug={projectSlug} identityId={it.identity.id} onSuccess={refresh} roles={roles} />
|
|
114
|
+
)}
|
|
106
115
|
</TableCell>
|
|
107
116
|
</TableRow>
|
|
108
117
|
))}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { dict } from '../dict.js'
|
|
3
|
+
|
|
4
|
+
export interface MfaBadgesProps {
|
|
5
|
+
otpEnabled?: boolean | null
|
|
6
|
+
emailOtpEnabled?: boolean | null
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const MfaBadges = ({ otpEnabled, emailOtpEnabled }: MfaBadgesProps) => {
|
|
10
|
+
const methods: string[] = []
|
|
11
|
+
if (otpEnabled) {
|
|
12
|
+
methods.push(dict.tenant.mfa.totp)
|
|
13
|
+
}
|
|
14
|
+
if (emailOtpEnabled) {
|
|
15
|
+
methods.push(dict.tenant.mfa.email)
|
|
16
|
+
}
|
|
17
|
+
if (methods.length === 0) {
|
|
18
|
+
return <span className="text-gray-400 italic">{dict.tenant.mfa.none}</span>
|
|
19
|
+
}
|
|
20
|
+
return (
|
|
21
|
+
<span className="flex gap-1 flex-wrap">
|
|
22
|
+
{methods.map(method => (
|
|
23
|
+
<span key={method} className="inline-flex items-center border border-gray-200 rounded-sm px-1.5 py-0.5 text-xs">
|
|
24
|
+
{method}
|
|
25
|
+
</span>
|
|
26
|
+
))}
|
|
27
|
+
</span>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { ReactNode, useState } from 'react'
|
|
3
|
+
import {
|
|
4
|
+
AlertDialog,
|
|
5
|
+
AlertDialogAction,
|
|
6
|
+
AlertDialogCancel,
|
|
7
|
+
AlertDialogContent,
|
|
8
|
+
AlertDialogFooter,
|
|
9
|
+
AlertDialogHeader,
|
|
10
|
+
AlertDialogTitle,
|
|
11
|
+
AlertDialogTrigger,
|
|
12
|
+
Button,
|
|
13
|
+
Input,
|
|
14
|
+
Label,
|
|
15
|
+
ToastContent,
|
|
16
|
+
useShowToast,
|
|
17
|
+
} from '~/lib'
|
|
18
|
+
import { BanIcon, LogOutIcon, ShieldOffIcon, UserCheckIcon } from 'lucide-react'
|
|
19
|
+
import { DisablePersonTrigger, EnablePersonTrigger, ForceSignOutPersonTrigger, ResetPersonMfaTrigger } from '@contember/interface'
|
|
20
|
+
import { dict } from '../dict.js'
|
|
21
|
+
import { actionErrorMessage } from '../errors.js'
|
|
22
|
+
|
|
23
|
+
export interface PersonActionProps {
|
|
24
|
+
personId: string
|
|
25
|
+
onSuccess: () => void
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Shared shell: an icon button opening a confirm dialog whose action slot hosts the tenant trigger. */
|
|
29
|
+
const PersonActionDialog = ({ icon, title, confirmation, confirmLabel, destructive, children, action }: {
|
|
30
|
+
icon: ReactNode
|
|
31
|
+
title: string
|
|
32
|
+
confirmation: string
|
|
33
|
+
confirmLabel: string
|
|
34
|
+
destructive?: boolean
|
|
35
|
+
children?: ReactNode
|
|
36
|
+
action: (props: { children: React.ReactElement }) => ReactNode
|
|
37
|
+
}) => {
|
|
38
|
+
const [open, setOpen] = useState(false)
|
|
39
|
+
return (
|
|
40
|
+
<AlertDialog open={open} onOpenChange={setOpen}>
|
|
41
|
+
<AlertDialogTrigger asChild>
|
|
42
|
+
<Button variant={destructive ? 'destructive' : 'outline'} size="sm" title={title}>
|
|
43
|
+
{icon}
|
|
44
|
+
<span className="sr-only">{title}</span>
|
|
45
|
+
</Button>
|
|
46
|
+
</AlertDialogTrigger>
|
|
47
|
+
<AlertDialogContent>
|
|
48
|
+
<AlertDialogHeader>
|
|
49
|
+
<AlertDialogTitle>{confirmation}</AlertDialogTitle>
|
|
50
|
+
</AlertDialogHeader>
|
|
51
|
+
{children}
|
|
52
|
+
<AlertDialogFooter>
|
|
53
|
+
<AlertDialogCancel>{dict.tenant.personActions.cancel}</AlertDialogCancel>
|
|
54
|
+
<AlertDialogAction asChild>
|
|
55
|
+
{action({
|
|
56
|
+
children: <Button variant={destructive ? 'destructive' : 'default'}>{confirmLabel}</Button>,
|
|
57
|
+
})}
|
|
58
|
+
</AlertDialogAction>
|
|
59
|
+
</AlertDialogFooter>
|
|
60
|
+
</AlertDialogContent>
|
|
61
|
+
</AlertDialog>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const DisablePersonAction = ({ personId, onSuccess }: PersonActionProps) => {
|
|
66
|
+
const showToast = useShowToast()
|
|
67
|
+
return (
|
|
68
|
+
<PersonActionDialog
|
|
69
|
+
icon={<BanIcon className="w-3 h-3" />}
|
|
70
|
+
title={dict.tenant.personActions.disableTitle}
|
|
71
|
+
confirmation={dict.tenant.personActions.disableConfirmation}
|
|
72
|
+
confirmLabel={dict.tenant.personActions.disable}
|
|
73
|
+
destructive
|
|
74
|
+
action={({ children }) => (
|
|
75
|
+
<DisablePersonTrigger
|
|
76
|
+
personId={personId}
|
|
77
|
+
onSuccess={() => {
|
|
78
|
+
showToast(<ToastContent>{dict.tenant.personActions.disableSuccess}</ToastContent>, { type: 'success' })
|
|
79
|
+
onSuccess()
|
|
80
|
+
}}
|
|
81
|
+
onError={({ code }) =>
|
|
82
|
+
showToast(<ToastContent>{actionErrorMessage(code, dict.tenant.personActions.disableFailed)}</ToastContent>, { type: 'error' })}
|
|
83
|
+
>
|
|
84
|
+
{children}
|
|
85
|
+
</DisablePersonTrigger>
|
|
86
|
+
)}
|
|
87
|
+
/>
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export const EnablePersonAction = ({ personId, onSuccess }: PersonActionProps) => {
|
|
92
|
+
const showToast = useShowToast()
|
|
93
|
+
return (
|
|
94
|
+
<PersonActionDialog
|
|
95
|
+
icon={<UserCheckIcon className="w-3 h-3" />}
|
|
96
|
+
title={dict.tenant.personActions.enableTitle}
|
|
97
|
+
confirmation={dict.tenant.personActions.enableConfirmation}
|
|
98
|
+
confirmLabel={dict.tenant.personActions.enable}
|
|
99
|
+
action={({ children }) => (
|
|
100
|
+
<EnablePersonTrigger
|
|
101
|
+
personId={personId}
|
|
102
|
+
onSuccess={() => {
|
|
103
|
+
showToast(<ToastContent>{dict.tenant.personActions.enableSuccess}</ToastContent>, { type: 'success' })
|
|
104
|
+
onSuccess()
|
|
105
|
+
}}
|
|
106
|
+
onError={({ code }) =>
|
|
107
|
+
showToast(<ToastContent>{actionErrorMessage(code, dict.tenant.personActions.enableFailed)}</ToastContent>, { type: 'error' })}
|
|
108
|
+
>
|
|
109
|
+
{children}
|
|
110
|
+
</EnablePersonTrigger>
|
|
111
|
+
)}
|
|
112
|
+
/>
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export const ForceSignOutPersonAction = ({ personId, onSuccess }: PersonActionProps) => {
|
|
117
|
+
const showToast = useShowToast()
|
|
118
|
+
const [reason, setReason] = useState('')
|
|
119
|
+
return (
|
|
120
|
+
<PersonActionDialog
|
|
121
|
+
icon={<LogOutIcon className="w-3 h-3" />}
|
|
122
|
+
title={dict.tenant.personActions.forceSignOutTitle}
|
|
123
|
+
confirmation={dict.tenant.personActions.forceSignOutConfirmation}
|
|
124
|
+
confirmLabel={dict.tenant.personActions.forceSignOut}
|
|
125
|
+
action={({ children }) => (
|
|
126
|
+
<ForceSignOutPersonTrigger
|
|
127
|
+
personId={personId}
|
|
128
|
+
reason={reason || undefined}
|
|
129
|
+
onSuccess={() => {
|
|
130
|
+
setReason('')
|
|
131
|
+
showToast(<ToastContent>{dict.tenant.personActions.forceSignOutSuccess}</ToastContent>, { type: 'success' })
|
|
132
|
+
onSuccess()
|
|
133
|
+
}}
|
|
134
|
+
onError={({ code }) =>
|
|
135
|
+
showToast(<ToastContent>{actionErrorMessage(code, dict.tenant.personActions.forceSignOutFailed)}</ToastContent>, { type: 'error' })}
|
|
136
|
+
>
|
|
137
|
+
{children}
|
|
138
|
+
</ForceSignOutPersonTrigger>
|
|
139
|
+
)}
|
|
140
|
+
>
|
|
141
|
+
<div className="flex flex-col gap-2">
|
|
142
|
+
<Label htmlFor="force-sign-out-reason">{dict.tenant.personActions.forceSignOutReason}</Label>
|
|
143
|
+
<Input
|
|
144
|
+
id="force-sign-out-reason"
|
|
145
|
+
type="text"
|
|
146
|
+
value={reason}
|
|
147
|
+
placeholder={dict.tenant.personActions.forceSignOutReasonPlaceholder}
|
|
148
|
+
onChange={e => setReason(e.target.value)}
|
|
149
|
+
/>
|
|
150
|
+
</div>
|
|
151
|
+
</PersonActionDialog>
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export const ResetPersonMfaAction = ({ personId, onSuccess }: PersonActionProps) => {
|
|
156
|
+
const showToast = useShowToast()
|
|
157
|
+
return (
|
|
158
|
+
<PersonActionDialog
|
|
159
|
+
icon={<ShieldOffIcon className="w-3 h-3" />}
|
|
160
|
+
title={dict.tenant.personActions.resetMfaTitle}
|
|
161
|
+
confirmation={dict.tenant.personActions.resetMfaConfirmation}
|
|
162
|
+
confirmLabel={dict.tenant.personActions.resetMfa}
|
|
163
|
+
destructive
|
|
164
|
+
action={({ children }) => (
|
|
165
|
+
<ResetPersonMfaTrigger
|
|
166
|
+
personId={personId}
|
|
167
|
+
onSuccess={() => {
|
|
168
|
+
showToast(<ToastContent>{dict.tenant.personActions.resetMfaSuccess}</ToastContent>, { type: 'success' })
|
|
169
|
+
onSuccess()
|
|
170
|
+
}}
|
|
171
|
+
onError={({ code }) =>
|
|
172
|
+
showToast(<ToastContent>{actionErrorMessage(code, dict.tenant.personActions.resetMfaFailed)}</ToastContent>, { type: 'error' })}
|
|
173
|
+
>
|
|
174
|
+
{children}
|
|
175
|
+
</ResetPersonMfaTrigger>
|
|
176
|
+
)}
|
|
177
|
+
/>
|
|
178
|
+
)
|
|
179
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { ReactNode } from 'react'
|
|
3
|
+
import { Loader, Table, TableCell, TableHead, TableHeader, TableRow, ToastContent, useShowToast } from '~/lib'
|
|
4
|
+
import { usePersonQuery, useTenantQueryLoader } from '@contember/react-client-tenant'
|
|
5
|
+
import { ChangePasswordForm, ChangeProfileForm } from '@contember/interface'
|
|
6
|
+
import { dict } from '../dict.js'
|
|
7
|
+
import { ChangeProfileFormFields, GlobalRolesControl, SetPersonPasswordFormFields } from '../forms/index.js'
|
|
8
|
+
import { SessionList } from '../security/index.js'
|
|
9
|
+
import { MfaBadges } from './mfa.js'
|
|
10
|
+
import { ResetPersonMfaAction } from './person-actions.js'
|
|
11
|
+
|
|
12
|
+
export interface PersonDetailController {
|
|
13
|
+
refresh: () => void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface PersonDetailProps {
|
|
17
|
+
personId: string
|
|
18
|
+
controller?: { current?: PersonDetailController }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const Section = ({ title, children }: { title: string; children: ReactNode }) => (
|
|
22
|
+
<div className="flex flex-col gap-2">
|
|
23
|
+
<h2 className="text-base font-semibold">{title}</h2>
|
|
24
|
+
{children}
|
|
25
|
+
</div>
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* `PersonDetail` is the administrator view of a single person — profile, password, 2FA, global roles, sessions
|
|
30
|
+
* and connected identity providers. The host application decides the surrounding layout.
|
|
31
|
+
*
|
|
32
|
+
* ## Example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* <PersonDetail personId={personId} />
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export const PersonDetail = ({ personId, controller }: PersonDetailProps) => {
|
|
38
|
+
const [query, { refresh }] = useTenantQueryLoader(usePersonQuery(), { personId })
|
|
39
|
+
if (controller) {
|
|
40
|
+
controller.current = { refresh }
|
|
41
|
+
}
|
|
42
|
+
const showToast = useShowToast()
|
|
43
|
+
|
|
44
|
+
if (query.state === 'error') {
|
|
45
|
+
return <div className="text-destructive italic">{dict.tenant.personDetail.failedToLoadData}</div>
|
|
46
|
+
}
|
|
47
|
+
if (!('data' in query)) {
|
|
48
|
+
return (
|
|
49
|
+
<div className="relative min-h-24">
|
|
50
|
+
<Loader position="absolute" />
|
|
51
|
+
</div>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
const person = query.data
|
|
55
|
+
if (person === null) {
|
|
56
|
+
return <div className="text-gray-400 italic">{dict.tenant.personDetail.notFound}</div>
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<div className="relative flex flex-col gap-8">
|
|
61
|
+
{query.state !== 'success' && <Loader position="absolute" />}
|
|
62
|
+
|
|
63
|
+
<Section title={dict.tenant.personDetail.profile}>
|
|
64
|
+
<div className="flex flex-col gap-1">
|
|
65
|
+
<span className="text-sm font-medium">{dict.tenant.personDetail.identityId}</span>
|
|
66
|
+
<code className="select-all rounded bg-gray-100 px-2 py-1 text-xs">{person.identity.id}</code>
|
|
67
|
+
</div>
|
|
68
|
+
{/* keyed on the loaded values: TenantForm snapshots initialValues on mount, so a refresh would otherwise show stale fields */}
|
|
69
|
+
<ChangeProfileForm
|
|
70
|
+
key={`${person.email ?? ''} ${person.name ?? ''}`}
|
|
71
|
+
personId={personId}
|
|
72
|
+
initialValues={{ email: person.email ?? '', name: person.name ?? '' }}
|
|
73
|
+
onSuccess={() => {
|
|
74
|
+
refresh()
|
|
75
|
+
showToast(<ToastContent>{dict.tenant.personDetail.profileUpdated}</ToastContent>, { type: 'success' })
|
|
76
|
+
}}
|
|
77
|
+
>
|
|
78
|
+
<form className="grid gap-4">
|
|
79
|
+
<ChangeProfileFormFields />
|
|
80
|
+
</form>
|
|
81
|
+
</ChangeProfileForm>
|
|
82
|
+
</Section>
|
|
83
|
+
|
|
84
|
+
<Section title={dict.tenant.personDetail.password}>
|
|
85
|
+
<ChangePasswordForm
|
|
86
|
+
personId={personId}
|
|
87
|
+
onSuccess={() => showToast(<ToastContent>{dict.tenant.personDetail.passwordUpdated}</ToastContent>, { type: 'success' })}
|
|
88
|
+
>
|
|
89
|
+
<form className="grid gap-4">
|
|
90
|
+
<SetPersonPasswordFormFields />
|
|
91
|
+
</form>
|
|
92
|
+
</ChangePasswordForm>
|
|
93
|
+
</Section>
|
|
94
|
+
|
|
95
|
+
<Section title={dict.tenant.personDetail.mfa}>
|
|
96
|
+
<div className="flex gap-4 items-center">
|
|
97
|
+
<MfaBadges otpEnabled={person.otpEnabled} emailOtpEnabled={person.emailOtpEnabled} />
|
|
98
|
+
<ResetPersonMfaAction personId={personId} onSuccess={refresh} />
|
|
99
|
+
</div>
|
|
100
|
+
</Section>
|
|
101
|
+
|
|
102
|
+
<Section title={dict.tenant.personDetail.globalRoles}>
|
|
103
|
+
<GlobalRolesControl identityId={person.identity.id} roles={person.identity.roles ?? []} onChange={refresh} />
|
|
104
|
+
</Section>
|
|
105
|
+
|
|
106
|
+
<Section title={dict.tenant.personDetail.sessions}>
|
|
107
|
+
<SessionList personId={personId} />
|
|
108
|
+
</Section>
|
|
109
|
+
|
|
110
|
+
<Section title={dict.tenant.personDetail.identityProviders}>
|
|
111
|
+
<Table>
|
|
112
|
+
<TableHeader>
|
|
113
|
+
<TableRow>
|
|
114
|
+
<TableHead>{dict.tenant.personDetail.identityProvider}</TableHead>
|
|
115
|
+
<TableHead>{dict.tenant.personDetail.identityProviderAccount}</TableHead>
|
|
116
|
+
<TableHead>{dict.tenant.personDetail.identityProviderConnectedAt}</TableHead>
|
|
117
|
+
<TableHead>{dict.tenant.personDetail.identityProviderStatus}</TableHead>
|
|
118
|
+
</TableRow>
|
|
119
|
+
</TableHeader>
|
|
120
|
+
{person.identityProviders.length === 0 && (
|
|
121
|
+
<TableRow>
|
|
122
|
+
<TableCell colSpan={4}>{dict.tenant.personDetail.noIdentityProviders}</TableCell>
|
|
123
|
+
</TableRow>
|
|
124
|
+
)}
|
|
125
|
+
{person.identityProviders.map(connection => (
|
|
126
|
+
<TableRow key={connection.id}>
|
|
127
|
+
<TableCell className="font-medium">{connection.identityProvider.slug}</TableCell>
|
|
128
|
+
<TableCell>{connection.externalIdentifier}</TableCell>
|
|
129
|
+
<TableCell className="whitespace-nowrap">{new Date(connection.createdAt).toLocaleString()}</TableCell>
|
|
130
|
+
<TableCell>
|
|
131
|
+
{connection.identityProvider.disabledAt
|
|
132
|
+
? <span className="text-destructive">{dict.tenant.personDetail.identityProviderDisabled}</span>
|
|
133
|
+
: null}
|
|
134
|
+
</TableCell>
|
|
135
|
+
</TableRow>
|
|
136
|
+
))}
|
|
137
|
+
</Table>
|
|
138
|
+
</Section>
|
|
139
|
+
</div>
|
|
140
|
+
)
|
|
141
|
+
}
|
|
@@ -3,12 +3,20 @@ import * as React from 'react'
|
|
|
3
3
|
import { TableCell } from '~/lib'
|
|
4
4
|
import { dict } from '../dict.js'
|
|
5
5
|
import { MemberList, MemberListController } from './member-list.js'
|
|
6
|
+
import { MfaBadges } from './mfa.js'
|
|
6
7
|
import { RolesConfig } from '../forms/index.js'
|
|
7
8
|
|
|
8
9
|
const filter: ProjectMembersFilter = {
|
|
9
10
|
memberType: 'PERSON',
|
|
10
11
|
}
|
|
11
|
-
export const PersonList = (
|
|
12
|
+
export const PersonList = (
|
|
13
|
+
props: {
|
|
14
|
+
controller?: { current?: MemberListController }
|
|
15
|
+
roles?: RolesConfig
|
|
16
|
+
canUpdateMember?: boolean
|
|
17
|
+
canRemoveMember?: boolean
|
|
18
|
+
},
|
|
19
|
+
) => (
|
|
12
20
|
<MemberList
|
|
13
21
|
{...props}
|
|
14
22
|
filter={filter}
|
|
@@ -17,11 +25,14 @@ export const PersonList = (props: { controller?: { current?: MemberListControlle
|
|
|
17
25
|
deleted: dict.tenant.personList.deleted,
|
|
18
26
|
deleteFailed: dict.tenant.personList.deleteFailed,
|
|
19
27
|
}}
|
|
20
|
-
tableHeaders={[dict.tenant.personList.email, dict.tenant.personList.name]}
|
|
28
|
+
tableHeaders={[dict.tenant.personList.email, dict.tenant.personList.name, dict.tenant.personsList.mfa]}
|
|
21
29
|
tableColumns={it => (
|
|
22
30
|
<>
|
|
23
31
|
<TableCell key="email">{it.identity.person?.email ?? dict.tenant.personList.noEmail}</TableCell>
|
|
24
32
|
<TableCell key="name">{it.identity.person?.name ?? dict.tenant.personList.noName}</TableCell>
|
|
33
|
+
<TableCell key="mfa">
|
|
34
|
+
<MfaBadges otpEnabled={it.identity.person?.otpEnabled} emailOtpEnabled={it.identity.person?.emailOtpEnabled} />
|
|
35
|
+
</TableCell>
|
|
25
36
|
</>
|
|
26
37
|
)}
|
|
27
38
|
/>
|