@contember/create 2.2.0-alpha.1 → 2.2.0-alpha.11
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,71 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { ReactNode } from 'react'
|
|
3
|
+
import { Loader } from '~/lib'
|
|
4
|
+
import { isForbiddenError, TenantQueryLoaderState } from '@contember/react-client-tenant'
|
|
5
|
+
import { TerminalIcon } from 'lucide-react'
|
|
6
|
+
import { dict } from '../dict.js'
|
|
7
|
+
|
|
8
|
+
export interface ConfigQueryStateProps {
|
|
9
|
+
forbiddenMessage: string
|
|
10
|
+
failedMessage: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Renders the non-data states of a configuration query, or `null` once data is
|
|
15
|
+
* available — a plain helper, not a component, so the caller can `return` it and
|
|
16
|
+
* then narrow on `'data' in query`.
|
|
17
|
+
*
|
|
18
|
+
* The read-only configuration views all share one shape: a permission-gated
|
|
19
|
+
* query that throws rather than returning an empty result, so "you may not see
|
|
20
|
+
* this" has to be rendered as an ordinary state instead of a failure.
|
|
21
|
+
*/
|
|
22
|
+
export const renderConfigQueryState = <Result,>(
|
|
23
|
+
{ query, forbiddenMessage, failedMessage }: ConfigQueryStateProps & { query: TenantQueryLoaderState<Result> },
|
|
24
|
+
): ReactNode => {
|
|
25
|
+
if (query.state === 'error') {
|
|
26
|
+
return isForbiddenError(query.error)
|
|
27
|
+
? <div className="text-gray-500 italic">{forbiddenMessage}</div>
|
|
28
|
+
: <div className="text-destructive italic">{failedMessage}</div>
|
|
29
|
+
}
|
|
30
|
+
if (!('data' in query)) {
|
|
31
|
+
return (
|
|
32
|
+
<div className="relative min-h-24">
|
|
33
|
+
<Loader position="absolute" />
|
|
34
|
+
</div>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
return null
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Points at the write path these views deliberately do not offer. */
|
|
41
|
+
export const ManagedByCliNote = () => (
|
|
42
|
+
<p className="flex items-center gap-2 text-sm text-gray-500">
|
|
43
|
+
<TerminalIcon className="w-3.5 h-3.5 shrink-0" />
|
|
44
|
+
<span>
|
|
45
|
+
{dict.tenant.configView.managedByCli} <code className="font-mono">{dict.tenant.configView.managedByCliCommand}</code>
|
|
46
|
+
</span>
|
|
47
|
+
</p>
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
export const ConfigSection = ({ title, children }: { title: string; children: ReactNode }) => (
|
|
51
|
+
<div className="flex flex-col gap-2">
|
|
52
|
+
<h3 className="text-sm font-semibold text-gray-700">{title}</h3>
|
|
53
|
+
{children}
|
|
54
|
+
</div>
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
/** Formats a config leaf value for display; `null`/`undefined` read as "not set". */
|
|
58
|
+
export const formatConfigValue = (value: unknown): string => {
|
|
59
|
+
if (value === null || value === undefined) {
|
|
60
|
+
return dict.tenant.configView.notSet
|
|
61
|
+
}
|
|
62
|
+
if (typeof value === 'boolean') {
|
|
63
|
+
return value ? dict.tenant.configView.enabled : dict.tenant.configView.disabled
|
|
64
|
+
}
|
|
65
|
+
if (Array.isArray(value)) {
|
|
66
|
+
// An empty list is a meaningful setting, not a missing one — for the panel policy it means
|
|
67
|
+
// nobody may enter — so it must not fall through to `String([])` and render as a blank cell.
|
|
68
|
+
return value.length === 0 ? dict.tenant.configView.emptyList : value.join(', ')
|
|
69
|
+
}
|
|
70
|
+
return String(value)
|
|
71
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
import { Button, Loader, Table, TableCell, TableHead, TableHeader, TableRow } from '~/lib'
|
|
4
|
+
import { useIdentityProvidersQuery, useTenantQueryLoader } from '@contember/react-client-tenant'
|
|
5
|
+
import { dict } from '../dict.js'
|
|
6
|
+
import { formatConfigValue, ManagedByCliNote, renderConfigQueryState } from './common.js'
|
|
7
|
+
|
|
8
|
+
export interface IdentityProviderListController {
|
|
9
|
+
refresh: () => void
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface IdentityProviderListProps {
|
|
13
|
+
controller?: { current?: IdentityProviderListController }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* `IdentityProviderList` shows the identity providers configured on the tenant, read-only.
|
|
18
|
+
*
|
|
19
|
+
* This is an administration view (`idp:list`), not a source for login-screen
|
|
20
|
+
* buttons — an unauthenticated visitor cannot run the query. Providers are
|
|
21
|
+
* written with `contember tenant:apply`.
|
|
22
|
+
*
|
|
23
|
+
* The configuration blob is collapsed by default and comes from
|
|
24
|
+
* `getPublicConfiguration`, which strips the client secret for the built-in
|
|
25
|
+
* handlers. A custom handler that does not implement it returns the raw stored
|
|
26
|
+
* configuration, hence the note under the table.
|
|
27
|
+
*
|
|
28
|
+
* ## Example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* <IdentityProviderList />
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export const IdentityProviderList = ({ controller }: IdentityProviderListProps) => {
|
|
34
|
+
const [query, { refresh }] = useTenantQueryLoader(useIdentityProvidersQuery(), {})
|
|
35
|
+
const [expanded, setExpanded] = useState<string | null>(null)
|
|
36
|
+
if (controller) {
|
|
37
|
+
controller.current = { refresh }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const nonData = renderConfigQueryState({
|
|
41
|
+
query,
|
|
42
|
+
forbiddenMessage: dict.tenant.identityProviderList.forbidden,
|
|
43
|
+
failedMessage: dict.tenant.identityProviderList.failedToLoadData,
|
|
44
|
+
})
|
|
45
|
+
if (nonData !== null) {
|
|
46
|
+
return nonData
|
|
47
|
+
}
|
|
48
|
+
if (!('data' in query)) {
|
|
49
|
+
return null
|
|
50
|
+
}
|
|
51
|
+
const providers = query.data
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<div className="relative flex flex-col gap-3">
|
|
55
|
+
{query.state !== 'success' && <Loader position="absolute" />}
|
|
56
|
+
<ManagedByCliNote />
|
|
57
|
+
|
|
58
|
+
<Table>
|
|
59
|
+
<TableHeader>
|
|
60
|
+
<TableRow>
|
|
61
|
+
<TableHead>{dict.tenant.identityProviderList.slug}</TableHead>
|
|
62
|
+
<TableHead>{dict.tenant.identityProviderList.type}</TableHead>
|
|
63
|
+
<TableHead>{dict.tenant.identityProviderList.status}</TableHead>
|
|
64
|
+
<TableHead>{dict.tenant.identityProviderList.autoSignUp}</TableHead>
|
|
65
|
+
<TableHead>{dict.tenant.identityProviderList.exclusive}</TableHead>
|
|
66
|
+
<TableHead>{dict.tenant.identityProviderList.configuration}</TableHead>
|
|
67
|
+
</TableRow>
|
|
68
|
+
</TableHeader>
|
|
69
|
+
{providers.length === 0 && (
|
|
70
|
+
<TableRow>
|
|
71
|
+
<TableCell colSpan={6}>{dict.tenant.identityProviderList.noResults}</TableCell>
|
|
72
|
+
</TableRow>
|
|
73
|
+
)}
|
|
74
|
+
{providers.map(provider => (
|
|
75
|
+
<React.Fragment key={provider.slug}>
|
|
76
|
+
<TableRow>
|
|
77
|
+
<TableCell className="font-medium">{provider.slug}</TableCell>
|
|
78
|
+
<TableCell className="font-mono text-xs">{provider.type}</TableCell>
|
|
79
|
+
<TableCell>
|
|
80
|
+
{provider.disabledAt
|
|
81
|
+
? <span className="text-destructive">{dict.tenant.configView.disabled}</span>
|
|
82
|
+
: <span>{dict.tenant.configView.enabled}</span>}
|
|
83
|
+
</TableCell>
|
|
84
|
+
<TableCell>{formatConfigValue(provider.options.autoSignUp)}</TableCell>
|
|
85
|
+
<TableCell>{formatConfigValue(provider.options.exclusive)}</TableCell>
|
|
86
|
+
<TableCell>
|
|
87
|
+
<Button
|
|
88
|
+
variant="outline"
|
|
89
|
+
size="sm"
|
|
90
|
+
onClick={() => setExpanded(expanded === provider.slug ? null : provider.slug)}
|
|
91
|
+
>
|
|
92
|
+
{expanded === provider.slug
|
|
93
|
+
? dict.tenant.identityProviderList.hideConfiguration
|
|
94
|
+
: dict.tenant.identityProviderList.showConfiguration}
|
|
95
|
+
</Button>
|
|
96
|
+
</TableCell>
|
|
97
|
+
</TableRow>
|
|
98
|
+
{expanded === provider.slug && (
|
|
99
|
+
<TableRow>
|
|
100
|
+
<TableCell colSpan={6}>
|
|
101
|
+
<pre className="overflow-x-auto text-xs bg-gray-50 p-3 rounded">
|
|
102
|
+
{JSON.stringify(provider.configuration, null, 2)}
|
|
103
|
+
</pre>
|
|
104
|
+
</TableCell>
|
|
105
|
+
</TableRow>
|
|
106
|
+
)}
|
|
107
|
+
</React.Fragment>
|
|
108
|
+
))}
|
|
109
|
+
</Table>
|
|
110
|
+
<p className="text-sm text-gray-500">{dict.tenant.identityProviderList.secretsNote}</p>
|
|
111
|
+
</div>
|
|
112
|
+
)
|
|
113
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
import { Button, Loader, Table, TableCell, TableHead, TableHeader, TableRow } from '~/lib'
|
|
4
|
+
import { useMailTemplatesQuery, useTenantQueryLoader } from '@contember/react-client-tenant'
|
|
5
|
+
import { dict } from '../dict.js'
|
|
6
|
+
import { formatConfigValue, ManagedByCliNote, renderConfigQueryState } from './common.js'
|
|
7
|
+
|
|
8
|
+
export interface MailTemplateListController {
|
|
9
|
+
refresh: () => void
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface MailTemplateListProps {
|
|
13
|
+
controller?: { current?: MailTemplateListController }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Templates have no id; type + variant + project is what identifies one server-side. */
|
|
17
|
+
const templateKey = (template: { type: string; variant?: string | null; projectSlug?: string | null }) =>
|
|
18
|
+
`${template.projectSlug ?? ''}/${template.type}/${template.variant ?? ''}`
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* `MailTemplateList` shows the configured mail templates read-only, with the body
|
|
22
|
+
* collapsed behind a toggle.
|
|
23
|
+
*
|
|
24
|
+
* Templates are written with `contember tenant:apply`; reading them requires
|
|
25
|
+
* `mailTemplate:list`. A type missing from this list is not broken — it means the
|
|
26
|
+
* built-in default is in use.
|
|
27
|
+
*
|
|
28
|
+
* ## Example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* <MailTemplateList />
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export const MailTemplateList = ({ controller }: MailTemplateListProps) => {
|
|
34
|
+
const [query, { refresh }] = useTenantQueryLoader(useMailTemplatesQuery(), {})
|
|
35
|
+
const [expanded, setExpanded] = useState<string | null>(null)
|
|
36
|
+
if (controller) {
|
|
37
|
+
controller.current = { refresh }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const nonData = renderConfigQueryState({
|
|
41
|
+
query,
|
|
42
|
+
forbiddenMessage: dict.tenant.mailTemplateList.forbidden,
|
|
43
|
+
failedMessage: dict.tenant.mailTemplateList.failedToLoadData,
|
|
44
|
+
})
|
|
45
|
+
if (nonData !== null) {
|
|
46
|
+
return nonData
|
|
47
|
+
}
|
|
48
|
+
if (!('data' in query)) {
|
|
49
|
+
return null
|
|
50
|
+
}
|
|
51
|
+
const templates = query.data
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<div className="relative flex flex-col gap-3">
|
|
55
|
+
{query.state !== 'success' && <Loader position="absolute" />}
|
|
56
|
+
<ManagedByCliNote />
|
|
57
|
+
|
|
58
|
+
{templates.length === 0
|
|
59
|
+
? <div className="text-gray-500 italic">{dict.tenant.mailTemplateList.noResults}</div>
|
|
60
|
+
: (
|
|
61
|
+
<Table>
|
|
62
|
+
<TableHeader>
|
|
63
|
+
<TableRow>
|
|
64
|
+
<TableHead>{dict.tenant.mailTemplateList.type}</TableHead>
|
|
65
|
+
<TableHead>{dict.tenant.mailTemplateList.variant}</TableHead>
|
|
66
|
+
<TableHead>{dict.tenant.mailTemplateList.project}</TableHead>
|
|
67
|
+
<TableHead>{dict.tenant.mailTemplateList.subject}</TableHead>
|
|
68
|
+
<TableHead>{dict.tenant.mailTemplateList.replyTo}</TableHead>
|
|
69
|
+
<TableHead>{dict.tenant.mailTemplateList.useLayout}</TableHead>
|
|
70
|
+
<TableHead />
|
|
71
|
+
</TableRow>
|
|
72
|
+
</TableHeader>
|
|
73
|
+
{templates.map(template => {
|
|
74
|
+
const key = templateKey(template)
|
|
75
|
+
return (
|
|
76
|
+
<React.Fragment key={key}>
|
|
77
|
+
<TableRow>
|
|
78
|
+
<TableCell className="font-mono text-xs">{template.type}</TableCell>
|
|
79
|
+
<TableCell>{template.variant || '—'}</TableCell>
|
|
80
|
+
<TableCell>{template.projectSlug ?? '—'}</TableCell>
|
|
81
|
+
<TableCell className="font-medium">{template.subject}</TableCell>
|
|
82
|
+
<TableCell>{template.replyTo ?? '—'}</TableCell>
|
|
83
|
+
<TableCell>{formatConfigValue(template.useLayout)}</TableCell>
|
|
84
|
+
<TableCell>
|
|
85
|
+
<Button variant="outline" size="sm" onClick={() => setExpanded(expanded === key ? null : key)}>
|
|
86
|
+
{expanded === key
|
|
87
|
+
? dict.tenant.mailTemplateList.hideContent
|
|
88
|
+
: dict.tenant.mailTemplateList.showContent}
|
|
89
|
+
</Button>
|
|
90
|
+
</TableCell>
|
|
91
|
+
</TableRow>
|
|
92
|
+
{expanded === key && (
|
|
93
|
+
<TableRow>
|
|
94
|
+
<TableCell colSpan={7}>
|
|
95
|
+
<pre className="overflow-x-auto whitespace-pre-wrap text-xs bg-gray-50 p-3 rounded">
|
|
96
|
+
{template.content}
|
|
97
|
+
</pre>
|
|
98
|
+
</TableCell>
|
|
99
|
+
</TableRow>
|
|
100
|
+
)}
|
|
101
|
+
</React.Fragment>
|
|
102
|
+
)
|
|
103
|
+
})}
|
|
104
|
+
</Table>
|
|
105
|
+
)}
|
|
106
|
+
</div>
|
|
107
|
+
)
|
|
108
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { ReactNode } from 'react'
|
|
3
|
+
import { Loader, Table, TableCell, TableHead, TableHeader, TableRow } from '~/lib'
|
|
4
|
+
import { useConfigurationQuery, useTenantQueryLoader } from '@contember/react-client-tenant'
|
|
5
|
+
import { dict } from '../dict.js'
|
|
6
|
+
import { ConfigSection, formatConfigValue, ManagedByCliNote, renderConfigQueryState } from './common.js'
|
|
7
|
+
|
|
8
|
+
export interface TenantConfigViewController {
|
|
9
|
+
refresh: () => void
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface TenantConfigViewProps {
|
|
13
|
+
controller?: { current?: TenantConfigViewController }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Listed explicitly rather than via Object.entries so the order is stable and a
|
|
17
|
+
// non-window field added to ConfigRateLimits cannot leak into the table.
|
|
18
|
+
const rateLimitKeys = [
|
|
19
|
+
'signUpPerIp',
|
|
20
|
+
'loginPerIp',
|
|
21
|
+
'passwordResetPerIp',
|
|
22
|
+
'passwordlessInitPerIp',
|
|
23
|
+
'emailOtpPerPerson',
|
|
24
|
+
'emailVerificationPerIp',
|
|
25
|
+
] as const
|
|
26
|
+
|
|
27
|
+
const SettingsTable = ({ rows }: { rows: readonly (readonly [string, ReactNode])[] }) => (
|
|
28
|
+
<Table>
|
|
29
|
+
<TableHeader>
|
|
30
|
+
<TableRow>
|
|
31
|
+
<TableHead className="w-1/2">{dict.tenant.configView.setting}</TableHead>
|
|
32
|
+
<TableHead>{dict.tenant.configView.value}</TableHead>
|
|
33
|
+
</TableRow>
|
|
34
|
+
</TableHeader>
|
|
35
|
+
{rows.map(([label, value]) => (
|
|
36
|
+
<TableRow key={label}>
|
|
37
|
+
<TableCell className="font-medium">{label}</TableCell>
|
|
38
|
+
<TableCell>{value}</TableCell>
|
|
39
|
+
</TableRow>
|
|
40
|
+
))}
|
|
41
|
+
</Table>
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* `TenantConfigView` shows the tenant-wide configuration read-only. There is no
|
|
46
|
+
* editing counterpart on purpose — the write path is `contember tenant:apply`.
|
|
47
|
+
*
|
|
48
|
+
* Requires `system:viewConfig` (the read counterpart of `system:configure`). A
|
|
49
|
+
* caller without it gets a "no permission" message rather than an error, because
|
|
50
|
+
* the resolver rejects instead of returning defaults.
|
|
51
|
+
*
|
|
52
|
+
* ## Example
|
|
53
|
+
* ```tsx
|
|
54
|
+
* <TenantConfigView />
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export const TenantConfigView = ({ controller }: TenantConfigViewProps) => {
|
|
58
|
+
const [query, { refresh }] = useTenantQueryLoader(useConfigurationQuery(), {})
|
|
59
|
+
if (controller) {
|
|
60
|
+
controller.current = { refresh }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const nonData = renderConfigQueryState({
|
|
64
|
+
query,
|
|
65
|
+
forbiddenMessage: dict.tenant.configView.forbidden,
|
|
66
|
+
failedMessage: dict.tenant.configView.failedToLoadData,
|
|
67
|
+
})
|
|
68
|
+
if (nonData !== null) {
|
|
69
|
+
return nonData
|
|
70
|
+
}
|
|
71
|
+
if (!('data' in query)) {
|
|
72
|
+
return null
|
|
73
|
+
}
|
|
74
|
+
const config = query.data
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<div className="relative flex flex-col gap-6">
|
|
78
|
+
{query.state !== 'success' && <Loader position="absolute" />}
|
|
79
|
+
<ManagedByCliNote />
|
|
80
|
+
|
|
81
|
+
<ConfigSection title={dict.tenant.configView.panelAccess}>
|
|
82
|
+
<SettingsTable
|
|
83
|
+
rows={[
|
|
84
|
+
['globalRoles', formatConfigValue(config.panel.globalRoles)],
|
|
85
|
+
['projectRoles', formatConfigValue(config.panel.projectRoles)],
|
|
86
|
+
]}
|
|
87
|
+
/>
|
|
88
|
+
</ConfigSection>
|
|
89
|
+
|
|
90
|
+
<ConfigSection title={dict.tenant.configView.signup}>
|
|
91
|
+
<SettingsTable rows={[['requireEmailVerification', formatConfigValue(config.signup.requireEmailVerification)]]} />
|
|
92
|
+
</ConfigSection>
|
|
93
|
+
|
|
94
|
+
<ConfigSection title={dict.tenant.configView.emailChange}>
|
|
95
|
+
<SettingsTable rows={[['requireVerification', formatConfigValue(config.emailChange.requireVerification)]]} />
|
|
96
|
+
</ConfigSection>
|
|
97
|
+
|
|
98
|
+
<ConfigSection title={dict.tenant.configView.password}>
|
|
99
|
+
<SettingsTable
|
|
100
|
+
rows={[
|
|
101
|
+
['minLength', formatConfigValue(config.password.minLength)],
|
|
102
|
+
['requireUppercase', formatConfigValue(config.password.requireUppercase)],
|
|
103
|
+
['requireLowercase', formatConfigValue(config.password.requireLowercase)],
|
|
104
|
+
['requireDigit', formatConfigValue(config.password.requireDigit)],
|
|
105
|
+
['requireSpecial', formatConfigValue(config.password.requireSpecial)],
|
|
106
|
+
['pattern', formatConfigValue(config.password.pattern)],
|
|
107
|
+
['checkBlacklist', formatConfigValue(config.password.checkBlacklist)],
|
|
108
|
+
['checkHibp', formatConfigValue(config.password.checkHibp)],
|
|
109
|
+
]}
|
|
110
|
+
/>
|
|
111
|
+
</ConfigSection>
|
|
112
|
+
|
|
113
|
+
<ConfigSection title={dict.tenant.configView.passwordless}>
|
|
114
|
+
<SettingsTable
|
|
115
|
+
rows={[
|
|
116
|
+
['enabled', formatConfigValue(config.passwordless.enabled)],
|
|
117
|
+
['url', formatConfigValue(config.passwordless.url)],
|
|
118
|
+
['expiration', formatConfigValue(config.passwordless.expiration)],
|
|
119
|
+
]}
|
|
120
|
+
/>
|
|
121
|
+
</ConfigSection>
|
|
122
|
+
|
|
123
|
+
<ConfigSection title={dict.tenant.configView.login}>
|
|
124
|
+
<SettingsTable
|
|
125
|
+
rows={[
|
|
126
|
+
['baseBackoff', formatConfigValue(config.login.baseBackoff)],
|
|
127
|
+
['maxBackoff', formatConfigValue(config.login.maxBackoff)],
|
|
128
|
+
['attemptWindow', formatConfigValue(config.login.attemptWindow)],
|
|
129
|
+
['revealUserExists', formatConfigValue(config.login.revealUserExists)],
|
|
130
|
+
['revealLoginMethod', formatConfigValue(config.login.revealLoginMethod)],
|
|
131
|
+
['defaultTokenExpiration', formatConfigValue(config.login.defaultTokenExpiration)],
|
|
132
|
+
['maxTokenExpiration', formatConfigValue(config.login.maxTokenExpiration)],
|
|
133
|
+
['mfaGraceDuration', formatConfigValue(config.login.mfaGraceDuration)],
|
|
134
|
+
]}
|
|
135
|
+
/>
|
|
136
|
+
</ConfigSection>
|
|
137
|
+
|
|
138
|
+
<ConfigSection title={dict.tenant.configView.anomalyDetection}>
|
|
139
|
+
<SettingsTable
|
|
140
|
+
rows={[
|
|
141
|
+
['enabled', formatConfigValue(config.login.anomalyDetection.enabled)],
|
|
142
|
+
['historySize', formatConfigValue(config.login.anomalyDetection.historySize)],
|
|
143
|
+
['emailThreshold', formatConfigValue(config.login.anomalyDetection.emailThreshold)],
|
|
144
|
+
['stepUpThreshold', formatConfigValue(config.login.anomalyDetection.stepUpThreshold)],
|
|
145
|
+
]}
|
|
146
|
+
/>
|
|
147
|
+
</ConfigSection>
|
|
148
|
+
|
|
149
|
+
<ConfigSection title={dict.tenant.configView.captcha}>
|
|
150
|
+
<SettingsTable
|
|
151
|
+
rows={[
|
|
152
|
+
['provider', formatConfigValue(config.captcha.provider)],
|
|
153
|
+
['threshold', formatConfigValue(config.captcha.threshold)],
|
|
154
|
+
['protect.signUp', formatConfigValue(config.captcha.protect.signUp)],
|
|
155
|
+
['protect.passwordReset', formatConfigValue(config.captcha.protect.passwordReset)],
|
|
156
|
+
['protect.passwordlessInit', formatConfigValue(config.captcha.protect.passwordlessInit)],
|
|
157
|
+
['protect.emailVerification', formatConfigValue(config.captcha.protect.emailVerification)],
|
|
158
|
+
]}
|
|
159
|
+
/>
|
|
160
|
+
</ConfigSection>
|
|
161
|
+
|
|
162
|
+
<ConfigSection title={dict.tenant.configView.rateLimits}>
|
|
163
|
+
<Table>
|
|
164
|
+
<TableHeader>
|
|
165
|
+
<TableRow>
|
|
166
|
+
<TableHead className="w-1/2">{dict.tenant.configView.setting}</TableHead>
|
|
167
|
+
<TableHead>{dict.tenant.configView.limit}</TableHead>
|
|
168
|
+
<TableHead>{dict.tenant.configView.window}</TableHead>
|
|
169
|
+
</TableRow>
|
|
170
|
+
</TableHeader>
|
|
171
|
+
{rateLimitKeys.map(key => (
|
|
172
|
+
<TableRow key={key}>
|
|
173
|
+
<TableCell className="font-medium">{key}</TableCell>
|
|
174
|
+
<TableCell>{formatConfigValue(config.rateLimits[key].limit)}</TableCell>
|
|
175
|
+
<TableCell>{formatConfigValue(config.rateLimits[key].window)}</TableCell>
|
|
176
|
+
</TableRow>
|
|
177
|
+
))}
|
|
178
|
+
</Table>
|
|
179
|
+
</ConfigSection>
|
|
180
|
+
</div>
|
|
181
|
+
)
|
|
182
|
+
}
|