fix: allow deleting system default sync channel with immediate heal

Remove hard ban that returned 400 with no UI feedback; delete then Ensure+rebinding, and show confirm/toast on SyncPage.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
whm
2026-08-06 09:03:41 +08:00
parent 362dcee242
commit 75622a728e
4 changed files with 56 additions and 16 deletions

View File

@@ -121,21 +121,23 @@ func syncDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
authx.WriteError(w, http.StatusNotFound, err.Error())
return
}
// Z12h-1公司默认同步通道禁止删除账号落点依赖它
if ch.IsSystemDefault {
authx.WriteError(w, http.StatusBadRequest, "公司默认同步通道不可删除;账号绑定落点依赖此通道。若异常请刷新页面自动修复")
return
}
wasDefault := ch.IsSystemDefault
svcCtx.DBSync.StopChannel(id)
if err := svcCtx.DBSync.Store().DeleteChannel(id); err != nil {
authx.WriteError(w, http.StatusBadRequest, err.Error())
return
}
// 若误删后仍有 Binding 挂死heal 会挂回默认通道
if _, hErr := applogic.HealTenantSyncBind(r.Context(), svcCtx, tid); hErr != nil {
_ = hErr
// Z12h-1默认同步可删删后 Ensure+heal账号落点自动挂回默认通道
out := map[string]any{"ok": true, "deleted_id": id, "was_system_default": wasDefault}
if healed, hErr := applogic.HealTenantSyncBind(r.Context(), svcCtx, tid); hErr != nil {
out["heal_error"] = hErr.Error()
} else if healed != nil {
out["channel_id"] = healed.ChannelID
out["recreated_default"] = wasDefault || healed.ChannelCreated
out["bindings_fixed"] = healed.BindingsFixed
out["agents_fixed"] = healed.AgentsFixed
}
httpx.OkJson(w, map[string]any{"ok": true})
httpx.OkJson(w, out)
}
}