feat: harden loose-offline sync for user JWT, schema, and console ops

Enable Binding-scoped agent push/pull, empty-table schema ensure, SyncPage inspect/drop-table, default module import, and agent-bound publish docs from the 宇恒联调意见.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
whm
2026-08-05 09:47:35 +08:00
parent 76cdcd760e
commit b04b180d30
59 changed files with 4762 additions and 308 deletions

View File

@@ -17,7 +17,16 @@ func syncBindingsListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return
}
localID := r.URL.Query().Get("local_database_id")
list, err := svcCtx.DBSync.Store().ListBindings(syncTenantID(r), localID)
tid := syncTenantID(r)
var (
list []dbsync.Binding
err error
)
if authx.SyncTenantWide(r.Context()) {
list, err = svcCtx.DBSync.Store().ListBindings(tid, localID)
} else {
list, err = svcCtx.DBSync.Store().ListBindingsFiltered(tid, authx.UserID(r.Context()), localID)
}
if err != nil {
authx.WriteError(w, http.StatusBadRequest, err.Error())
return
@@ -37,8 +46,14 @@ func syncBindingsEnsureHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return
}
body.TenantID = syncTenantID(r)
if body.UserID == 0 {
body.UserID = authx.UserID(r.Context())
uid := authx.UserID(r.Context())
if authx.SyncTenantWide(r.Context()) {
if body.UserID == 0 {
body.UserID = uid
}
} else {
// 用户自助:强制绑定到本人,禁止冒用他人 user_id
body.UserID = uid
}
saved, err := svcCtx.DBSync.Store().EnsureBinding(body)
if err != nil {