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
@@ -226,9 +226,22 @@ type fakeRemarkSnapshot map[string]string
|
||||
func (f fakeRemarkSnapshot) Note(deviceID string) string { return f[deviceID] }
|
||||
func (f fakeRemarkSnapshot) Notes() map[string]string { return f }
|
||||
|
||||
// fakeGroups stands in for web.DeviceGroups (per-device fallback path).
|
||||
type fakeGroups map[string]string
|
||||
|
||||
func (f fakeGroups) Group(deviceID string) string { return f[deviceID] }
|
||||
|
||||
// fakeGroupSnapshot also implements Groups(), the snapshot capability the
|
||||
// shipped web.DeviceGroups provides.
|
||||
type fakeGroupSnapshot map[string]string
|
||||
|
||||
func (f fakeGroupSnapshot) Group(deviceID string) string { return f[deviceID] }
|
||||
func (f fakeGroupSnapshot) Groups() map[string]string { return f }
|
||||
|
||||
func TestListHostsPoolsAndProjection(t *testing.T) {
|
||||
f := newLocalFixture(t)
|
||||
f.srv.cfg.DeviceRemarks = fakeRemarkSnapshot{"1001": "Reception PC"}
|
||||
f.srv.cfg.DeviceGroups = fakeGroupSnapshot{"1002": "Remote"}
|
||||
|
||||
text, sc := mustCallLocal(t, f.srv, "list_hosts", `{}`)
|
||||
hosts := hostList(t, sc)
|
||||
@@ -285,6 +298,9 @@ func TestListHostsPoolsAndProjection(t *testing.T) {
|
||||
if got := strField(t, alpha, "remark"); got != "Reception PC" {
|
||||
t.Fatalf("remark = %q, want the web console's label", got)
|
||||
}
|
||||
if !strings.Contains(text, "1002\tBETA\t-\t192.168.1.2\tRemote\tWindows 11\ttrue\tEXE\t-") {
|
||||
t.Fatalf("text = %q, want BETA row with the group override", text)
|
||||
}
|
||||
if _, ok := hosts[1]["remark"]; ok {
|
||||
t.Fatalf("unset remark present on %v", hosts[1]["id"])
|
||||
}
|
||||
@@ -378,6 +394,33 @@ func TestListHostsFilters(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestListHostsGroupOverride: the web console's group override drives both the
|
||||
// projected group and the group filter, including for offline records.
|
||||
func TestListHostsGroupOverride(t *testing.T) {
|
||||
f := newLocalFixture(t)
|
||||
f.srv.cfg.DeviceGroups = fakeGroupSnapshot{"1002": "Remote", "1003": "Remote", "2001": "Archive"}
|
||||
|
||||
_, sc := mustCallLocal(t, f.srv, "list_hosts", `{"group":"remote"}`)
|
||||
wantIDs(t, hostList(t, sc), "1002", "1003")
|
||||
|
||||
_, sc = mustCallLocal(t, f.srv, "list_hosts", `{"online":false,"group":"archive"}`)
|
||||
wantIDs(t, hostList(t, sc), "2001")
|
||||
if got := strField(t, hostList(t, sc)[0], "group"); got != "Archive" {
|
||||
t.Fatalf("offline group = %q, want the override", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestListHostsGroupOverrideFallback covers a DeviceGroups implementation that
|
||||
// participates through Group() only (no whole-table snapshot).
|
||||
func TestListHostsGroupOverrideFallback(t *testing.T) {
|
||||
f := newLocalFixture(t)
|
||||
f.srv.cfg.DeviceGroups = fakeGroups{"1002": "Remote"}
|
||||
_, sc := mustCallLocal(t, f.srv, "list_hosts", `{}`)
|
||||
if got := strField(t, hostList(t, sc)[1], "group"); got != "Remote" {
|
||||
t.Fatalf("group = %q, want the override", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListHostsPaging(t *testing.T) {
|
||||
f := newLocalFixture(t)
|
||||
|
||||
|
||||
Reference in new issue
Block a user