Feature: let the web console move a host to another group
The Go server now keeps a per-device group override (device_groups.json) edited from the card's "..." menu below Edit remark. The override wins over the group the host reported (or the offline history record) in the device list, the group filter, get_groups and the MCP host tools, so offline records can be regrouped and the change survives restarts. An empty value clears the override; names are capped at 23 characters, matching the Win32 regroup dialog. The command is admin-only and honours the device ACL; it refuses IDs the server has never seen (online or in history) so a stale card cannot create an orphan entry, and the remark handler gets the same guard. Each change is audited as admin.device.group, deleting a device drops its override, and values loaded from disk are trimmed and capped like remarks. The menu entry is gated on the groupEdit capability, so the shared page hides it on the MFC server. Like remarks, the override is a Go-side label: no CMD_SET_GROUP is sent, so the host keeps reporting its own group to other masters. Verified with go test ./..., go vet, gofmt and a node --check pass on the page. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
5f764b2425
commit
034b11fa6a
16 files changed
+895
-54
No files matched your search
@@ -142,9 +142,15 @@ func (s *Server) callListHosts(_ context.Context, raw json.RawMessage) (any, *rp
|
||||
ctF := strings.ToLower(args.ClientType)
|
||||
|
||||
matched := make([]hub.DeviceInfo, 0, len(pool))
|
||||
remarkOf := s.remarkLookup()
|
||||
view := s.hostView()
|
||||
for _, d := range pool {
|
||||
group := d.Group
|
||||
if view.groupOf != nil {
|
||||
// A web-console override wins over the group the host reported.
|
||||
if g := view.groupOf(d.ID); g != "" {
|
||||
group = g
|
||||
}
|
||||
}
|
||||
if group == "" {
|
||||
group = "default"
|
||||
}
|
||||
@@ -157,8 +163,8 @@ func (s *Server) callListHosts(_ context.Context, raw json.RawMessage) (any, *rp
|
||||
clientType = s.clientType(d.ID)
|
||||
}
|
||||
remark := ""
|
||||
if remarkOf != nil {
|
||||
remark = remarkOf(d.ID)
|
||||
if view.remarkOf != nil {
|
||||
remark = view.remarkOf(d.ID)
|
||||
}
|
||||
// query matches computer name, remark and IP; name matches computer
|
||||
// name and remark, like the Win32 server. The remark is the web
|
||||
@@ -194,7 +200,7 @@ func (s *Server) callListHosts(_ context.Context, raw json.RawMessage) (any, *rp
|
||||
end := min(begin+limit, total)
|
||||
hosts := make([]map[string]any, 0, end-begin)
|
||||
for _, d := range matched[begin:end] {
|
||||
hosts = append(hosts, s.hostJSON(d, remarkOf))
|
||||
hosts = append(hosts, s.hostJSON(d, view))
|
||||
}
|
||||
|
||||
structured := map[string]any{
|
||||
@@ -215,11 +221,16 @@ func (s *Server) callListHosts(_ context.Context, raw json.RawMessage) (any, *rp
|
||||
|
||||
// hostJSON projects a hub device onto the list_hosts/get_host_detail schema.
|
||||
// Fields the Go server does not know (authStatus, tls, clientType of an
|
||||
// offline entry) are omitted rather than fabricated. remark is included when
|
||||
// the web console has one for the device; remarkOf is the per-call snapshot
|
||||
// (nil when no remark table is configured).
|
||||
func (s *Server) hostJSON(d hub.DeviceInfo, remarkOf func(string) string) map[string]any {
|
||||
// offline entry) are omitted rather than fabricated. remark and group come
|
||||
// from the web console when it has them (view carries the per-call snapshots).
|
||||
func (s *Server) hostJSON(d hub.DeviceInfo, view hostView) map[string]any {
|
||||
group := d.Group
|
||||
if view.groupOf != nil {
|
||||
// A web-console override wins over the group the host reported.
|
||||
if g := view.groupOf(d.ID); g != "" {
|
||||
group = g
|
||||
}
|
||||
}
|
||||
if group == "" {
|
||||
group = "default"
|
||||
}
|
||||
@@ -229,8 +240,8 @@ func (s *Server) hostJSON(d hub.DeviceInfo, remarkOf func(string) string) map[st
|
||||
"group": group,
|
||||
"online": d.Online,
|
||||
}
|
||||
if remarkOf != nil {
|
||||
if remark := remarkOf(d.ID); remark != "" {
|
||||
if view.remarkOf != nil {
|
||||
if remark := view.remarkOf(d.ID); remark != "" {
|
||||
h["remark"] = remark
|
||||
}
|
||||
}
|
||||
@@ -316,7 +327,7 @@ func (s *Server) callGetHostDetail(_ context.Context, raw json.RawMessage) (any,
|
||||
return nil, errf(CodeInvalidParams, "Missing required parameter: id or ids")
|
||||
}
|
||||
online, offline := s.hostMaps()
|
||||
host, rerr := s.lookupHost(args.ID, online, offline, s.remarkLookup())
|
||||
host, rerr := s.lookupHost(args.ID, online, offline, s.hostView())
|
||||
if rerr != nil {
|
||||
return nil, rerr
|
||||
}
|
||||
@@ -329,11 +340,11 @@ func (s *Server) hostDetailBatch(ids []string) (any, *rpcError) {
|
||||
"Too many ids: %d (max %d per batch)", len(ids), batchMaxIDs)
|
||||
}
|
||||
online, offline := s.hostMaps()
|
||||
remarkOf := s.remarkLookup() // one snapshot for the whole batch
|
||||
view := s.hostView() // one snapshot for the whole batch
|
||||
results := make([]map[string]any, 0, len(ids))
|
||||
succeeded, failed := 0, 0
|
||||
for _, id := range ids {
|
||||
host, rerr := s.lookupHost(id, online, offline, remarkOf)
|
||||
host, rerr := s.lookupHost(id, online, offline, view)
|
||||
if rerr != nil {
|
||||
results = append(results, map[string]any{
|
||||
"id": id,
|
||||
@@ -392,17 +403,17 @@ func (s *Server) hostMaps() (online, offline map[string]hub.DeviceInfo) {
|
||||
// lookupHost resolves one host: online first, then the last-known history
|
||||
// record. It mirrors the Win32 server, which answers offline hosts with their
|
||||
// final snapshot instead of an error.
|
||||
func (s *Server) lookupHost(id string, online, offline map[string]hub.DeviceInfo, remarkOf func(string) string) (map[string]any, *rpcError) {
|
||||
func (s *Server) lookupHost(id string, online, offline map[string]hub.DeviceInfo, view hostView) (map[string]any, *rpcError) {
|
||||
if !isDecimalID(id) {
|
||||
return nil, errf(CodeInvalidParams, "Invalid id: expected a decimal host id string")
|
||||
}
|
||||
if d, ok := online[id]; ok {
|
||||
h := s.hostJSON(d, remarkOf)
|
||||
h := s.hostJSON(d, view)
|
||||
h["capabilities"] = s.capabilities(d)
|
||||
return h, nil
|
||||
}
|
||||
if d, ok := offline[id]; ok {
|
||||
return s.hostJSON(d, remarkOf), nil
|
||||
return s.hostJSON(d, view), nil
|
||||
}
|
||||
return nil, errf(CodeOffline, "Host not found or offline: %s", id)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user