Add UUID/FK channel checks, agent whitelist/push APIs, bindings, super-admin LWW audit with rollback, reconcile rate limits, and sync docs. Default customers stay opt-in; company conflict UI is removed. Co-authored-by: Cursor <cursoragent@cursor.com>
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package handler
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"aijianzhan/platform/internal/authx"
|
|
"aijianzhan/platform/internal/dbsync"
|
|
"aijianzhan/platform/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/rest/httpx"
|
|
)
|
|
|
|
func syncBindingsListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
if !requireDBSync(svcCtx, w) {
|
|
return
|
|
}
|
|
localID := r.URL.Query().Get("local_database_id")
|
|
list, err := svcCtx.DBSync.Store().ListBindings(syncTenantID(r), localID)
|
|
if err != nil {
|
|
authx.WriteError(w, http.StatusBadRequest, err.Error())
|
|
return
|
|
}
|
|
httpx.OkJson(w, map[string]any{"items": list})
|
|
}
|
|
}
|
|
|
|
func syncBindingsEnsureHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
if !requireDBSync(svcCtx, w) {
|
|
return
|
|
}
|
|
var body dbsync.Binding
|
|
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
|
authx.WriteError(w, http.StatusBadRequest, err.Error())
|
|
return
|
|
}
|
|
body.TenantID = syncTenantID(r)
|
|
if body.UserID == 0 {
|
|
body.UserID = authx.UserID(r.Context())
|
|
}
|
|
saved, err := svcCtx.DBSync.Store().EnsureBinding(body)
|
|
if err != nil {
|
|
authx.WriteError(w, http.StatusBadRequest, err.Error())
|
|
return
|
|
}
|
|
httpx.OkJson(w, saved)
|
|
}
|
|
}
|