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:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user