Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
fix(frontend): project create-user HTTP status onto a 'created' flag
MidoriKurage384fbcf7ede8
diff --git a/frontend/src/api/system/index.ts b/frontend/src/api/system/index.tsindex 5b503a1f2..7cc0c6e9a 100644--- a/frontend/src/api/system/index.ts+++ b/frontend/src/api/system/index.ts@@ -398,22 +398,25 @@ export interface CreateSystemUserResponse {* be fetched again.*/generated_password?: string+}++export interface CreateSystemUserResult extends CreateSystemUserResponse {/**- * 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.+ * True only when this call created the account (HTTP 201), false on the+ * idempotent 200 retry (identity already existed).*/- idempotent?: boolean+ created: boolean}/*** Provision a new local user account (SystemAdmin only).- * Backend returns the unwrapped CreateSystemUserResponse body.- * 201 on create, 200 with `idempotent: true` when the identity existed.+ * The backend answers 201 on create and 200 on the idempotent retry with+ * the same CreateSystemUserResponse body. The status is projected onto+ * `created`.*/-export async function createSystemUser(req: CreateSystemUserRequest): Promise<CreateSystemUserResponse> {- const response = await post('/api/v1/system/admin/users/create', req)- return response as unknown as CreateSystemUserResponse+export async function createSystemUser(req: CreateSystemUserRequest): Promise<CreateSystemUserResult> {+ const response = await post<CreateSystemUserResponse>('/api/v1/system/admin/users/create', req)+ return { ...response, created: response.$httpStatus === 201 }}// ---- System Settings (P1) ----diff --git a/frontend/src/views/system/createUserDialogState.test.ts b/frontend/src/views/system/createUserDialogState.test.tsindex a32a9751b..43595cf62 100644--- a/frontend/src/views/system/createUserDialogState.test.ts+++ b/frontend/src/views/system/createUserDialogState.test.ts@@ -14,7 +14,7 @@ const identity = { username: 'alice', email: '[email protected]' }test('reveal wins whenever the server minted a one-time password', () => {const view = resolveCreateUserView(- { generated_password: 'OnceOnly9', idempotent: false },+ { generated_password: 'OnceOnly9', created: true },identity,true,)@@ -26,27 +26,27 @@ test('reveal wins whenever the server minted a one-time password', () => {})})-test('idempotent flag is the 200 retry signal when no password was minted', () => {+test('created:false is the 200 retry signal when no password was minted', () => {assert.deepEqual(- resolveCreateUserView({ idempotent: true }, identity, true),+ resolveCreateUserView({ created: false }, identity, true),{ kind: 'idempotent' },)assert.deepEqual(- resolveCreateUserView({ idempotent: true }, identity, false),+ resolveCreateUserView({ created: false }, identity, false),{ kind: 'idempotent' },)})-test('supplied-password create without the idempotent flag is a real create', () => {+test('created:true with a supplied password is a real create', () => {assert.deepEqual(- resolveCreateUserView({}, identity, false),+ resolveCreateUserView({ created: true }, identity, false),{ kind: 'created' },)})-test('auto-generate create missing generated_password is not treated as idempotent', () => {+test('auto-generate create that failed to return generated_password surfaces missingPassword', () => {assert.deepEqual(- resolveCreateUserView({}, identity, true),+ resolveCreateUserView({ created: true }, identity, true),{ kind: 'missingPassword' },)})diff --git a/frontend/src/views/system/createUserDialogState.ts b/frontend/src/views/system/createUserDialogState.tsindex d4ab51911..6c9e4fb8a 100644--- a/frontend/src/views/system/createUserDialogState.ts+++ b/frontend/src/views/system/createUserDialogState.ts@@ -1,22 +1,14 @@/*** 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.*/+import type { CreateSystemUserResult } from "@/api/system"+export type CreateUserIdentity = {username: stringemail: string}-export type CreateUserApiResponse = {- generated_password?: string- idempotent?: boolean-}-export type CreateUserReveal = CreateUserIdentity & {generatedPassword: string}@@ -30,7 +22,7 @@ export type CreateUserView =export type CreateUserNotice = 'reveal' | 'created' | 'idempotent' | 'missingPassword'export function resolveCreateUserView(- response: CreateUserApiResponse,+ response: Omit<CreateSystemUserResult, 'user'>,identity: CreateUserIdentity,autoGenerate: boolean,): CreateUserView {@@ -43,7 +35,7 @@ export function resolveCreateUserView(generatedPassword: generated,}}- if (response.idempotent) {+ if (!response.created) {return { kind: 'idempotent' }}if (autoGenerate) {