@contember/create 2.2.0-alpha.3 → 2.2.0-alpha.4
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 +443 -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,124 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { 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 { RefreshCwIcon, UnlinkIcon } from 'lucide-react'
|
|
23
|
+
import { useDisconnectMyIdentityProviderMutation, useMyIdentityProvidersQuery, useTenantQueryLoader } from '@contember/react-client-tenant'
|
|
24
|
+
import { dict } from '../dict.js'
|
|
25
|
+
|
|
26
|
+
export interface IdentityProviderConnectionsController {
|
|
27
|
+
refresh: () => void
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface IdentityProviderConnectionsProps {
|
|
31
|
+
controller?: { current?: IdentityProviderConnectionsController }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const IdentityProviderConnections = ({ controller }: IdentityProviderConnectionsProps) => {
|
|
35
|
+
const [query, { refresh }] = useTenantQueryLoader(useMyIdentityProvidersQuery(), {})
|
|
36
|
+
if (controller) {
|
|
37
|
+
controller.current = { refresh }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (query.state === 'error') {
|
|
41
|
+
return <div className="text-destructive italic">{dict.tenant.identityProviderConnections.failedToLoadData}</div>
|
|
42
|
+
}
|
|
43
|
+
return (
|
|
44
|
+
<div className="relative">
|
|
45
|
+
{query.state !== 'success' && <Loader position="absolute" />}
|
|
46
|
+
<Table>
|
|
47
|
+
<TableHeader>
|
|
48
|
+
<TableRow>
|
|
49
|
+
<TableHead>{dict.tenant.identityProviderConnections.provider}</TableHead>
|
|
50
|
+
<TableHead>{dict.tenant.identityProviderConnections.account}</TableHead>
|
|
51
|
+
<TableHead>{dict.tenant.identityProviderConnections.connectedAt}</TableHead>
|
|
52
|
+
<TableHead>{dict.tenant.identityProviderConnections.status}</TableHead>
|
|
53
|
+
<TableHead className="w-24">
|
|
54
|
+
<div className="flex gap-2 items-center">
|
|
55
|
+
<span>{dict.tenant.identityProviderConnections.action}</span>
|
|
56
|
+
<Button variant="outline" onClick={refresh} className="ml-auto" size="sm">
|
|
57
|
+
<RefreshCwIcon className="w-3 h-3" />
|
|
58
|
+
</Button>
|
|
59
|
+
</div>
|
|
60
|
+
</TableHead>
|
|
61
|
+
</TableRow>
|
|
62
|
+
</TableHeader>
|
|
63
|
+
{'data' in query && query.data.length === 0 && (
|
|
64
|
+
<TableRow>
|
|
65
|
+
<TableCell colSpan={5}>{dict.tenant.identityProviderConnections.noResults}</TableCell>
|
|
66
|
+
</TableRow>
|
|
67
|
+
)}
|
|
68
|
+
{'data' in query && query.data.map(connection => (
|
|
69
|
+
<TableRow key={connection.id}>
|
|
70
|
+
<TableCell className="font-medium">{connection.identityProvider.slug}</TableCell>
|
|
71
|
+
<TableCell>{connection.externalIdentifier}</TableCell>
|
|
72
|
+
<TableCell className="whitespace-nowrap">{new Date(connection.createdAt).toLocaleString()}</TableCell>
|
|
73
|
+
<TableCell>
|
|
74
|
+
{connection.identityProvider.disabledAt
|
|
75
|
+
? <span className="text-destructive">{dict.tenant.identityProviderConnections.disabled}</span>
|
|
76
|
+
: null}
|
|
77
|
+
</TableCell>
|
|
78
|
+
<TableCell className="whitespace-nowrap">
|
|
79
|
+
<DisconnectDialog connectionId={connection.id} onSuccess={refresh} />
|
|
80
|
+
</TableCell>
|
|
81
|
+
</TableRow>
|
|
82
|
+
))}
|
|
83
|
+
</Table>
|
|
84
|
+
</div>
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const DisconnectDialog = ({ connectionId, onSuccess }: { connectionId: string; onSuccess: () => void }) => {
|
|
89
|
+
const disconnect = useDisconnectMyIdentityProviderMutation()
|
|
90
|
+
const showToast = useShowToast()
|
|
91
|
+
const [open, setOpen] = useState(false)
|
|
92
|
+
const onConfirm = async () => {
|
|
93
|
+
const result = await disconnect({ id: connectionId })
|
|
94
|
+
setOpen(false)
|
|
95
|
+
if (result.ok) {
|
|
96
|
+
showToast(<ToastContent>{dict.tenant.identityProviderConnections.disconnected}</ToastContent>, { type: 'success' })
|
|
97
|
+
onSuccess()
|
|
98
|
+
} else {
|
|
99
|
+
const message = dict.tenant.identityProviderConnections.errorMessages[result.error]
|
|
100
|
+
?? dict.tenant.identityProviderConnections.errorMessages.UNKNOWN_ERROR
|
|
101
|
+
showToast(<ToastContent>{message}</ToastContent>, { type: 'error' })
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return (
|
|
105
|
+
<AlertDialog open={open} onOpenChange={setOpen}>
|
|
106
|
+
<AlertDialogTrigger asChild>
|
|
107
|
+
<Button variant="destructive">
|
|
108
|
+
<UnlinkIcon className="w-3 h-3" />
|
|
109
|
+
</Button>
|
|
110
|
+
</AlertDialogTrigger>
|
|
111
|
+
<AlertDialogContent>
|
|
112
|
+
<AlertDialogHeader>
|
|
113
|
+
<AlertDialogTitle>{dict.tenant.identityProviderConnections.disconnectConfirmation}</AlertDialogTitle>
|
|
114
|
+
</AlertDialogHeader>
|
|
115
|
+
<AlertDialogFooter>
|
|
116
|
+
<AlertDialogCancel>{dict.tenant.identityProviderConnections.cancel}</AlertDialogCancel>
|
|
117
|
+
<AlertDialogAction asChild>
|
|
118
|
+
<Button variant="destructive" onClick={onConfirm}>{dict.tenant.identityProviderConnections.disconnect}</Button>
|
|
119
|
+
</AlertDialogAction>
|
|
120
|
+
</AlertDialogFooter>
|
|
121
|
+
</AlertDialogContent>
|
|
122
|
+
</AlertDialog>
|
|
123
|
+
)
|
|
124
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './identity-provider-connections.js'
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
// re-exported under a prefixed name: `react-ui-lib-base` also exports a `dict`, and `react-ui-lib` star-exports both
|
|
2
|
+
export { dict as tenantDict } from './dict.js'
|
|
3
|
+
export * from './config/index.js'
|
|
4
|
+
export * from './errors.js'
|
|
1
5
|
export * from './forms/index.js'
|
|
6
|
+
export * from './hooks/index.js'
|
|
7
|
+
export * from './idp/index.js'
|
|
2
8
|
export * from './listing/index.js'
|
|
3
9
|
export * from './otp/index.js'
|
|
10
|
+
export * from './security/index.js'
|
|
@@ -1,27 +1,165 @@
|
|
|
1
|
-
import { ProjectMembersFilter } from '@contember/graphql-client-tenant'
|
|
2
1
|
import * as React from 'react'
|
|
3
|
-
import {
|
|
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 {
|
|
24
|
+
ProjectApiKeysQueryResult,
|
|
25
|
+
toFormErrorCode,
|
|
26
|
+
useDisableApiKeyMutation,
|
|
27
|
+
useProjectApiKeysQuery,
|
|
28
|
+
useTenantQueryLoader,
|
|
29
|
+
} from '@contember/react-client-tenant'
|
|
30
|
+
import { useProjectSlug } from '@contember/react-client'
|
|
4
31
|
import { dict } from '../dict.js'
|
|
5
|
-
import {
|
|
32
|
+
import { actionErrorMessage } from '../errors.js'
|
|
6
33
|
|
|
7
|
-
const
|
|
8
|
-
|
|
34
|
+
const formatDateTime = (value?: string | null): ReactNode => {
|
|
35
|
+
if (!value) {
|
|
36
|
+
return <span className="text-gray-400 italic">{dict.tenant.apiKeyList.never}</span>
|
|
37
|
+
}
|
|
38
|
+
return new Date(value).toLocaleString()
|
|
9
39
|
}
|
|
10
40
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
41
|
+
const projectRoles = (apiKey: ProjectApiKeysQueryResult[number], projectSlug: string): string[] =>
|
|
42
|
+
apiKey.identity.projects
|
|
43
|
+
.filter(it => it.project.slug === projectSlug)
|
|
44
|
+
.flatMap(it => it.memberships.map(membership => membership.role))
|
|
45
|
+
|
|
46
|
+
export interface ApiKeyListController {
|
|
47
|
+
refresh: () => void
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface ApiKeyListProps {
|
|
51
|
+
controller?: { current?: ApiKeyListController }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const ApiKeyList = ({ controller }: ApiKeyListProps) => {
|
|
55
|
+
const projectSlug = useProjectSlug()!
|
|
56
|
+
const [query, { refresh }] = useTenantQueryLoader(useProjectApiKeysQuery(), { projectSlug })
|
|
57
|
+
if (controller) {
|
|
58
|
+
controller.current = { refresh }
|
|
59
|
+
}
|
|
60
|
+
const showToast = useShowToast()
|
|
61
|
+
|
|
62
|
+
const onDisabled = () => {
|
|
63
|
+
refresh()
|
|
64
|
+
showToast(<ToastContent>{dict.tenant.apiKeyList.disableSuccess}</ToastContent>, { type: 'success' })
|
|
65
|
+
}
|
|
66
|
+
const onDisableError = (code: string) => {
|
|
67
|
+
showToast(<ToastContent>{actionErrorMessage(code, dict.tenant.apiKeyList.disableFailed)}</ToastContent>, { type: 'error' })
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (query.state === 'error') {
|
|
71
|
+
return <div className="text-destructive italic">{dict.tenant.apiKeyList.failedToLoadData}</div>
|
|
72
|
+
}
|
|
73
|
+
return (
|
|
74
|
+
<div className="relative">
|
|
75
|
+
{query.state !== 'success' && <Loader position="absolute" />}
|
|
76
|
+
<Table>
|
|
77
|
+
<TableHeader>
|
|
78
|
+
<TableRow>
|
|
79
|
+
<TableHead>{dict.tenant.apiKeyList.description}</TableHead>
|
|
80
|
+
<TableHead>{dict.tenant.apiKeyList.type}</TableHead>
|
|
81
|
+
<TableHead>{dict.tenant.apiKeyList.roles}</TableHead>
|
|
82
|
+
<TableHead>{dict.tenant.apiKeyList.status}</TableHead>
|
|
83
|
+
<TableHead>{dict.tenant.apiKeyList.created}</TableHead>
|
|
84
|
+
<TableHead>{dict.tenant.apiKeyList.lastUsed}</TableHead>
|
|
85
|
+
<TableHead>{dict.tenant.apiKeyList.expires}</TableHead>
|
|
86
|
+
<TableHead className="w-24">
|
|
87
|
+
<div className="flex gap-2 items-center">
|
|
88
|
+
<span>{dict.tenant.apiKeyList.action}</span>
|
|
89
|
+
<Button variant="outline" onClick={refresh} className="ml-auto" size="sm">
|
|
90
|
+
<RefreshCwIcon className="w-3 h-3" />
|
|
91
|
+
</Button>
|
|
92
|
+
</div>
|
|
93
|
+
</TableHead>
|
|
94
|
+
</TableRow>
|
|
95
|
+
</TableHeader>
|
|
96
|
+
{'data' in query && query.data.length === 0 && (
|
|
97
|
+
<TableRow>
|
|
98
|
+
<TableCell colSpan={8}>{dict.tenant.apiKeyList.noResults}</TableCell>
|
|
99
|
+
</TableRow>
|
|
100
|
+
)}
|
|
101
|
+
{'data' in query && query.data.map(apiKey => {
|
|
102
|
+
const roles = projectRoles(apiKey, projectSlug)
|
|
103
|
+
return (
|
|
104
|
+
<TableRow key={apiKey.id}>
|
|
105
|
+
<TableCell>{apiKey.description ?? apiKey.identity.description ?? dict.tenant.apiKeyList.unnamed}</TableCell>
|
|
106
|
+
<TableCell>{apiKey.type ?? dict.tenant.apiKeyList.unknownType}</TableCell>
|
|
107
|
+
<TableCell>{roles.length ? roles.join(', ') : dict.tenant.apiKeyList.noRoles}</TableCell>
|
|
108
|
+
<TableCell>
|
|
109
|
+
{apiKey.enabled === false
|
|
110
|
+
? <span className="text-destructive">{dict.tenant.apiKeyList.disabled}</span>
|
|
111
|
+
: dict.tenant.apiKeyList.enabled}
|
|
112
|
+
</TableCell>
|
|
113
|
+
<TableCell className="whitespace-nowrap">{formatDateTime(apiKey.createdAt)}</TableCell>
|
|
114
|
+
<TableCell className="whitespace-nowrap">{formatDateTime(apiKey.lastUsedAt)}</TableCell>
|
|
115
|
+
<TableCell className="whitespace-nowrap">{formatDateTime(apiKey.expiresAt)}</TableCell>
|
|
116
|
+
<TableCell className="whitespace-nowrap">
|
|
117
|
+
{apiKey.enabled !== false && <DisableApiKeyDialog apiKeyId={apiKey.id} onSuccess={onDisabled} onError={onDisableError} />}
|
|
118
|
+
</TableCell>
|
|
119
|
+
</TableRow>
|
|
120
|
+
)
|
|
121
|
+
})}
|
|
122
|
+
</Table>
|
|
123
|
+
</div>
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const DisableApiKeyDialog = ({ apiKeyId, onSuccess, onError }: { apiKeyId: string; onSuccess: () => void; onError: (code: string) => void }) => {
|
|
128
|
+
const disableApiKey = useDisableApiKeyMutation()
|
|
129
|
+
const [open, setOpen] = useState(false)
|
|
130
|
+
const onConfirm = async () => {
|
|
131
|
+
try {
|
|
132
|
+
const result = await disableApiKey({ id: apiKeyId })
|
|
133
|
+
setOpen(false)
|
|
134
|
+
if (result.ok) {
|
|
135
|
+
onSuccess()
|
|
136
|
+
} else {
|
|
137
|
+
onError('UNKNOWN_ERROR')
|
|
138
|
+
}
|
|
139
|
+
} catch (e) {
|
|
140
|
+
// A denied mutation throws; without this the dialog would just hang on an unhandled rejection.
|
|
141
|
+
setOpen(false)
|
|
142
|
+
onError(toFormErrorCode(e))
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return (
|
|
146
|
+
<AlertDialog open={open} onOpenChange={setOpen}>
|
|
147
|
+
<AlertDialogTrigger asChild>
|
|
148
|
+
<Button variant="destructive">
|
|
149
|
+
<BanIcon className="w-3 h-3" />
|
|
150
|
+
</Button>
|
|
151
|
+
</AlertDialogTrigger>
|
|
152
|
+
<AlertDialogContent>
|
|
153
|
+
<AlertDialogHeader>
|
|
154
|
+
<AlertDialogTitle>{dict.tenant.apiKeyList.disableConfirmation}</AlertDialogTitle>
|
|
155
|
+
</AlertDialogHeader>
|
|
156
|
+
<AlertDialogFooter>
|
|
157
|
+
<AlertDialogCancel>{dict.tenant.apiKeyList.cancel}</AlertDialogCancel>
|
|
158
|
+
<AlertDialogAction asChild>
|
|
159
|
+
<Button variant="destructive" onClick={onConfirm}>{dict.tenant.apiKeyList.disable}</Button>
|
|
160
|
+
</AlertDialogAction>
|
|
161
|
+
</AlertDialogFooter>
|
|
162
|
+
</AlertDialogContent>
|
|
163
|
+
</AlertDialog>
|
|
164
|
+
)
|
|
165
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { useMemo, useState } from 'react'
|
|
3
|
+
import {
|
|
4
|
+
Button,
|
|
5
|
+
Input,
|
|
6
|
+
Label,
|
|
7
|
+
Loader,
|
|
8
|
+
Select,
|
|
9
|
+
SelectContent,
|
|
10
|
+
SelectItem,
|
|
11
|
+
SelectTrigger,
|
|
12
|
+
SelectValue,
|
|
13
|
+
Table,
|
|
14
|
+
TableCell,
|
|
15
|
+
TableHead,
|
|
16
|
+
TableHeader,
|
|
17
|
+
TableRow,
|
|
18
|
+
} from '~/lib'
|
|
19
|
+
import { ChevronLeftIcon, ChevronRightIcon, RefreshCwIcon } from 'lucide-react'
|
|
20
|
+
import { AuthLogFilter } from '@contember/graphql-client-tenant'
|
|
21
|
+
import { isForbiddenError, useAuthLogQuery, useTenantQueryLoader } from '@contember/react-client-tenant'
|
|
22
|
+
import { dict } from '../dict.js'
|
|
23
|
+
|
|
24
|
+
const perPage = 20
|
|
25
|
+
|
|
26
|
+
type SuccessFilter = 'all' | 'ok' | 'failed'
|
|
27
|
+
|
|
28
|
+
export interface AuthLogListController {
|
|
29
|
+
refresh: () => void
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface AuthLogListProps {
|
|
33
|
+
controller?: { current?: AuthLogListController }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* `AuthLogList` renders the tenant authentication audit log with filtering and pagination.
|
|
38
|
+
*
|
|
39
|
+
* ## Example
|
|
40
|
+
* ```tsx
|
|
41
|
+
* <AuthLogList />
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export const AuthLogList = ({ controller }: AuthLogListProps) => {
|
|
45
|
+
const [page, setPage] = useState(0)
|
|
46
|
+
const [types, setTypes] = useState('')
|
|
47
|
+
const [success, setSuccess] = useState<SuccessFilter>('all')
|
|
48
|
+
const [person, setPerson] = useState('')
|
|
49
|
+
|
|
50
|
+
// `useTenantQueryLoader` compares its variables shallowly, so the nested filter has to keep its identity.
|
|
51
|
+
const filter = useMemo((): AuthLogFilter => {
|
|
52
|
+
// There is no enum of `auth_log_type` values in the API, so types are entered as a free-text, comma separated, OR-combined list.
|
|
53
|
+
const typeList = types.split(',').map(it => it.trim()).filter(Boolean)
|
|
54
|
+
return {
|
|
55
|
+
types: typeList.length ? typeList : undefined,
|
|
56
|
+
success: success === 'all' ? undefined : success === 'ok',
|
|
57
|
+
personInputIdentifier: person.trim() || undefined,
|
|
58
|
+
}
|
|
59
|
+
}, [types, success, person])
|
|
60
|
+
|
|
61
|
+
const [query, { refresh }] = useTenantQueryLoader(useAuthLogQuery(), {
|
|
62
|
+
filter,
|
|
63
|
+
offset: page * perPage,
|
|
64
|
+
limit: perPage,
|
|
65
|
+
})
|
|
66
|
+
if (controller) {
|
|
67
|
+
controller.current = { refresh }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<div className="relative flex flex-col gap-4">
|
|
72
|
+
<div className="flex flex-col gap-4 sm:flex-row sm:items-end">
|
|
73
|
+
<div className="flex flex-col gap-2 grow">
|
|
74
|
+
<Label htmlFor="auth-log-types">{dict.tenant.authLog.filterTypes}</Label>
|
|
75
|
+
<Input
|
|
76
|
+
id="auth-log-types"
|
|
77
|
+
type="text"
|
|
78
|
+
value={types}
|
|
79
|
+
placeholder={dict.tenant.authLog.filterTypesPlaceholder}
|
|
80
|
+
onChange={e => {
|
|
81
|
+
setPage(0)
|
|
82
|
+
setTypes(e.target.value)
|
|
83
|
+
}}
|
|
84
|
+
/>
|
|
85
|
+
</div>
|
|
86
|
+
<div className="flex flex-col gap-2 grow">
|
|
87
|
+
<Label htmlFor="auth-log-person">{dict.tenant.authLog.filterPerson}</Label>
|
|
88
|
+
<Input
|
|
89
|
+
id="auth-log-person"
|
|
90
|
+
type="text"
|
|
91
|
+
value={person}
|
|
92
|
+
placeholder={dict.tenant.authLog.filterPersonPlaceholder}
|
|
93
|
+
onChange={e => {
|
|
94
|
+
setPage(0)
|
|
95
|
+
setPerson(e.target.value)
|
|
96
|
+
}}
|
|
97
|
+
/>
|
|
98
|
+
</div>
|
|
99
|
+
<div className="flex flex-col gap-2 sm:w-48">
|
|
100
|
+
<Label htmlFor="auth-log-success">{dict.tenant.authLog.filterSuccess}</Label>
|
|
101
|
+
<Select
|
|
102
|
+
value={success}
|
|
103
|
+
onValueChange={value => {
|
|
104
|
+
setPage(0)
|
|
105
|
+
setSuccess(value === 'ok' || value === 'failed' ? value : 'all')
|
|
106
|
+
}}
|
|
107
|
+
>
|
|
108
|
+
<SelectTrigger id="auth-log-success">
|
|
109
|
+
<SelectValue />
|
|
110
|
+
</SelectTrigger>
|
|
111
|
+
<SelectContent>
|
|
112
|
+
<SelectItem value="all">{dict.tenant.authLog.filterSuccessAll}</SelectItem>
|
|
113
|
+
<SelectItem value="ok">{dict.tenant.authLog.filterSuccessOk}</SelectItem>
|
|
114
|
+
<SelectItem value="failed">{dict.tenant.authLog.filterSuccessFailed}</SelectItem>
|
|
115
|
+
</SelectContent>
|
|
116
|
+
</Select>
|
|
117
|
+
</div>
|
|
118
|
+
</div>
|
|
119
|
+
{/* `authLog` rejects rather than answering an empty page, so "not yours to see" is an ordinary state here. */}
|
|
120
|
+
{query.state === 'error'
|
|
121
|
+
? isForbiddenError(query.error)
|
|
122
|
+
? <div className="text-gray-500 italic">{dict.tenant.authLog.forbidden}</div>
|
|
123
|
+
: <div className="text-destructive italic">{dict.tenant.authLog.failedToLoadData}</div>
|
|
124
|
+
: (
|
|
125
|
+
<div className="relative">
|
|
126
|
+
{query.state !== 'success' && <Loader position="absolute" />}
|
|
127
|
+
<Table>
|
|
128
|
+
<TableHeader>
|
|
129
|
+
<TableRow>
|
|
130
|
+
<TableHead>{dict.tenant.authLog.createdAt}</TableHead>
|
|
131
|
+
<TableHead>{dict.tenant.authLog.type}</TableHead>
|
|
132
|
+
<TableHead>{dict.tenant.authLog.success}</TableHead>
|
|
133
|
+
<TableHead>{dict.tenant.authLog.person}</TableHead>
|
|
134
|
+
<TableHead>{dict.tenant.authLog.ipAddress}</TableHead>
|
|
135
|
+
<TableHead className="w-40">
|
|
136
|
+
<div className="flex gap-2 items-center">
|
|
137
|
+
<span>{dict.tenant.authLog.errorCode}</span>
|
|
138
|
+
<Button variant="outline" onClick={refresh} className="ml-auto" size="sm">
|
|
139
|
+
<RefreshCwIcon className="w-3 h-3" />
|
|
140
|
+
</Button>
|
|
141
|
+
</div>
|
|
142
|
+
</TableHead>
|
|
143
|
+
</TableRow>
|
|
144
|
+
</TableHeader>
|
|
145
|
+
{'data' in query && query.data.entries.length === 0 && (
|
|
146
|
+
<TableRow>
|
|
147
|
+
<TableCell colSpan={6}>{dict.tenant.authLog.noResults}</TableCell>
|
|
148
|
+
</TableRow>
|
|
149
|
+
)}
|
|
150
|
+
{'data' in query && query.data.entries.map(entry => (
|
|
151
|
+
<TableRow key={entry.id}>
|
|
152
|
+
<TableCell className="whitespace-nowrap">{new Date(entry.createdAt).toLocaleString()}</TableCell>
|
|
153
|
+
<TableCell className="font-mono text-xs">{entry.type}</TableCell>
|
|
154
|
+
<TableCell>
|
|
155
|
+
{entry.success
|
|
156
|
+
? dict.tenant.authLog.ok
|
|
157
|
+
: <span className="text-destructive">{dict.tenant.authLog.failed}</span>}
|
|
158
|
+
</TableCell>
|
|
159
|
+
<TableCell>{entry.personInputIdentifier}</TableCell>
|
|
160
|
+
<TableCell className="whitespace-nowrap">{entry.ipAddress}</TableCell>
|
|
161
|
+
<TableCell className="font-mono text-xs" title={entry.errorMessage}>{entry.errorCode}</TableCell>
|
|
162
|
+
</TableRow>
|
|
163
|
+
))}
|
|
164
|
+
</Table>
|
|
165
|
+
<div className="flex gap-2 mt-4 justify-between">
|
|
166
|
+
<Button variant="outline" disabled={page === 0} onClick={() => setPage(page - 1)}>
|
|
167
|
+
<ChevronLeftIcon className="w-4 h-4" />
|
|
168
|
+
<span className="sr-only">{dict.tenant.authLog.previous}</span>
|
|
169
|
+
</Button>
|
|
170
|
+
<Button variant="outline" disabled={'data' in query && !query.data.hasMore} onClick={() => setPage(page + 1)}>
|
|
171
|
+
<ChevronRightIcon className="w-4 h-4" />
|
|
172
|
+
<span className="sr-only">{dict.tenant.authLog.next}</span>
|
|
173
|
+
</Button>
|
|
174
|
+
</div>
|
|
175
|
+
</div>
|
|
176
|
+
)}
|
|
177
|
+
</div>
|
|
178
|
+
)
|
|
179
|
+
}
|
|
@@ -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) => {
|