From f4eaa2f63181c422f87c942a99abced80b3de210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=BF=E4=BA=91=E7=A7=8B=E6=9C=88?= <15273589815@163.com> Date: Sun, 13 Sep 2026 16:19:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(seed):=20=E5=AE=A2=E6=88=B7=E7=A7=8D?= =?UTF-8?q?=E5=AD=90=E6=94=B9=E4=B8=BA=E5=B7=B2=E5=BC=80=E6=88=B7=EF=BC=9B?= =?UTF-8?q?portal.py=20=E6=A0=87=E6=B3=A8=E4=B8=BA=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - seed_test_rbac.py 把 fund_account_status 硬编码成 'closed',与 create_test_user.py 的 {customer: 已开户, employee: closed} 口径不一致,导致种子建的客户永远未开户 - 影响:GET /users/me/account/dashboard、/users/me/cash-ledger 恒返回 404, 正式前端 T001/T009 两个页面打不开(端点本身是好的) - 改为按 user_type 取状态;配合 tools/seed_sim_account_demo.py 开虚拟资金账户后 T001/T006/T007/T009 全部 200 - tools/portal.py:正式前端已在 app/static/portal/,本工具降级为跨角色联调工具 --- tools/seed_test_rbac.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tools/seed_test_rbac.py b/tools/seed_test_rbac.py index a4be30b..b06a30b 100644 --- a/tools/seed_test_rbac.py +++ b/tools/seed_test_rbac.py @@ -186,6 +186,16 @@ USERS: tuple[tuple[int, str, str, str], ...] = ( (9004, "T-REVIEW", "review_t", "employee"), ) +#: `sys_user.user_type` → `fund_account_status`。口径与 `tools/create_test_user.py` +#: 的 `FUND_ACCOUNT_STATUS` **必须一致**:客户只有"已开户"才能访问账户域接口, +#: 员工账号没有基金账户。此前这里(以及 INSERT 语句)硬编码写死 `'closed'`, +#: 于是种子建的客户永远"未开户"—— `GET /api/v1/users/me/account/dashboard` 与 +#: `GET /api/v1/users/me/cash-ledger` 会返回 404「客户未开户」,前端对应页面直接打不开。 +FUND_ACCOUNT_STATUS_BY_USER_TYPE: dict[str, str] = { + "customer": "已开户", + "employee": "closed", +} + #: 用户 → 角色绑定,**显式列出**而不是按位置配对。 #: #: 原先写的是 `zip(user_ids, role_ids, strict=True)`,隐含假设「USERS 与 ROLES 一一对应」; @@ -244,13 +254,20 @@ async def seed() -> None: # 一起弄丢。改为下面循环里的「更新或插入」,且不覆盖 password_hash。 for user_id, user_no, user_name, user_type in USERS: + # 开户状态按角色区分,与 `tools/create_test_user.py` 的 FUND_ACCOUNT_STATUS 口径一致: + # **客户必须"已开户"**,否则账户域接口会一律 404「客户未开户」—— + # 实测受影响的是 `GET /api/v1/users/me/account/dashboard`(前端 T001)与 + # `GET /api/v1/users/me/cash-ledger`(T009),页面直接打不开。 + # 员工账号没有基金账户,保持 closed。 + fund_status = FUND_ACCOUNT_STATUS_BY_USER_TYPE.get(user_type, "closed") updated = await session.execute( text( "UPDATE sys_user SET user_no=:no, username=:name, user_type=:type," - " professional_investor_status='none', fund_account_status='closed'," + " professional_investor_status='none', fund_account_status=:fund," " status='正常', updated_at=:now WHERE id=:id" ), - {"id": user_id, "no": user_no, "name": user_name, "type": user_type, "now": now}, + {"id": user_id, "no": user_no, "name": user_name, "type": user_type, + "fund": fund_status, "now": now}, ) if updated.rowcount == 0: await session.execute( @@ -258,10 +275,10 @@ async def seed() -> None: "INSERT INTO sys_user (id, user_no, username, password_hash, user_type," " professional_investor_status, fund_account_status, status," " created_at, updated_at)" - " VALUES (:id,:no,:name,'x',:type,'none','closed','正常',:now,:now)" + " VALUES (:id,:no,:name,'x',:type,'none',:fund,'正常',:now,:now)" ), {"id": user_id, "no": user_no, "name": user_name, - "type": user_type, "now": now}, + "type": user_type, "fund": fund_status, "now": now}, ) for role_id, role_code, role_name in ROLES: await session.execute(