fix: 修改目标分组名称后自动同步更新本地绑定表中的名称缓存,并为前端更新分组 URL 中的 groupId 进行 Url 编码
This commit is contained in:
@@ -331,7 +331,16 @@ def update_website_group(
|
|||||||
"name": body.name,
|
"name": body.name,
|
||||||
"description": body.description,
|
"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:
|
except Exception as exc:
|
||||||
raise HTTPException(502, str(exc))
|
raise HTTPException(502, str(exc))
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from sqlalchemy.orm import sessionmaker
|
|||||||
from sqlalchemy.pool import StaticPool
|
from sqlalchemy.pool import StaticPool
|
||||||
|
|
||||||
from app.database import Base
|
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.routers.websites import create_website_group, update_website_group
|
||||||
from app.schemas.website import WebsiteGroupCreate, WebsiteGroupUpdate
|
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.commit()
|
||||||
db_session.refresh(w)
|
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_create = []
|
||||||
called_update = []
|
called_update = []
|
||||||
|
|
||||||
@@ -77,3 +88,7 @@ def test_create_and_update_website_group(db_session, monkeypatch):
|
|||||||
assert len(called_update) == 1
|
assert len(called_update) == 1
|
||||||
assert called_update[0][1] == "g123"
|
assert called_update[0][1] == "g123"
|
||||||
assert called_update[0][2] == {"name": "UpdatedGroup", "description": "UpdatedDesc"}
|
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"
|
||||||
|
|||||||
@@ -338,7 +338,7 @@ export const websitesApi = {
|
|||||||
test: (id: number) => api.post<{ success: boolean; message: string; detail?: string }>(`/api/websites/${id}/test`),
|
test: (id: number) => api.post<{ success: boolean; message: string; detail?: string }>(`/api/websites/${id}/test`),
|
||||||
groups: (id: number) => api.get<WebsiteGroup[]>(`/api/websites/${id}/groups`),
|
groups: (id: number) => api.get<WebsiteGroup[]>(`/api/websites/${id}/groups`),
|
||||||
createGroup: (id: number, data: { name: string; description?: string | null }) => api.post<any>(`/api/websites/${id}/groups`, data),
|
createGroup: (id: number, data: { name: string; description?: string | null }) => api.post<any>(`/api/websites/${id}/groups`, data),
|
||||||
updateGroup: (id: number, groupId: string, data: { name: string; description?: string | null }) => api.put<any>(`/api/websites/${id}/groups/${groupId}`, data),
|
updateGroup: (id: number, groupId: string, data: { name: string; description?: string | null }) => api.put<any>(`/api/websites/${id}/groups/${encodeURIComponent(groupId)}`, data),
|
||||||
importGroupsFromUpstream: (id: number, upstreamId: number, data: { group_ids: string[]; name_prefix: string }) =>
|
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),
|
api.post<{ success: boolean; message: string; items: ImportGroupItem[] }>(`/api/websites/${id}/groups/import-from-upstream/${upstreamId}`, data),
|
||||||
syncImportedUpstreamKeys: (id: number, data: { upstream_id: number }) =>
|
syncImportedUpstreamKeys: (id: number, data: { upstream_id: number }) =>
|
||||||
|
|||||||
@@ -1339,7 +1339,7 @@ async function saveWebsiteGroup() {
|
|||||||
ElMessage.success('新增成功')
|
ElMessage.success('新增成功')
|
||||||
}
|
}
|
||||||
groupFormVisible.value = false
|
groupFormVisible.value = false
|
||||||
await loadWebsiteGroups()
|
await Promise.all([loadWebsiteGroups(), loadBindings()])
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
ElMessage.error(e.response?.data?.detail || e.message || '保存失败')
|
ElMessage.error(e.response?.data?.detail || e.message || '保存失败')
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user