From c591f16d539a3e458b65b1c65f504ac0ddb9c495 Mon Sep 17 00:00:00 2001 From: MidoriKurage Date: Mon, 7 Sep 2026 16:10:44 +0800 Subject: [PATCH] refactor(system): drop idempotent flag from create-user response body --- docs/docs.go | 4 ---- docs/swagger.json | 4 ---- docs/swagger.yaml | 6 ------ internal/handler/system.go | 6 +----- internal/handler/system_user_create_test.go | 9 --------- 5 files changed, 1 insertion(+), 28 deletions(-) diff --git a/docs/docs.go b/docs/docs.go index aac91a12..73a4592a 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -23489,10 +23489,6 @@ 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 0f7ac47d..4ce7bff1 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -23482,10 +23482,6 @@ "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 2f163288..572ac193 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -5064,12 +5064,6 @@ 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/internal/handler/system.go b/internal/handler/system.go index e481ace7..cee7f54d 100644 --- a/internal/handler/system.go +++ b/internal/handler/system.go @@ -1596,10 +1596,6 @@ 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 @@ -1658,7 +1654,7 @@ func (h *SystemHandler) CreateSystemUser(c *gin.Context) { "password_generated": false, "idempotent": true, }) - c.JSON(http.StatusOK, CreateSystemUserResponse{User: user.ToUserInfo(), Idempotent: true}) + c.JSON(http.StatusOK, CreateSystemUserResponse{User: user.ToUserInfo()}) case errors.Is(err, service.ErrPasswordPolicy): c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) case errors.Is(err, service.ErrUserIdentityConflict): diff --git a/internal/handler/system_user_create_test.go b/internal/handler/system_user_create_test.go index 78e5c719..4b9af3cb 100644 --- a/internal/handler/system_user_create_test.go +++ b/internal/handler/system_user_create_test.go @@ -91,9 +91,6 @@ 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) } @@ -136,9 +133,6 @@ 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) } @@ -266,9 +260,6 @@ 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) }