From 3d3bb7f6d1acca8caa84bb73b189fe46c30967a9 Mon Sep 17 00:00:00 2001 From: lyingbug Date: Sun, 6 Sep 2026 00:35:08 +0800 Subject: [PATCH] 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. --- docs/docs.go | 4 + docs/swagger.json | 4 + docs/swagger.yaml | 6 + frontend/src/api/system/index.ts | 8 +- frontend/src/i18n/locales/en-US.ts | 6 +- frontend/src/i18n/locales/ko-KR.ts | 6 +- frontend/src/i18n/locales/ru-RU.ts | 6 +- frontend/src/i18n/locales/zh-CN.ts | 6 +- .../src/views/system/CreateUserDialog.vue | 457 +++++++------- frontend/src/views/system/SystemSettings.vue | 570 +++++++----------- .../system/createUserDialogState.test.ts | 111 ++++ .../src/views/system/createUserDialogState.ts | 108 ++++ .../src/views/system/systemAdminDialog.less | 145 ++--- internal/handler/system.go | 6 +- internal/handler/system_user_create_test.go | 9 + 15 files changed, 753 insertions(+), 699 deletions(-) create mode 100644 frontend/src/views/system/createUserDialogState.test.ts create mode 100644 frontend/src/views/system/createUserDialogState.ts diff --git a/docs/docs.go b/docs/docs.go index 73a4592a..aac91a12 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -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" } diff --git a/docs/swagger.json b/docs/swagger.json index 4ce7bff1..0f7ac47d 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -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" } diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 572ac193..2f163288 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -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 diff --git a/frontend/src/api/system/index.ts b/frontend/src/api/system/index.ts index 9e501ca6..5b503a1f 100644 --- a/frontend/src/api/system/index.ts +++ b/frontend/src/api/system/index.ts @@ -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 { const response = await post('/api/v1/system/admin/users/create', req) diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index d78fb782..8f7e80a6 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -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' } }, diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index 7fbc548e..8f07d874 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -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: '비밀번호를 저장했습니다' } }, diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index a4fa6b37..58a6b0ac 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -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: 'Я сохранил пароль' } }, diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index 46f04348..518ff2fc 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -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: '我已保存密码' } }, diff --git a/frontend/src/views/system/CreateUserDialog.vue b/frontend/src/views/system/CreateUserDialog.vue index 4b28a239..a3e0f55d 100644 --- a/frontend/src/views/system/CreateUserDialog.vue +++ b/frontend/src/views/system/CreateUserDialog.vue @@ -1,156 +1,115 @@