MCPcopy Create free account
hub / github.com/0xUnixIO/pulse / handleGroupSync

Method handleGroupSync

internal/serverapi/usergroup.go:298–331  ·  view source on GitHub ↗

handleGroupSync 同步用户组所有成员的 inbound 记录。

(w http.ResponseWriter, r *http.Request, groupID string)

Source from the content-addressed store, hash-verified

296
297// handleGroupSync 同步用户组所有成员的 inbound 记录。
298func (a *userGroupAPI) handleGroupSync(w http.ResponseWriter, r *http.Request, groupID string) {
299 if r.Method != http.MethodPost {
300 writeMethodNotAllowed(w, http.MethodPost)
301 return
302 }
303 g, err := a.ugStore.GetUserGroup(groupID)
304 if err != nil {
305 writeUserGroupError(w, err)
306 return
307 }
308 inboundIDs := parseCommaList(g.InboundIDs)
309 memberIDs, err := a.ugStore.ListGroupMembers(groupID)
310 if err != nil {
311 internalError(w, r, err)
312 return
313 }
314 affectedNodeIDs := make(map[string]struct{})
315 for _, uid := range memberIDs {
316 nodeIDs, err := a.syncGroupForUser(groupID, uid, inboundIDs)
317 if err != nil {
318 internalError(w, r, err)
319 return
320 }
321 for _, nid := range nodeIDs {
322 affectedNodeIDs[nid] = struct{}{}
323 }
324 }
325 nodes := make([]string, 0, len(affectedNodeIDs))
326 for nid := range affectedNodeIDs {
327 nodes = append(nodes, nid)
328 }
329 a.applyNodes(nodes)
330 writeJSON(w, http.StatusOK, map[string]any{"synced_members": len(memberIDs), "affected_nodes": nodes})
331}
332
333// syncGroupForUser 同步指定用户在指定组的 inbound 记录:
334// 先删除旧的组记录,再按 inboundIDs 重建,返回受影响的 nodeIDs。

Callers 1

handleUserGroupRoutesMethod · 0.95

Calls 9

syncGroupForUserMethod · 0.95
writeMethodNotAllowedFunction · 0.85
writeUserGroupErrorFunction · 0.85
parseCommaListFunction · 0.85
internalErrorFunction · 0.85
applyNodesMethod · 0.80
writeJSONFunction · 0.70
GetUserGroupMethod · 0.65
ListGroupMembersMethod · 0.65

Tested by

no test coverage detected