From 3172ab18bfe49c4b0a3c3011cf39dac56200009a Mon Sep 17 00:00:00 2001 From: liumangmang Date: Wed, 1 Jul 2026 17:55:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E7=9B=AE=E6=A0=87?= =?UTF-8?q?=E5=88=86=E7=BB=84=E5=90=8D=E7=A7=B0=E5=90=8E=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=9B=B4=E6=96=B0=E6=9C=AC=E5=9C=B0=E7=BB=91?= =?UTF-8?q?=E5=AE=9A=E8=A1=A8=E4=B8=AD=E7=9A=84=E5=90=8D=E7=A7=B0=E7=BC=93?= =?UTF-8?q?=E5=AD=98=EF=BC=8C=E5=B9=B6=E4=B8=BA=E5=89=8D=E7=AB=AF=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=88=86=E7=BB=84=20URL=20=E4=B8=AD=E7=9A=84=20groupI?= =?UTF-8?q?d=20=E8=BF=9B=E8=A1=8C=20Url=20=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/routers/websites.py | 11 ++++++++++- backend/test_website_group_mgmt.py | 17 ++++++++++++++++- frontend/src/api/index.ts | 2 +- frontend/src/views/Websites.vue | 2 +- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/backend/app/routers/websites.py b/backend/app/routers/websites.py index d175367..241ec94 100644 --- a/backend/app/routers/websites.py +++ b/backend/app/routers/websites.py @@ -331,7 +331,16 @@ def update_website_group( "name": body.name, "description": body.description, } - return c.update_group(row.group_update_endpoint, group_id, payload) + resp = c.update_group(row.group_update_endpoint, group_id, payload) + + # Sync updated group name to local group bindings cache + db.query(WebsiteGroupBinding).filter( + WebsiteGroupBinding.website_id == wid, + WebsiteGroupBinding.target_group_id == group_id + ).update({"target_group_name": body.name}) + db.commit() + + return resp except Exception as exc: raise HTTPException(502, str(exc)) diff --git a/backend/test_website_group_mgmt.py b/backend/test_website_group_mgmt.py index f5799a9..7a8c489 100644 --- a/backend/test_website_group_mgmt.py +++ b/backend/test_website_group_mgmt.py @@ -4,7 +4,7 @@ from sqlalchemy.orm import sessionmaker from sqlalchemy.pool import StaticPool from app.database import Base -from app.models.website import Website +from app.models.website import Website, WebsiteGroupBinding from app.routers.websites import create_website_group, update_website_group from app.schemas.website import WebsiteGroupCreate, WebsiteGroupUpdate @@ -40,6 +40,17 @@ def test_create_and_update_website_group(db_session, monkeypatch): db_session.commit() db_session.refresh(w) + b = WebsiteGroupBinding( + website_id=w.id, + target_group_id="g123", + target_group_name="OldName", + source_groups_json="[]", + enabled=True + ) + db_session.add(b) + db_session.commit() + db_session.refresh(b) + called_create = [] called_update = [] @@ -77,3 +88,7 @@ def test_create_and_update_website_group(db_session, monkeypatch): assert len(called_update) == 1 assert called_update[0][1] == "g123" assert called_update[0][2] == {"name": "UpdatedGroup", "description": "UpdatedDesc"} + + # Verify that local binding was updated + db_session.refresh(b) + assert b.target_group_name == "UpdatedGroup" diff --git a/frontend/src/api/index.ts b/frontend/src/api/index.ts index 5682db7..60996e4 100644 --- a/frontend/src/api/index.ts +++ b/frontend/src/api/index.ts @@ -338,7 +338,7 @@ export const websitesApi = { test: (id: number) => api.post<{ success: boolean; message: string; detail?: string }>(`/api/websites/${id}/test`), groups: (id: number) => api.get(`/api/websites/${id}/groups`), createGroup: (id: number, data: { name: string; description?: string | null }) => api.post(`/api/websites/${id}/groups`, data), - updateGroup: (id: number, groupId: string, data: { name: string; description?: string | null }) => api.put(`/api/websites/${id}/groups/${groupId}`, data), + updateGroup: (id: number, groupId: string, data: { name: string; description?: string | null }) => api.put(`/api/websites/${id}/groups/${encodeURIComponent(groupId)}`, data), importGroupsFromUpstream: (id: number, upstreamId: number, data: { group_ids: string[]; name_prefix: string }) => api.post<{ success: boolean; message: string; items: ImportGroupItem[] }>(`/api/websites/${id}/groups/import-from-upstream/${upstreamId}`, data), syncImportedUpstreamKeys: (id: number, data: { upstream_id: number }) => diff --git a/frontend/src/views/Websites.vue b/frontend/src/views/Websites.vue index 7eeb286..12f6e7f 100644 --- a/frontend/src/views/Websites.vue +++ b/frontend/src/views/Websites.vue @@ -1339,7 +1339,7 @@ async function saveWebsiteGroup() { ElMessage.success('新增成功') } groupFormVisible.value = false - await loadWebsiteGroups() + await Promise.all([loadWebsiteGroups(), loadBindings()]) } catch (e: any) { ElMessage.error(e.response?.data?.detail || e.message || '保存失败') } finally {