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
@@ -83,7 +83,7 @@ func (n *DeviceNotes) Load() error {
|
||||
id = strings.TrimSpace(id)
|
||||
// Apply the same invariants Set enforces: a hand-edited or restored
|
||||
// file must not put a multi-line / over-long label on a card.
|
||||
e.Note = capRemark(sanitizeRemark(e.Note))
|
||||
e.Note = capRunes(sanitizeLabel(e.Note), MaxRemarkRunes)
|
||||
if id == "" || e.Note == "" {
|
||||
continue
|
||||
}
|
||||
@@ -154,7 +154,7 @@ func (n *DeviceNotes) Set(deviceID, note, actor string) error {
|
||||
if deviceID == "" {
|
||||
return fmt.Errorf("empty device id")
|
||||
}
|
||||
note = sanitizeRemark(note)
|
||||
note = sanitizeLabel(note)
|
||||
if utf8.RuneCountInString(note) > MaxRemarkRunes {
|
||||
return fmt.Errorf("remark is too long (max %d characters)", MaxRemarkRunes)
|
||||
}
|
||||
@@ -212,10 +212,11 @@ func (n *DeviceNotes) Remove(deviceID string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// sanitizeRemark folds line breaks and other control characters (including
|
||||
// sanitizeLabel folds line breaks and other control characters (including
|
||||
// bidi/zero-width formatting runes, which could reorder the card title) to
|
||||
// spaces so the label always renders on one line, then trims both ends.
|
||||
func sanitizeRemark(s string) string {
|
||||
// Shared by the per-device remark and group tables.
|
||||
func sanitizeLabel(s string) string {
|
||||
s = strings.Map(func(r rune) rune {
|
||||
if unicode.IsControl(r) || unicode.Is(unicode.Cf, r) {
|
||||
return ' '
|
||||
@@ -225,13 +226,14 @@ func sanitizeRemark(s string) string {
|
||||
return strings.TrimSpace(s)
|
||||
}
|
||||
|
||||
// capRemark truncates s to MaxRemarkRunes runes. Used on values read back
|
||||
// from disk, where an older/hand-edited file may exceed the current limit.
|
||||
func capRemark(s string) string {
|
||||
if utf8.RuneCountInString(s) <= MaxRemarkRunes {
|
||||
// capRunes truncates s to max runes. Used on values read back from disk, where
|
||||
// an older/hand-edited file may exceed the current limit. Trims again after the
|
||||
// cut so the stored label cannot end in an invisible space.
|
||||
func capRunes(s string, max int) string {
|
||||
if utf8.RuneCountInString(s) <= max {
|
||||
return s
|
||||
}
|
||||
return string([]rune(s)[:MaxRemarkRunes])
|
||||
return strings.TrimSpace(string([]rune(s)[:max]))
|
||||
}
|
||||
|
||||
// saveLocked writes the table via a temp file + rename. Caller holds n.mu.
|
||||
|
||||
Reference in new issue
Block a user