fix(system): keep one-time create-user passwords and copy full account details (#3039)

* fix(system): keep one-time create-user passwords from being discarded

Escape leaked to the Settings modal, and a double submit could replace a
201 reveal with an idempotent 200. Show the password in plaintext and
distinguish create vs retry via an idempotent body flag.

* i18n(system): update copy button and success message for account details

Changed the labels for the copy button and success message across multiple languages in the localization files to reflect the new terminology for copying account details instead of just passwords. This update enhances clarity for users when interacting with the Create User dialog.
main
lyingbug 2026-09-06 00:35:08 +08:00 committed by GitHub
parent dcc89d4b2d
commit 3d3bb7f6d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 753 additions and 699 deletions

View File

@ -23489,6 +23489,10 @@ const docTemplate = `{
"description": "GeneratedPassword is the plaintext password when the server\nauto-generated one. Absent when the caller supplied the password.",
"type": "string"
},
"idempotent": {
"description": "Idempotent is true when the identity already existed (HTTP 200).\nThe SPA axios interceptor discards status codes, so this flag is\nthe body-level signal that nothing was created or changed.",
"type": "boolean"
},
"user": {
"$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.UserInfo"
}

View File

@ -23482,6 +23482,10 @@
"description": "GeneratedPassword is the plaintext password when the server\nauto-generated one. Absent when the caller supplied the password.",
"type": "string"
},
"idempotent": {
"description": "Idempotent is true when the identity already existed (HTTP 200).\nThe SPA axios interceptor discards status codes, so this flag is\nthe body-level signal that nothing was created or changed.",
"type": "boolean"
},
"user": {
"$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.UserInfo"
}

View File

@ -5064,6 +5064,12 @@ definitions:
GeneratedPassword is the plaintext password when the server
auto-generated one. Absent when the caller supplied the password.
type: string
idempotent:
description: |-
Idempotent is true when the identity already existed (HTTP 200).
The SPA axios interceptor discards status codes, so this flag is
the body-level signal that nothing was created or changed.
type: boolean
user:
$ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.UserInfo'
type: object

View File

@ -398,12 +398,18 @@ export interface CreateSystemUserResponse {
* be fetched again.
*/
generated_password?: string
/**
* True on the 200 retry when the identity already existed. The shared
* axios interceptor drops HTTP status, so callers must read this flag
* instead of the status code.
*/
idempotent?: boolean
}
/**
* Provision a new local user account (SystemAdmin only).
* Backend returns the unwrapped CreateSystemUserResponse body.
* Responses 201 on success.
* 201 on create, 200 with `idempotent: true` when the identity existed.
*/
export async function createSystemUser(req: CreateSystemUserRequest): Promise<CreateSystemUserResponse> {
const response = await post('/api/v1/system/admin/users/create', req)

View File

@ -4087,8 +4087,8 @@ export default {
confirmPasswordPlaceholder: 'Enter the new password again',
confirmBtn: 'Create user',
success: 'User created',
successSuppliedPassword: 'Submitted. If this user already existed, no changes were made (including the password).',
successIdempotent: 'User already existed; no changes made',
missingPassword: 'User was created but the generated password was not returned. Reset the password to recover access.',
failed: 'Failed to create user',
validation: {
usernameRequired: 'Enter a username',
@ -4108,8 +4108,8 @@ export default {
usernameLabel: 'Username',
emailLabel: 'Email',
passwordLabel: 'Generated password',
copyBtn: 'Copy password',
copySuccess: 'Password copied to clipboard',
copyBtn: 'Copy account details',
copySuccess: 'Account details copied to clipboard',
acknowledgeBtn: 'I have saved the password'
}
},

View File

@ -2784,8 +2784,8 @@ export default {
confirmPasswordPlaceholder: '새 비밀번호를 다시 입력',
confirmBtn: '사용자 생성',
success: '사용자가 생성되었습니다',
successSuppliedPassword: '제출 완료. 이미 존재하는 사용자라면 변경된 내용이 없습니다(비밀번호 포함).',
successIdempotent: '이미 존재하는 사용자입니다. 변경 사항이 없습니다',
missingPassword: '사용자는 생성되었지만 생성된 비밀번호가 반환되지 않았습니다. 비밀번호를 재설정해 접근을 복구하세요.',
failed: '사용자 생성 실패',
validation: {
usernameRequired: '사용자 이름을 입력하세요',
@ -2805,8 +2805,8 @@ export default {
usernameLabel: '사용자 이름',
emailLabel: '이메일',
passwordLabel: '생성된 비밀번호',
copyBtn: '비밀번호 복사',
copySuccess: '비밀번호가 클립보드에 복사되었습니다',
copyBtn: '계정 정보 복사',
copySuccess: '계정 정보가 클립보드에 복사되었습니다',
acknowledgeBtn: '비밀번호를 저장했습니다'
}
},

View File

@ -2784,8 +2784,8 @@ export default {
confirmPasswordPlaceholder: 'Введите новый пароль ещё раз',
confirmBtn: 'Создать пользователя',
success: 'Пользователь создан',
successSuppliedPassword: 'Запрос отправлен. Если пользователь уже существовал, изменения не внесены (включая пароль).',
successIdempotent: 'Пользователь уже существует; изменений нет',
missingPassword: 'Пользователь создан, но сгенерированный пароль не вернулся. Сбросьте пароль, чтобы восстановить доступ.',
failed: 'Не удалось создать пользователя',
validation: {
usernameRequired: 'Введите имя пользователя',
@ -2805,8 +2805,8 @@ export default {
usernameLabel: 'Имя пользователя',
emailLabel: 'Email',
passwordLabel: 'Сгенерированный пароль',
copyBtn: 'Скопировать пароль',
copySuccess: 'Пароль скопирован в буфер обмена',
copyBtn: 'Скопировать данные аккаунта',
copySuccess: 'Данные аккаунта скопированы в буфер обмена',
acknowledgeBtn: 'Я сохранил пароль'
}
},

View File

@ -2786,8 +2786,8 @@ export default {
confirmPasswordPlaceholder: '再次输入新密码',
confirmBtn: '创建用户',
success: '用户已创建',
successSuppliedPassword: '已提交。若该用户此前已存在,则未对其做任何更改(包括密码)。',
successIdempotent: '用户已存在,未做任何更改',
missingPassword: '用户已创建,但未返回生成的密码。请使用重置密码来恢复访问。',
failed: '创建用户失败',
validation: {
usernameRequired: '请输入用户名',
@ -2807,8 +2807,8 @@ export default {
usernameLabel: '用户名',
emailLabel: '邮箱',
passwordLabel: '生成的密码',
copyBtn: '复制密码',
copySuccess: '密码已复制到剪贴板',
copyBtn: '复制账号信息',
copySuccess: '账号信息已复制到剪贴板',
acknowledgeBtn: '我已保存密码'
}
},

View File

@ -1,156 +1,115 @@
<!--
CreateUserDialog: SystemAdmin "Create user" dialog (Access settings row).
CreateUserDialog: SystemAdmin "Create user" in-place popup (Access row).
Owns the whole create-user flow: form (username + email + auto-generate
toggle revealing new/confirm password fields) and, when the server mints a
one-time password, a reveal view that must be acknowledged before the
dialog can close (overlay click, Esc, and the close button are disabled
via `locked`). The idempotent 200 OK path (no generated_password) closes
with its own success toast instead.
Anchors to the row action via the default slot, matching TenantMembers
invite and UserProfile password popups. Form (username + email +
auto-generate toggle) and, when the server mints a one-time password, a
reveal view that must be acknowledged before the popup can close. Esc is
captured on window so the parent Settings modal cannot unmount this and
discard the password. The idempotent retry path closes with its own
success toast instead.
Visibility is owned by the parent via v-model:visible. Every user-visible
message is also emitted via `announced` so the parent's sr-only live
region can relay it. The shared teleported-dialog shell comes from the
systemAdminDialog.less import in SystemSettings.vue.
region can relay it. Shared popup chrome comes from systemAdminDialog.less
(imported by SystemSettings.vue).
-->
<template>
<t-dialog
:visible="visible"
:header="createUserSuccess
? t('system.globalSettings.createUser.generated.successTitle')
: t('system.globalSettings.createUser.dialogTitle')"
width="440px"
placement="center"
dialog-class-name="create-user-dialog"
:footer="!createUserSuccess"
:confirm-btn="{
content: t('system.globalSettings.createUser.confirmBtn'),
theme: 'primary',
loading: submitting,
}"
:cancel-btn="{
content: t('system.globalSettings.confirm.cancelBtn'),
variant: 'outline',
}"
:close-on-overlay-click="!locked"
:close-btn="!locked"
:close-on-esc-keydown="!locked"
@update:visible="onVisibleChange"
@close="resetForm"
@confirm="submit"
>
<template v-if="createUserSuccess">
<t-alert
theme="success"
:message="t('system.globalSettings.createUser.generated.successBody')"
class="create-user-warning"
/>
<div class="create-user-reveal">
<div class="create-user-reveal-row">
<span class="create-user-reveal-label">
{{ t('system.globalSettings.createUser.generated.usernameLabel') }}
</span>
<span class="create-user-reveal-value">{{ createUserSuccess.username }}</span>
<t-popup :visible="visible" trigger="click" placement="left-top" :destroy-on-close="!locked"
overlay-class-name="system-admin-action-popup-overlay" @visible-change="onVisibleChange">
<span class="system-admin-action-popup-anchor">
<slot />
</span>
<template #content>
<div class="system-admin-action-popup-inner" @click.stop>
<div class="system-admin-action-popup-title">
{{ createUserSuccess
? t('system.globalSettings.createUser.generated.successTitle')
: t('system.globalSettings.createUser.dialogTitle') }}
</div>
<div class="create-user-reveal-row">
<span class="create-user-reveal-label">
{{ t('system.globalSettings.createUser.generated.emailLabel') }}
</span>
<span class="create-user-reveal-value">{{ createUserSuccess.email }}</span>
</div>
<div class="create-user-reveal-row create-user-reveal-row--password">
<span class="create-user-reveal-label">
{{ t('system.globalSettings.createUser.generated.passwordLabel') }}
</span>
<div class="create-user-reveal-password">
<t-input
v-model="createUserSuccess.generatedPassword"
readonly
type="password"
class="create-user-reveal-password-field"
/>
<t-button theme="primary" variant="outline" @click="copyGeneratedPassword">
<p class="system-admin-action-popup-hint">
{{ createUserSuccess
? t('system.globalSettings.createUser.generated.successBody')
: t('system.globalSettings.createUser.warning') }}
</p>
<template v-if="createUserSuccess">
<div class="create-user-reveal">
<div class="create-user-reveal-item">
<span class="create-user-reveal-label">
{{ t('system.globalSettings.createUser.generated.usernameLabel') }}
</span>
<span class="create-user-reveal-value">{{ createUserSuccess.username }}</span>
</div>
<div class="create-user-reveal-item">
<span class="create-user-reveal-label">
{{ t('system.globalSettings.createUser.generated.emailLabel') }}
</span>
<span class="create-user-reveal-value">{{ createUserSuccess.email }}</span>
</div>
<div class="create-user-reveal-item">
<span class="create-user-reveal-label">
{{ t('system.globalSettings.createUser.generated.passwordLabel') }}
</span>
<pre
class="create-user-reveal-value create-user-reveal-value--mono">{{ createUserSuccess.generatedPassword }}</pre>
</div>
</div>
<div class="system-admin-action-popup-footer">
<t-button theme="primary" variant="outline" @click="copyAccountDetails">
{{ t('system.globalSettings.createUser.generated.copyBtn') }}
</t-button>
<t-button theme="primary" @click="acknowledge">
{{ t('system.globalSettings.createUser.generated.acknowledgeBtn') }}
</t-button>
</div>
</div>
</div>
<div class="create-user-acknowledge">
<t-button theme="primary" block @click="acknowledge">
{{ t('system.globalSettings.createUser.generated.acknowledgeBtn') }}
</t-button>
</div>
</template>
<template v-else>
<t-alert
theme="warning"
:message="t('system.globalSettings.createUser.warning')"
class="create-user-warning"
/>
<t-form
ref="formRef"
:data="form"
:rules="rules"
label-align="top"
class="create-user-form"
>
<t-form-item :label="t('system.globalSettings.createUser.usernameLabel')" name="username">
<t-input
v-model="form.username"
type="text"
clearable
autocomplete="off"
:disabled="submitting"
:placeholder="t('system.globalSettings.createUser.usernamePlaceholder')"
/>
</t-form-item>
<t-form-item :label="t('system.globalSettings.createUser.emailLabel')" name="email">
<t-input
v-model="form.email"
type="text"
clearable
autocomplete="off"
:disabled="submitting"
:placeholder="t('system.globalSettings.createUser.emailPlaceholder')"
/>
</t-form-item>
<t-form-item name="autoGenerate">
<t-checkbox v-model="form.autoGenerate" :disabled="submitting">
{{ t('system.globalSettings.createUser.autoGenerateLabel') }}
</t-checkbox>
</t-form-item>
<template v-if="!form.autoGenerate">
<t-form-item :label="t('system.globalSettings.createUser.newPasswordLabel')" name="newPassword">
<t-input
v-model="form.newPassword"
type="password"
autocomplete="new-password"
:disabled="submitting"
:placeholder="t('system.globalSettings.createUser.newPasswordPlaceholder')"
>
<template #prefix-icon><t-icon name="lock-on" /></template>
</t-input>
</t-form-item>
<t-form-item :label="t('system.globalSettings.createUser.confirmPasswordLabel')" name="confirmPassword">
<t-input
v-model="form.confirmPassword"
type="password"
autocomplete="new-password"
:disabled="submitting"
:placeholder="t('system.globalSettings.createUser.confirmPasswordPlaceholder')"
@enter="submit"
>
<template #prefix-icon><t-icon name="lock-on" /></template>
</t-input>
</t-form-item>
</template>
</t-form>
<template v-else>
<t-form ref="formRef" :data="form" :rules="rules" label-align="top" class="system-admin-action-popup-form">
<t-form-item :label="t('system.globalSettings.createUser.usernameLabel')" name="username">
<t-input v-model="form.username" type="text" clearable autocomplete="off" :disabled="submitting"
:placeholder="t('system.globalSettings.createUser.usernamePlaceholder')" />
</t-form-item>
<t-form-item :label="t('system.globalSettings.createUser.emailLabel')" name="email">
<t-input v-model="form.email" type="text" clearable autocomplete="off" :disabled="submitting"
:placeholder="t('system.globalSettings.createUser.emailPlaceholder')" />
</t-form-item>
<t-form-item name="autoGenerate">
<t-checkbox v-model="form.autoGenerate" :disabled="submitting">
{{ t('system.globalSettings.createUser.autoGenerateLabel') }}
</t-checkbox>
</t-form-item>
<template v-if="!form.autoGenerate">
<t-form-item :label="t('system.globalSettings.createUser.newPasswordLabel')" name="newPassword">
<t-input v-model="form.newPassword" type="password" autocomplete="new-password" :disabled="submitting"
:placeholder="t('system.globalSettings.createUser.newPasswordPlaceholder')">
<template #prefix-icon><t-icon name="lock-on" /></template>
</t-input>
</t-form-item>
<t-form-item :label="t('system.globalSettings.createUser.confirmPasswordLabel')" name="confirmPassword">
<t-input v-model="form.confirmPassword" type="password" autocomplete="new-password"
:disabled="submitting" :placeholder="t('system.globalSettings.createUser.confirmPasswordPlaceholder')"
@enter="submit">
<template #prefix-icon><t-icon name="lock-on" /></template>
</t-input>
</t-form-item>
</template>
</t-form>
<div class="system-admin-action-popup-footer">
<t-button variant="outline" :disabled="submitting" @click="emit('update:visible', false)">
{{ t('system.globalSettings.confirm.cancelBtn') }}
</t-button>
<t-button theme="primary" :loading="submitting" @click="submit">
{{ t('system.globalSettings.createUser.confirmBtn') }}
</t-button>
</div>
</template>
</div>
</template>
</t-dialog>
</t-popup>
</template>
<script setup lang="ts">
import { computed, nextTick, reactive, ref, watch } from 'vue'
import { computed, nextTick, onMounted, onUnmounted, reactive, ref, watch } from 'vue'
import { MessagePlugin } from 'tdesign-vue-next'
import type { FormInstanceFunctions, FormRule } from 'tdesign-vue-next'
import { useI18n } from 'vue-i18n'
@ -158,6 +117,14 @@ import { createSystemUser, type CreateSystemUserRequest } from '@/api/system'
import { getAuthConfig } from '@/api/auth'
import { copyWithToast } from '@/utils/clipboard'
import { newPasswordRules } from '@/utils/passwordPolicy'
import {
applyCreateUserResponse,
captureLockedEscape,
formatCreateUserCredentials,
resolveCreateUserView,
shouldAcceptCreateUserSubmit,
type CreateUserReveal,
} from './createUserDialogState'
const props = defineProps<{ visible: boolean }>()
const emit = defineEmits<{
@ -168,6 +135,7 @@ const emit = defineEmits<{
const { t } = useI18n()
const submitting = ref(false)
const dismissing = ref(false)
const formRef = ref<FormInstanceFunctions>()
const form = reactive({
username: '',
@ -176,25 +144,18 @@ const form = reactive({
newPassword: '',
confirmPassword: '',
})
// Non-null switches the dialog to the reveal view; cleared on close so
// the success view survives the close animation.
const createUserSuccess = ref<{ username: string; email: string; generatedPassword: string } | null>(null)
// While submitting or showing the reveal view, the dialog can only be
// dismissed through its footer / acknowledge actions.
const createUserSuccess = ref<CreateUserReveal | null>(null)
const locked = computed(() => submitting.value || createUserSuccess.value !== null)
// Mirror SystemSettings.vue: the backend's password policy strictness is
// toggled by the complex_password setting, fetched from the auth config.
const complexPasswordEnabled = ref(false)
const loadAuthConfig = async () => {
try {
const resp = await getAuthConfig()
complexPasswordEnabled.value = !!resp.complex_password_enabled
} catch {
complexPasswordEnabled.value = false
const resp = await getAuthConfig()
complexPasswordEnabled.value = !!resp.complex_password_enabled
if (!resp.success) {
MessagePlugin.warning(t('system.globalSettings.messages.loadFailed'))
}
}
// autoGenerate hides the password fields (v-if), so they are never
// registered with the form and need no skip-guard in their rules.
const rules = computed<Record<string, FormRule[]>>(() => ({
username: [
{ required: true, message: t('system.globalSettings.createUser.validation.usernameRequired'), trigger: 'blur' },
@ -209,41 +170,69 @@ const rules = computed<Record<string, FormRule[]>>(() => ({
{ required: true, message: t('system.globalSettings.createUser.validation.confirmRequired'), trigger: 'blur' },
{
validator: (value: string) => value === form.newPassword,
message: t('auth.passwordMismatch'),
message: t('system.globalSettings.createUser.validation.passwordMismatch'),
trigger: 'blur',
},
],
}))
watch(() => props.visible, (visible) => {
if (visible) {
resetForm()
loadAuthConfig()
nextTick(() => formRef.value?.clearValidate?.())
watch(() => props.visible, async (visible) => {
if (!visible) {
createUserSuccess.value = null
dismissing.value = false
resetFormFields()
return
}
dismissing.value = false
createUserSuccess.value = null
resetFormFields()
await loadAuthConfig()
await nextTick()
formRef.value?.clearValidate?.()
})
function onVisibleChange(visible: boolean) {
if (!visible && locked.value && !dismissing.value) return
emit('update:visible', visible)
}
function resetForm() {
function onWindowEscCapture(e: KeyboardEvent) {
captureLockedEscape(props.visible, locked.value && !dismissing.value, e)
}
onMounted(() => {
window.addEventListener('keydown', onWindowEscCapture, true)
})
onUnmounted(() => {
window.removeEventListener('keydown', onWindowEscCapture, true)
})
function resetFormFields() {
form.username = ''
form.email = ''
form.autoGenerate = true
form.newPassword = ''
form.confirmPassword = ''
createUserSuccess.value = null
formRef.value?.clearValidate?.()
}
async function submit() {
if (submitting.value) return
const valid = await formRef.value?.validate?.()
if (valid !== true) return
function announce(msg: string, kind: 'success' | 'error' = 'success') {
emit('announced', msg)
if (kind === 'error') {
MessagePlugin.error(msg)
} else {
MessagePlugin.success(msg)
}
}
async function submit() {
if (!shouldAcceptCreateUserSubmit(submitting.value, createUserSuccess.value !== null)) return
submitting.value = true
try {
const valid = await formRef.value?.validate?.()
if (valid !== true) return
const payload: CreateSystemUserRequest = {
username: form.username.trim(),
email: form.email.trim(),
@ -252,109 +241,99 @@ async function submit() {
payload.password = form.newPassword
}
const response = await createSystemUser(payload)
const generated = response.generated_password ?? ''
if (generated) {
// One-time plaintext password: keep the dialog open on the reveal
// view until the admin explicitly acknowledges.
createUserSuccess.value = {
username: payload.username,
email: payload.email,
generatedPassword: generated,
}
const view = resolveCreateUserView(
response,
{ username: payload.username, email: payload.email },
form.autoGenerate,
)
const next = applyCreateUserResponse(createUserSuccess.value, view)
createUserSuccess.value = next.success
if (next.notice === 'reveal') {
emit('announced', t('system.globalSettings.createUser.success'))
} else if (!form.autoGenerate) {
// TODO: a fresh 201 create and an idempotent 200 retry return
// identical bodies (the API client drops the HTTP status), so the
// message is worded to be true for both.
const msg = t('system.globalSettings.createUser.successSuppliedPassword')
emit('announced', msg)
MessagePlugin.success(msg)
emit('update:visible', false)
} else {
// Idempotent path: identity already existed, nothing was minted.
const msg = t('system.globalSettings.createUser.successIdempotent')
emit('announced', msg)
MessagePlugin.success(msg)
} else if (next.notice === 'created') {
announce(t('system.globalSettings.createUser.success'))
} else if (next.notice === 'idempotent') {
announce(t('system.globalSettings.createUser.successIdempotent'))
} else if (next.notice === 'missingPassword') {
announce(t('system.globalSettings.createUser.missingPassword'), 'error')
}
if (next.close) {
dismissing.value = true
emit('update:visible', false)
}
} catch (err: any) {
const msg = err?.message || t('system.globalSettings.createUser.failed')
emit('announced', msg)
MessagePlugin.error(msg)
announce(msg, 'error')
} finally {
submitting.value = false
}
}
async function copyGeneratedPassword() {
async function copyAccountDetails() {
if (!createUserSuccess.value) return
await copyWithToast(
createUserSuccess.value.generatedPassword,
formatCreateUserCredentials(createUserSuccess.value, {
username: t('system.globalSettings.createUser.generated.usernameLabel'),
email: t('system.globalSettings.createUser.generated.emailLabel'),
password: t('system.globalSettings.createUser.generated.passwordLabel'),
}),
'system.globalSettings.createUser.generated.copySuccess',
)
}
function acknowledge() {
if (!createUserSuccess.value) return
dismissing.value = true
MessagePlugin.success(t('system.globalSettings.createUser.success'))
emit('update:visible', false)
}
</script>
<style lang="less">
/*
* Per-flow styles on top of the shared shell in systemAdminDialog.less
* (imported by SystemSettings.vue).
*/
.create-user-dialog {
.create-user-reveal {
display: flex;
flex-direction: column;
gap: 12px;
margin-bottom: 20px;
}
@import './systemAdminDialog.less';
.create-user-reveal-row {
display: flex;
align-items: baseline;
gap: 12px;
.create-user-reveal {
display: flex;
flex-direction: column;
gap: 0;
padding: 2px 0 0;
border: 1px solid var(--td-component-stroke);
border-radius: 8px;
background: var(--td-bg-color-page);
overflow: hidden;
}
&--password {
flex-direction: column;
align-items: stretch;
gap: 6px;
}
}
.create-user-reveal-item {
display: flex;
flex-direction: column;
gap: 4px;
padding: 10px 12px;
border-bottom: 1px solid var(--td-component-stroke);
.create-user-reveal-label {
flex-shrink: 0;
min-width: 80px;
font-size: 13px;
color: var(--td-text-color-secondary);
}
.create-user-reveal-value {
font-size: 14px;
color: var(--td-text-color-primary);
word-break: break-all;
}
.create-user-reveal-password {
display: flex;
gap: 8px;
align-items: stretch;
}
.create-user-reveal-password-field {
flex: 1;
}
.create-user-acknowledge {
display: flex;
flex-direction: column;
gap: 8px;
padding: 16px 0;
border-top: 1px solid var(--td-component-stroke);
&:last-child {
border-bottom: none;
}
}
.create-user-reveal-label {
font-size: 12px;
line-height: 16px;
color: var(--td-text-color-secondary);
}
.create-user-reveal-value {
font-size: 14px;
line-height: 20px;
color: var(--td-text-color-primary);
word-break: break-all;
}
.create-user-reveal-value--mono {
margin: 0;
font-family: var(--td-font-family-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
font-size: 12px;
line-height: 18px;
white-space: pre-wrap;
user-select: all;
}
</style>

View File

@ -36,8 +36,7 @@
<div class="section-header__titlewrap">
<h2>{{ t('system.globalSettings.title') }}</h2>
<t-popup placement="bottom-start" trigger="hover" :overlay-inner-style="{ maxWidth: '420px' }">
<button type="button" class="hint-trigger"
:aria-label="t('system.globalSettings.priorityHint.disclosure')">
<button type="button" class="hint-trigger" :aria-label="t('system.globalSettings.priorityHint.disclosure')">
<t-icon name="info-circle" size="16px" />
</button>
<template #content>
@ -72,38 +71,25 @@
<t-tab-panel value="tenant" :label="sectionTabLabel('tenant')" />
<t-tab-panel value="runtime" :label="sectionTabLabel('runtime')" />
<t-tab-panel value="security" :label="sectionTabLabel('security')" />
<t-tab-panel
v-if="hasUnknownSettings"
value="other"
:label="sectionTabLabel('other')"
/>
<t-tab-panel v-if="hasUnknownSettings" value="other" :label="sectionTabLabel('other')" />
</t-tabs>
<section class="settings-section-panel" :aria-label="activeSectionTitle">
<div
class="settings-section-intro"
:class="{ 'settings-section-intro--runtime': activeSettingsSection === 'runtime' }"
>
<div class="settings-section-intro"
:class="{ 'settings-section-intro--runtime': activeSettingsSection === 'runtime' }">
<p>{{ activeSectionDescription }}</p>
<t-tag v-if="activeSettingsSection === 'runtime'" theme="warning" variant="light" size="small">
{{ t('system.globalSettings.sections.runtime.restartHint') }}
</t-tag>
</div>
<div
v-if="activeSettingsSection === 'runtime'"
class="runtime-table-header"
aria-hidden="true"
>
<div v-if="activeSettingsSection === 'runtime'" class="runtime-table-header" aria-hidden="true">
<span>{{ t('system.globalSettings.runtimeTable.setting') }}</span>
<span>{{ t('system.globalSettings.runtimeTable.value') }}</span>
</div>
<div
class="settings-group"
:class="{ 'settings-group--runtime': activeSettingsSection === 'runtime' }"
>
<!--
<div class="settings-group" :class="{ 'settings-group--runtime': activeSettingsSection === 'runtime' }">
<!--
System-admins management. Visually identical to SSRF whitelist
(a tag-input with one entry per email). NOT a system_setting
row — it's backed by the user table via promote/revoke APIs.
@ -114,48 +100,35 @@
that can't be removed is worse than not showing it).
-->
<div v-if="activeSettingsSection === 'access'" class="setting-row setting-row--admin">
<div class="setting-info">
<div class="setting-info">
<div class="setting-label">
<span>{{ t('system.globalSettings.admins.label') }}</span>
<span>{{ t('system.globalSettings.admins.label') }}</span>
<t-tag theme="danger" variant="light" size="small" class="setting-badge">
{{ t('system.globalSettings.badgeHighRisk') }}
</t-tag>
</div>
<p class="desc">{{ t('system.globalSettings.admins.description') }}</p>
</div>
<div class="setting-control">
<div class="setting-control-row">
<t-popconfirm
v-model:visible="adminPopconfirm.visible"
:content="adminPopconfirm.content"
:theme="adminPopconfirm.theme"
:confirm-btn="adminPopconfirm.confirmBtn"
:cancel-btn="t('system.globalSettings.confirm.cancelBtn')"
:popup-props="PROGRAMMATIC_POPCONFIRM_PROPS"
placement="left"
@confirm="adminPopconfirm.finish(true)"
@cancel="adminPopconfirm.finish(false)"
@visible-change="adminPopconfirm.onVisibleChange"
>
<div class="setting-control-anchor">
<t-tag-input
v-model="adminEmails"
:placeholder="t('system.globalSettings.admins.placeholder')"
:aria-label="t('system.globalSettings.admins.label')"
:disabled="adminBusy"
class="setting-input setting-input--wide"
clearable
@change="onAdminsChange"
/>
</div>
</t-popconfirm>
<p class="desc">{{ t('system.globalSettings.admins.description') }}</p>
</div>
<div class="setting-control">
<div class="setting-control-row">
<t-popconfirm v-model:visible="adminPopconfirm.visible" :content="adminPopconfirm.content"
:theme="adminPopconfirm.theme" :confirm-btn="adminPopconfirm.confirmBtn"
:cancel-btn="t('system.globalSettings.confirm.cancelBtn')"
:popup-props="PROGRAMMATIC_POPCONFIRM_PROPS" placement="left" @confirm="adminPopconfirm.finish(true)"
@cancel="adminPopconfirm.finish(false)" @visible-change="adminPopconfirm.onVisibleChange">
<div class="setting-control-anchor">
<t-tag-input v-model="adminEmails" :placeholder="t('system.globalSettings.admins.placeholder')"
:aria-label="t('system.globalSettings.admins.label')" :disabled="adminBusy"
class="setting-input setting-input--wide" clearable @change="onAdminsChange" />
</div>
</t-popconfirm>
<div v-if="adminBusy" class="setting-save-state" role="status">
<t-loading size="small" />
<span>{{ t('system.globalSettings.saving') }}</span>
</div>
</div>
</div>
</div>
</div>
</div>
<div v-if="activeSettingsSection === 'access'" class="setting-row setting-row--password-reset">
<div class="setting-info">
@ -168,15 +141,59 @@
<p class="desc">{{ t('system.globalSettings.passwordReset.description') }}</p>
</div>
<div class="setting-control">
<t-button
theme="danger"
variant="text"
class="password-reset-trigger"
@click="openPasswordResetDialog"
>
<template #icon><t-icon name="lock-on" /></template>
{{ t('system.globalSettings.passwordReset.action') }}
</t-button>
<t-popup :visible="passwordResetVisible" trigger="click" placement="left-top" destroy-on-close
overlay-class-name="system-admin-action-popup-overlay" @visible-change="onPasswordResetVisibleChange">
<span class="system-admin-action-popup-anchor">
<t-button theme="danger" variant="text" class="password-reset-trigger">
<template #icon><t-icon name="lock-on" /></template>
{{ t('system.globalSettings.passwordReset.action') }}
</t-button>
</span>
<template #content>
<div class="system-admin-action-popup-inner" @click.stop>
<div class="system-admin-action-popup-title">
{{ t('system.globalSettings.passwordReset.dialogTitle') }}
</div>
<p class="system-admin-action-popup-hint">
{{ t('system.globalSettings.passwordReset.warning') }}
</p>
<t-form ref="passwordResetFormRef" :data="passwordResetForm" :rules="passwordResetRules"
label-align="top" class="system-admin-action-popup-form">
<t-form-item :label="t('system.globalSettings.passwordReset.emailLabel')" name="email">
<t-input v-model="passwordResetForm.email" type="text" clearable autocomplete="off"
:disabled="passwordResetSubmitting"
:placeholder="t('system.globalSettings.passwordReset.emailPlaceholder')" />
</t-form-item>
<t-form-item :label="t('system.globalSettings.passwordReset.newPasswordLabel')"
name="newPassword">
<t-input v-model="passwordResetForm.newPassword" type="password" autocomplete="new-password"
:disabled="passwordResetSubmitting"
:placeholder="t('system.globalSettings.passwordReset.newPasswordPlaceholder')">
<template #prefix-icon><t-icon name="lock-on" /></template>
</t-input>
</t-form-item>
<t-form-item :label="t('system.globalSettings.passwordReset.confirmPasswordLabel')"
name="confirmPassword">
<t-input v-model="passwordResetForm.confirmPassword" type="password" autocomplete="new-password"
:disabled="passwordResetSubmitting"
:placeholder="t('system.globalSettings.passwordReset.confirmPasswordPlaceholder')"
@enter="submitPasswordReset">
<template #prefix-icon><t-icon name="lock-on" /></template>
</t-input>
</t-form-item>
</t-form>
<div class="system-admin-action-popup-footer">
<t-button variant="outline" :disabled="passwordResetSubmitting"
@click="passwordResetVisible = false">
{{ t('system.globalSettings.confirm.cancelBtn') }}
</t-button>
<t-button theme="danger" :loading="passwordResetSubmitting" @click="submitPasswordReset">
{{ t('system.globalSettings.passwordReset.confirmBtn') }}
</t-button>
</div>
</div>
</template>
</t-popup>
</div>
</div>
@ -191,64 +208,39 @@
<p class="desc">{{ t('system.globalSettings.createUser.description') }}</p>
</div>
<div class="setting-control">
<t-button
theme="primary"
variant="text"
class="create-user-trigger"
@click="createUserVisible = true"
>
<template #icon><t-icon name="user-add" /></template>
{{ t('system.globalSettings.createUser.action') }}
</t-button>
<CreateUserDialog v-model:visible="createUserVisible" @announced="saveAnnouncement = $event">
<t-button theme="primary" variant="text" class="create-user-trigger">
<template #icon><t-icon name="user-add" /></template>
{{ t('system.globalSettings.createUser.action') }}
</t-button>
</CreateUserDialog>
</div>
</div>
<div
v-for="item in activeSectionSettings"
:key="item.key"
class="setting-row"
>
<div class="setting-info">
<div v-for="item in activeSectionSettings" :key="item.key" class="setting-row">
<div class="setting-info">
<div class="setting-label">
<span>{{ keyLabel(item.key) }}</span>
<t-tag
v-if="item.requires_restart"
theme="warning"
variant="light"
size="small"
class="setting-badge"
>{{ t('system.globalSettings.badgeRequiresRestart') }}</t-tag>
<t-tag
v-if="item.is_secret"
theme="primary"
variant="light"
size="small"
class="setting-badge"
>{{ t('system.globalSettings.badgeSecret') }}</t-tag>
<t-tag
v-if="isHighImpactKey(item.key)"
theme="danger"
variant="light"
size="small"
class="setting-badge"
>{{ t('system.globalSettings.badgeHighRisk') }}</t-tag>
<t-tag
v-if="hasOverride(item)"
theme="success"
variant="light"
size="small"
class="setting-badge"
:title="t('system.globalSettings.badgeOverrideTooltip')"
>{{ t('system.globalSettings.badgeOverride') }}</t-tag>
<span>{{ keyLabel(item.key) }}</span>
<t-tag v-if="item.requires_restart" theme="warning" variant="light" size="small"
class="setting-badge">{{
t('system.globalSettings.badgeRequiresRestart') }}</t-tag>
<t-tag v-if="item.is_secret" theme="primary" variant="light" size="small" class="setting-badge">{{
t('system.globalSettings.badgeSecret') }}</t-tag>
<t-tag v-if="isHighImpactKey(item.key)" theme="danger" variant="light" size="small"
class="setting-badge">{{
t('system.globalSettings.badgeHighRisk') }}</t-tag>
<t-tag v-if="hasOverride(item)" theme="success" variant="light" size="small" class="setting-badge"
:title="t('system.globalSettings.badgeOverrideTooltip')">{{ t('system.globalSettings.badgeOverride')
}}</t-tag>
</div>
<p v-if="settingDescription(item)" class="desc">{{ settingDescription(item) }}</p>
<div v-if="modifiedMeta(item)" class="setting-meta">
{{ t('system.globalSettings.modifiedAt', { value: modifiedMeta(item) }) }}
</div>
</div>
<p v-if="settingDescription(item)" class="desc">{{ settingDescription(item) }}</p>
<div v-if="modifiedMeta(item)" class="setting-meta">
{{ t('system.globalSettings.modifiedAt', { value: modifiedMeta(item) }) }}
</div>
</div>
<div class="setting-control">
<!--
<div class="setting-control">
<!--
Two-row layout: input + spinner on top, secondary actions
(currently just Reset) on a second row below, right-aligned
under the input. We tried inlining the reset button on the
@ -257,138 +249,75 @@
the primary control visually clean while still placing the
action close to the value it affects.
-->
<div class="setting-control-row">
<t-popconfirm
v-if="hasEnum(item) && isHighRiskKey(item.key)"
v-model:visible="highRiskPopconfirm.visible"
:content="highRiskPopconfirm.content"
:theme="highRiskPopconfirm.theme"
:confirm-btn="highRiskPopconfirm.confirmBtn"
:cancel-btn="t('system.globalSettings.confirm.cancelBtn')"
:popup-props="PROGRAMMATIC_POPCONFIRM_PROPS"
placement="left"
@confirm="highRiskPopconfirm.finish(true)"
@cancel="highRiskPopconfirm.finish(false)"
@visible-change="highRiskPopconfirm.onVisibleChange"
>
<div class="setting-control-anchor">
<t-select
v-model="editValues[item.key]"
:options="enumOptions(item)"
:aria-label="keyLabel(item.key)"
:disabled="savingKey === item.key"
class="setting-input"
@change="onHighRiskSelectChange(item)"
/>
</div>
</t-popconfirm>
<t-select
v-else-if="hasEnum(item)"
v-model="editValues[item.key]"
:options="enumOptions(item)"
:aria-label="keyLabel(item.key)"
:disabled="savingKey === item.key"
class="setting-input"
@change="onChange(item)"
/>
<t-popconfirm
v-else-if="item.value_type === 'bool' && isHighRiskKey(item.key)"
v-model:visible="highRiskPopconfirm.visible"
:content="highRiskPopconfirm.content"
:theme="highRiskPopconfirm.theme"
:confirm-btn="highRiskPopconfirm.confirmBtn"
:cancel-btn="t('system.globalSettings.confirm.cancelBtn')"
:popup-props="PROGRAMMATIC_POPCONFIRM_PROPS"
placement="left"
@confirm="highRiskPopconfirm.finish(true)"
@cancel="highRiskPopconfirm.finish(false)"
@visible-change="highRiskPopconfirm.onVisibleChange"
>
<div class="setting-control-anchor">
<t-switch
v-model="editValues[item.key]"
:aria-label="keyLabel(item.key)"
:disabled="savingKey === item.key"
@change="onHighRiskBoolChange(item)"
/>
</div>
</t-popconfirm>
<t-switch
v-else-if="item.value_type === 'bool'"
v-model="editValues[item.key]"
:aria-label="keyLabel(item.key)"
:disabled="savingKey === item.key"
@change="onChange(item)"
/>
<t-input-number
v-else-if="item.value_type === 'int'"
v-model="editValues[item.key]"
:placeholder="placeholderFor(item)"
:aria-label="keyLabel(item.key)"
:disabled="savingKey === item.key"
theme="normal"
:step="1"
:min="minimumFor(item)"
class="setting-input"
@blur="onChange(item)"
/>
<t-popconfirm
v-else-if="item.value_type === 'string_list' && item.key === 'ssrf.whitelist'"
v-model:visible="ssrfPopconfirm.visible"
:content="ssrfPopconfirm.content"
:theme="ssrfPopconfirm.theme"
:confirm-btn="ssrfPopconfirm.confirmBtn"
:cancel-btn="t('system.globalSettings.confirm.cancelBtn')"
:popup-props="PROGRAMMATIC_POPCONFIRM_PROPS"
placement="left"
@confirm="ssrfPopconfirm.finish(true)"
@cancel="ssrfPopconfirm.finish(false)"
@visible-change="ssrfPopconfirm.onVisibleChange"
>
<div class="setting-control-anchor">
<t-tag-input
:key="`ssrf-tag-${ssrfTagInputKey()}`"
:model-value="ssrfWhitelistModelValue()"
:placeholder="emptyListPlaceholder"
:aria-label="keyLabel(item.key)"
:disabled="savingKey === item.key"
class="setting-input setting-input--wide"
clearable
@update:model-value="onSsrfWhitelistModelUpdate"
/>
</div>
</t-popconfirm>
<t-input
v-else
v-model="editValues[item.key]"
:placeholder="placeholderFor(item)"
:aria-label="keyLabel(item.key)"
:disabled="savingKey === item.key"
class="setting-input"
clearable
@blur="onChange(item)"
/>
<div class="setting-control-row">
<t-popconfirm v-if="hasEnum(item) && isHighRiskKey(item.key)"
v-model:visible="highRiskPopconfirm.visible" :content="highRiskPopconfirm.content"
:theme="highRiskPopconfirm.theme" :confirm-btn="highRiskPopconfirm.confirmBtn"
:cancel-btn="t('system.globalSettings.confirm.cancelBtn')"
:popup-props="PROGRAMMATIC_POPCONFIRM_PROPS" placement="left"
@confirm="highRiskPopconfirm.finish(true)" @cancel="highRiskPopconfirm.finish(false)"
@visible-change="highRiskPopconfirm.onVisibleChange">
<div class="setting-control-anchor">
<t-select v-model="editValues[item.key]" :options="enumOptions(item)"
:aria-label="keyLabel(item.key)" :disabled="savingKey === item.key" class="setting-input"
@change="onHighRiskSelectChange(item)" />
</div>
</t-popconfirm>
<t-select v-else-if="hasEnum(item)" v-model="editValues[item.key]" :options="enumOptions(item)"
:aria-label="keyLabel(item.key)" :disabled="savingKey === item.key" class="setting-input"
@change="onChange(item)" />
<t-popconfirm v-else-if="item.value_type === 'bool' && isHighRiskKey(item.key)"
v-model:visible="highRiskPopconfirm.visible" :content="highRiskPopconfirm.content"
:theme="highRiskPopconfirm.theme" :confirm-btn="highRiskPopconfirm.confirmBtn"
:cancel-btn="t('system.globalSettings.confirm.cancelBtn')"
:popup-props="PROGRAMMATIC_POPCONFIRM_PROPS" placement="left"
@confirm="highRiskPopconfirm.finish(true)" @cancel="highRiskPopconfirm.finish(false)"
@visible-change="highRiskPopconfirm.onVisibleChange">
<div class="setting-control-anchor">
<t-switch v-model="editValues[item.key]" :aria-label="keyLabel(item.key)"
:disabled="savingKey === item.key" @change="onHighRiskBoolChange(item)" />
</div>
</t-popconfirm>
<t-switch v-else-if="item.value_type === 'bool'" v-model="editValues[item.key]"
:aria-label="keyLabel(item.key)" :disabled="savingKey === item.key" @change="onChange(item)" />
<t-input-number v-else-if="item.value_type === 'int'" v-model="editValues[item.key]"
:placeholder="placeholderFor(item)" :aria-label="keyLabel(item.key)"
:disabled="savingKey === item.key" theme="normal" :step="1" :min="minimumFor(item)"
class="setting-input" @blur="onChange(item)" />
<t-popconfirm v-else-if="item.value_type === 'string_list' && item.key === 'ssrf.whitelist'"
v-model:visible="ssrfPopconfirm.visible" :content="ssrfPopconfirm.content"
:theme="ssrfPopconfirm.theme" :confirm-btn="ssrfPopconfirm.confirmBtn"
:cancel-btn="t('system.globalSettings.confirm.cancelBtn')"
:popup-props="PROGRAMMATIC_POPCONFIRM_PROPS" placement="left" @confirm="ssrfPopconfirm.finish(true)"
@cancel="ssrfPopconfirm.finish(false)" @visible-change="ssrfPopconfirm.onVisibleChange">
<div class="setting-control-anchor">
<t-tag-input :key="`ssrf-tag-${ssrfTagInputKey()}`" :model-value="ssrfWhitelistModelValue()"
:placeholder="emptyListPlaceholder" :aria-label="keyLabel(item.key)"
:disabled="savingKey === item.key" class="setting-input setting-input--wide" clearable
@update:model-value="onSsrfWhitelistModelUpdate" />
</div>
</t-popconfirm>
<t-input v-else v-model="editValues[item.key]" :placeholder="placeholderFor(item)"
:aria-label="keyLabel(item.key)" :disabled="savingKey === item.key" class="setting-input" clearable
@blur="onChange(item)" />
<!--
<!--
Per-row saving spinner. Appears next to the control while
a PUT is in flight; the controls stay disabled (see
:disabled bindings above) so concurrent edits can't race.
-->
<div v-if="savingKey === item.key" class="setting-save-state" role="status">
<t-loading size="small" />
<span>{{ t('system.globalSettings.saving') }}</span>
<div v-if="savingKey === item.key" class="setting-save-state" role="status">
<t-loading size="small" />
<span>{{ t('system.globalSettings.saving') }}</span>
</div>
<div v-else-if="savedKey === item.key" class="setting-save-state setting-save-state--success"
role="status">
<t-icon name="check-circle-filled" />
<span>{{ t('system.globalSettings.saved') }}</span>
</div>
</div>
<div
v-else-if="savedKey === item.key"
class="setting-save-state setting-save-state--success"
role="status"
>
<t-icon name="check-circle-filled" />
<span>{{ t('system.globalSettings.saved') }}</span>
</div>
</div>
<!--
<!--
Reset-to-default lives on the row below the input, right-
aligned under it. Hidden entirely for virtual (ENV / default)
rows so the layout collapses to a single row in the common
@ -396,11 +325,8 @@
override exists, so the button only appears where it can do
something.
-->
<div
v-if="hasOverride(item) || hasBulkAction(item)"
class="setting-control-actions"
>
<!--
<div v-if="hasOverride(item) || hasBulkAction(item)" class="setting-control-actions">
<!--
Per-key bulk action. Currently only one key
(tenant.default_storage_quota_gb) carries one — clicking
writes the current setting value onto every existing
@ -411,121 +337,35 @@
when the row is dirty because applying a not-yet-saved
value would confuse "what just happened".
-->
<t-popconfirm
v-if="hasBulkAction(item)"
:content="bulkActionConfirmBody(item)"
:confirm-btn="{ content: t('system.globalSettings.bulkApply.confirmBtn'), theme: 'primary' }"
:cancel-btn="{ content: t('system.globalSettings.confirm.cancelBtn') }"
placement="left"
@confirm="runBulkAction(item)"
>
<t-button
variant="text"
size="small"
:disabled="savingKey === item.key || isDirty(item)"
:title="t('system.globalSettings.bulkApply.tooltip')"
class="setting-bulk-btn"
>
<template #icon><t-icon name="usergroup" /></template>
{{ t('system.globalSettings.bulkApply.label') }}
</t-button>
</t-popconfirm>
<t-popconfirm v-if="hasBulkAction(item)" :content="bulkActionConfirmBody(item)"
:confirm-btn="{ content: t('system.globalSettings.bulkApply.confirmBtn'), theme: 'primary' }"
:cancel-btn="{ content: t('system.globalSettings.confirm.cancelBtn') }" placement="left"
@confirm="runBulkAction(item)">
<t-button variant="text" size="small" :disabled="savingKey === item.key || isDirty(item)"
:title="t('system.globalSettings.bulkApply.tooltip')" class="setting-bulk-btn">
<template #icon><t-icon name="usergroup" /></template>
{{ t('system.globalSettings.bulkApply.label') }}
</t-button>
</t-popconfirm>
<t-popconfirm
v-if="hasOverride(item)"
:content="t('system.globalSettings.reset.confirmBody', { label: keyLabel(item.key) })"
:confirm-btn="{ content: t('system.globalSettings.reset.confirmBtn'), theme: 'warning' }"
:cancel-btn="{ content: t('system.globalSettings.confirm.cancelBtn') }"
placement="left"
@confirm="resetSetting(item)"
>
<t-button
variant="text"
size="small"
:disabled="savingKey === item.key"
:title="t('system.globalSettings.reset.tooltip')"
class="setting-reset-btn"
>
<template #icon><t-icon name="refresh" /></template>
{{ t('system.globalSettings.reset.label') }}
</t-button>
</t-popconfirm>
<t-popconfirm v-if="hasOverride(item)"
:content="t('system.globalSettings.reset.confirmBody', { label: keyLabel(item.key) })"
:confirm-btn="{ content: t('system.globalSettings.reset.confirmBtn'), theme: 'warning' }"
:cancel-btn="{ content: t('system.globalSettings.confirm.cancelBtn') }" placement="left"
@confirm="resetSetting(item)">
<t-button variant="text" size="small" :disabled="savingKey === item.key"
:title="t('system.globalSettings.reset.tooltip')" class="setting-reset-btn">
<template #icon><t-icon name="refresh" /></template>
{{ t('system.globalSettings.reset.label') }}
</t-button>
</t-popconfirm>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<div class="sr-only" role="status" aria-live="polite">{{ saveAnnouncement }}</div>
</template>
<t-dialog
v-model:visible="passwordResetVisible"
:header="t('system.globalSettings.passwordReset.dialogTitle')"
width="440px"
placement="center"
dialog-class-name="password-reset-dialog"
:confirm-btn="{
content: t('system.globalSettings.passwordReset.confirmBtn'),
theme: 'danger',
loading: passwordResetSubmitting,
}"
:cancel-btn="{
content: t('system.globalSettings.confirm.cancelBtn'),
variant: 'outline',
}"
:close-on-overlay-click="!passwordResetSubmitting"
:close-btn="!passwordResetSubmitting"
@confirm="submitPasswordReset"
@close="resetPasswordResetForm"
>
<t-alert
theme="warning"
:message="t('system.globalSettings.passwordReset.warning')"
class="password-reset-warning"
/>
<t-form
ref="passwordResetFormRef"
:data="passwordResetForm"
:rules="passwordResetRules"
label-align="top"
class="password-reset-form"
>
<t-form-item :label="t('system.globalSettings.passwordReset.emailLabel')" name="email">
<t-input
v-model="passwordResetForm.email"
type="text"
clearable
autocomplete="off"
:disabled="passwordResetSubmitting"
:placeholder="t('system.globalSettings.passwordReset.emailPlaceholder')"
/>
</t-form-item>
<t-form-item :label="t('system.globalSettings.passwordReset.newPasswordLabel')" name="newPassword">
<t-input
v-model="passwordResetForm.newPassword"
type="password"
autocomplete="new-password"
:disabled="passwordResetSubmitting"
:placeholder="t('system.globalSettings.passwordReset.newPasswordPlaceholder')"
>
<template #prefix-icon><t-icon name="lock-on" /></template>
</t-input>
</t-form-item>
<t-form-item :label="t('system.globalSettings.passwordReset.confirmPasswordLabel')" name="confirmPassword">
<t-input
v-model="passwordResetForm.confirmPassword"
type="password"
autocomplete="new-password"
:disabled="passwordResetSubmitting"
:placeholder="t('system.globalSettings.passwordReset.confirmPasswordPlaceholder')"
@enter="submitPasswordReset"
>
<template #prefix-icon><t-icon name="lock-on" /></template>
</t-input>
</t-form-item>
</t-form>
</t-dialog>
<CreateUserDialog v-model:visible="createUserVisible" @announced="saveAnnouncement = $event" />
</div>
</template>
@ -808,21 +648,25 @@ function resetPasswordResetForm() {
passwordResetFormRef.value?.clearValidate?.()
}
async function openPasswordResetDialog() {
await loadAuthConfig()
async function onPasswordResetVisibleChange(visible: boolean) {
if (!visible && passwordResetSubmitting.value) return
passwordResetVisible.value = visible
if (visible) {
await loadAuthConfig()
resetPasswordResetForm()
await nextTick()
passwordResetFormRef.value?.clearValidate?.()
return
}
resetPasswordResetForm()
passwordResetVisible.value = true
await nextTick()
passwordResetFormRef.value?.clearValidate?.()
}
async function submitPasswordReset() {
if (passwordResetSubmitting.value) return
const valid = await passwordResetFormRef.value?.validate?.()
if (valid !== true) return
passwordResetSubmitting.value = true
try {
const valid = await passwordResetFormRef.value?.validate?.()
if (valid !== true) return
await resetUserPassword({
email: passwordResetForm.email.trim(),
new_password: passwordResetForm.newPassword,
@ -839,7 +683,7 @@ async function submitPasswordReset() {
}
}
// Create-user dialog lives in CreateUserDialog.vue (same Access row);
// Create-user popup lives in CreateUserDialog.vue (same Access row);
// only its visibility is owned here.
const createUserVisible = ref(false)
@ -1463,7 +1307,7 @@ onUnmounted(() => {
color: var(--td-text-color-secondary);
list-style: disc;
li + li {
li+li {
margin-top: 4px;
}
}

View File

@ -0,0 +1,111 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import {
applyCreateUserResponse,
captureLockedEscape,
formatCreateUserCredentials,
resolveCreateUserView,
shouldAcceptCreateUserSubmit,
type CreateUserReveal,
} from './createUserDialogState.ts'
const identity = { username: 'alice', email: 'alice@example.com' }
test('reveal wins whenever the server minted a one-time password', () => {
const view = resolveCreateUserView(
{ generated_password: 'OnceOnly9', idempotent: false },
identity,
true,
)
assert.deepEqual(view, {
kind: 'reveal',
username: 'alice',
email: 'alice@example.com',
generatedPassword: 'OnceOnly9',
})
})
test('idempotent flag is the 200 retry signal when no password was minted', () => {
assert.deepEqual(
resolveCreateUserView({ idempotent: true }, identity, true),
{ kind: 'idempotent' },
)
assert.deepEqual(
resolveCreateUserView({ idempotent: true }, identity, false),
{ kind: 'idempotent' },
)
})
test('supplied-password create without the idempotent flag is a real create', () => {
assert.deepEqual(
resolveCreateUserView({}, identity, false),
{ kind: 'created' },
)
})
test('auto-generate create missing generated_password is not treated as idempotent', () => {
assert.deepEqual(
resolveCreateUserView({}, identity, true),
{ kind: 'missingPassword' },
)
})
test('a later idempotent response does not close an open reveal', () => {
const current: CreateUserReveal = {
username: 'alice',
email: 'alice@example.com',
generatedPassword: 'OnceOnly9',
}
const next = applyCreateUserResponse(current, { kind: 'idempotent' })
assert.equal(next.close, false)
assert.equal(next.notice, null)
assert.equal(next.success, current)
assert.equal(next.success?.generatedPassword, 'OnceOnly9')
})
test('applyCreateUserResponse opens reveal and keeps the dialog open', () => {
const next = applyCreateUserResponse(
null,
{
kind: 'reveal',
username: 'alice',
email: 'alice@example.com',
generatedPassword: 'OnceOnly9',
},
)
assert.equal(next.close, false)
assert.equal(next.notice, 'reveal')
assert.equal(next.success?.generatedPassword, 'OnceOnly9')
})
test('submit is rejected while validating/in-flight or while revealing', () => {
assert.equal(shouldAcceptCreateUserSubmit(false, false), true)
assert.equal(shouldAcceptCreateUserSubmit(true, false), false)
assert.equal(shouldAcceptCreateUserSubmit(false, true), false)
})
test('locked visible dialog captures Escape before Settings can unmount', () => {
let stopped = false
const event = {
key: 'Escape',
stopImmediatePropagation() {
stopped = true
},
}
assert.equal(captureLockedEscape(true, true, event), true)
assert.equal(stopped, true)
stopped = false
assert.equal(captureLockedEscape(true, false, event), false)
assert.equal(stopped, false)
assert.equal(captureLockedEscape(false, true, { key: 'Escape', stopImmediatePropagation() { stopped = true } }), false)
})
test('formats username, email and password for a single clipboard paste', () => {
const text = formatCreateUserCredentials(
{ username: 'alice', email: 'alice@example.com', generatedPassword: 'OnceOnly9' },
{ username: 'Username', email: 'Email', password: 'Password' },
)
assert.equal(text, 'Username: alice\nEmail: alice@example.com\nPassword: OnceOnly9')
})

View File

@ -0,0 +1,108 @@
/**
* Pure helpers for the SystemAdmin create-user dialog.
*
* The axios interceptor discards HTTP status, so 201 (created) and 200
* (idempotent retry) used to look identical. The backend now sets
* `idempotent` on the body; generated_password is still the signal for
* the one-time reveal view.
*/
export type CreateUserIdentity = {
username: string
email: string
}
export type CreateUserApiResponse = {
generated_password?: string
idempotent?: boolean
}
export type CreateUserReveal = CreateUserIdentity & {
generatedPassword: string
}
export type CreateUserView =
| ({ kind: 'reveal' } & CreateUserReveal)
| { kind: 'created' }
| { kind: 'idempotent' }
| { kind: 'missingPassword' }
export type CreateUserNotice = 'reveal' | 'created' | 'idempotent' | 'missingPassword'
export function resolveCreateUserView(
response: CreateUserApiResponse,
identity: CreateUserIdentity,
autoGenerate: boolean,
): CreateUserView {
const generated = response.generated_password ?? ''
if (generated) {
return {
kind: 'reveal',
username: identity.username,
email: identity.email,
generatedPassword: generated,
}
}
if (response.idempotent) {
return { kind: 'idempotent' }
}
if (autoGenerate) {
return { kind: 'missingPassword' }
}
return { kind: 'created' }
}
export function applyCreateUserResponse(
current: CreateUserReveal | null,
view: CreateUserView,
): { success: CreateUserReveal | null; close: boolean; notice: CreateUserNotice | null } {
// A later 200/500-shaped success must not dismiss a one-time password
// that is already on screen (double-submit race).
if (current) {
return { success: current, close: false, notice: null }
}
switch (view.kind) {
case 'reveal':
return {
success: {
username: view.username,
email: view.email,
generatedPassword: view.generatedPassword,
},
close: false,
notice: 'reveal',
}
case 'created':
return { success: null, close: true, notice: 'created' }
case 'idempotent':
return { success: null, close: true, notice: 'idempotent' }
case 'missingPassword':
return { success: null, close: false, notice: 'missingPassword' }
}
}
export function shouldAcceptCreateUserSubmit(submitting: boolean, revealing: boolean): boolean {
return !submitting && !revealing
}
export function captureLockedEscape(
dialogVisible: boolean,
locked: boolean,
event: { key?: string; code?: string; stopImmediatePropagation: () => void },
): boolean {
if (!dialogVisible || !locked) return false
if (event.key !== 'Escape' && event.code !== 'Escape') return false
event.stopImmediatePropagation()
return true
}
export function formatCreateUserCredentials(
reveal: CreateUserReveal,
labels: { username: string; email: string; password: string },
): string {
return [
`${labels.username}: ${reveal.username}`,
`${labels.email}: ${reveal.email}`,
`${labels.password}: ${reveal.generatedPassword}`,
].join('\n')
}

View File

@ -1,96 +1,75 @@
/* Shared visual shell for the SystemAdmin action dialogs. The dialogs are
teleported to body, so this must be global CSS (imported from an
unscoped SFC style block), not scoped styles. */
/* Shared in-place popup chrome for SystemAdmin actions (create user /
reset password). Matches TenantMembers invite / UserProfile password
popups: t-popup teleports to body, so this must be global CSS. */
.password-reset-dialog,
.create-user-dialog {
padding: 0;
overflow: hidden;
border-color: var(--td-component-stroke);
border-radius: 12px;
.system-admin-action-popup-overlay {
z-index: 3050 !important;
.t-popup__content {
padding: 14px 16px !important;
min-width: 300px;
max-width: min(360px, calc(100vw - 24px));
max-height: min(480px, calc(100vh - 96px));
overflow-y: auto;
border-radius: 12px !important;
background: var(--td-bg-color-container) !important;
border: 0.5px solid var(--td-component-stroke) !important;
box-shadow:
0 0 0 0.5px rgba(0, 0, 0, 0.03),
0 2px 4px rgba(0, 0, 0, 0.04),
0 8px 24px rgba(0, 0, 0, 0.1) !important;
backdrop-filter: blur(20px) saturate(180%) !important;
-webkit-backdrop-filter: blur(20px) saturate(180%) !important;
}
}
:root[theme-mode='dark'] .system-admin-action-popup-overlay .t-popup__content {
background: rgba(36, 36, 36, 0.92) !important;
border-color: rgba(255, 255, 255, 0.08) !important;
box-shadow:
0 12px 32px rgba(15, 23, 42, 0.12),
0 2px 8px rgba(15, 23, 42, 0.08);
0 0 0 0.5px rgba(255, 255, 255, 0.05),
0 2px 4px rgba(0, 0, 0, 0.12),
0 8px 32px rgba(0, 0, 0, 0.28) !important;
}
.t-dialog__header {
min-height: 64px;
padding: 0 24px;
font-size: 18px;
line-height: 26px;
border-bottom: 1px solid var(--td-component-stroke);
}
.system-admin-action-popup-anchor {
display: inline-flex;
max-width: 100%;
}
.t-dialog__close {
width: 28px;
height: 28px;
padding: 0;
justify-content: center;
border-radius: 6px;
}
.system-admin-action-popup-inner {
max-width: 100%;
}
.t-dialog__body {
padding: 20px 24px 4px;
}
.system-admin-action-popup-title {
margin: 0 0 8px;
font-size: 15px;
font-weight: 600;
line-height: 1.35;
color: var(--td-text-color-primary);
}
.t-dialog__footer {
box-sizing: border-box;
padding: 16px 24px 20px;
border-top: 1px solid var(--td-component-stroke);
.system-admin-action-popup-hint {
margin: 0 0 12px;
font-size: 13px;
line-height: 1.55;
color: var(--td-text-color-secondary);
}
.t-button {
min-width: 88px;
border-radius: 6px;
}
}
.system-admin-action-popup-form {
.t-form__item {
margin-bottom: 14px;
.password-reset-warning,
.create-user-warning {
padding: 12px 14px;
margin-bottom: 20px;
border-radius: 8px;
.t-alert__content {
font-size: 13px;
line-height: 20px;
}
}
.password-reset-form,
.create-user-form {
.t-form__item {
margin-bottom: 16px;
}
.t-form__label--top {
min-height: 28px;
padding: 0;
font-size: 14px;
line-height: 22px;
}
.t-input {
border-radius: 6px;
&:last-child {
margin-bottom: 4px;
}
}
}
@media (max-width: 480px) {
.password-reset-dialog,
.create-user-dialog {
width: calc(100vw - 24px) !important;
.t-dialog__header {
min-height: 56px;
padding: 0 20px;
font-size: 17px;
}
.t-dialog__body {
padding: 16px 20px 4px;
}
.t-dialog__footer {
padding: 14px 20px 18px;
}
}
.system-admin-action-popup-footer {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
margin-top: 16px;
}

View File

@ -1596,6 +1596,10 @@ type CreateSystemUserResponse struct {
// GeneratedPassword is the plaintext password when the server
// auto-generated one. Absent when the caller supplied the password.
GeneratedPassword string `json:"generated_password,omitempty"`
// Idempotent is true when the identity already existed (HTTP 200).
// The SPA axios interceptor discards status codes, so this flag is
// the body-level signal that nothing was created or changed.
Idempotent bool `json:"idempotent,omitempty"`
}
// CreateSystemUser godoc
@ -1654,7 +1658,7 @@ func (h *SystemHandler) CreateSystemUser(c *gin.Context) {
"password_generated": false,
"idempotent": true,
})
c.JSON(http.StatusOK, CreateSystemUserResponse{User: user.ToUserInfo()})
c.JSON(http.StatusOK, CreateSystemUserResponse{User: user.ToUserInfo(), Idempotent: true})
case errors.Is(err, service.ErrPasswordPolicy):
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
case errors.Is(err, service.ErrUserIdentityConflict):

View File

@ -91,6 +91,9 @@ func TestCreateSystemUserCreatesUserWithExplicitPassword(t *testing.T) {
resp.GeneratedPassword,
)
}
if resp.Idempotent {
t.Fatal("fresh create must not set idempotent")
}
if users.gotReq == nil || users.gotReq.Password == nil || *users.gotReq.Password != "PlainPass9" {
t.Fatalf("service received unexpected request: %+v", users.gotReq)
}
@ -133,6 +136,9 @@ func TestCreateSystemUserAutoGeneratesPasswordWhenEmpty(t *testing.T) {
if resp.GeneratedPassword != "G3n3r4t3dP4ssw0rd" {
t.Fatalf("generated_password=%q, want the once-only generated password", resp.GeneratedPassword)
}
if resp.Idempotent {
t.Fatal("fresh auto-generate create must not set idempotent")
}
if users.gotReq == nil || users.gotReq.Password != nil {
t.Fatalf("absent password must reach the service as nil, got %+v", users.gotReq)
}
@ -260,6 +266,9 @@ func TestCreateSystemUserDuplicateIdentityReturnsExistingUser(t *testing.T) {
if resp.GeneratedPassword != "" {
t.Fatalf("generated_password=%q, want empty for an existing user", resp.GeneratedPassword)
}
if !resp.Idempotent {
t.Fatal("duplicate identity 200 must set idempotent=true so the SPA can tell it from a 201")
}
if len(audits.entries) != 1 || audits.entries[0].Action != types.AuditActionSystemUserCreated {
t.Fatalf("expected one %s audit entry, got %+v", types.AuditActionSystemUserCreated, audits.entries)
}