Feature: edit device remarks from the web console

The Go web console now stores a per-device remark and renders it as
"hostname (remark)" on the card, the label displayName already
supported. The card's "..." menu gets an Edit remark entry directly
below Terminal; it opens a small dialog, and an empty value clears the
label. Remarks live in device_notes.json next to users.json, independent
of the device history and ACL, so offline records carry them too.

The WebSocket command set_device_remark is admin-only and honors the
device ACL (a private device of another owner is refused). Updates are
audited as admin.device.remark and broadcast as devices_changed so every
open console refreshes. Deleting a device drops its remark. The
device_list reply reports remarkEdit only when a notes table is wired,
so the shared page hides the entry on the MFC server, which does not
implement it.

A malformed or newer-version device_notes.json disables writes instead
of letting the first save overwrite labels it could not parse; loaded
values are re-sanitized and capped. Verified with go test ./..., vet,
gofmt, and a node --check pass on the inline script.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-27 13:22:21 +01:00
1 parent 1bd7fa5b2d
commit 95d2bbc1b6
9 files changed
+741 -7

No files matched your search

+9
View File
@@ -33,6 +33,7 @@ type Server struct {
auth *wsauth.Authenticator
history *devicehistory.Store // nil → no offline devices
deviceACL *DeviceACL // nil → no per-device owner filtering
deviceNotes *DeviceNotes // nil → no "edit remark" entry in the UI
ws *wsHub
allowedOrigins []string // for WS Origin allowlist; empty = same-origin only
loginIPLimit *wsauth.RateLimiter
@@ -96,6 +97,12 @@ type Config struct {
// behaviour: every authenticated session sees every device). The shipped
// server always wires one; tests may omit it.
DeviceACL *DeviceACL
// DeviceNotes is the per-device remark table rendered on the card as
// "hostname (remark)". nil disables the "edit remark" menu entry: the
// device_list reply reports remarkEdit only when this is wired, so the
// shared page hides the action on a backend that does not implement it
// (the MFC server).
DeviceNotes *DeviceNotes
// TransferTarget ("host:port") and TransferDays pre-fill the web UI's
// "transfer host" dialog. Reporting them is also what tells the shared
// page that this backend implements COMMAND_ASSIGN_MASTER — the MFC server
@@ -138,6 +145,7 @@ func (s *Server) WithConfig(cfg Config) *Server {
s.brandName = resolveBrandName(cfg.BrandName, s.basePath)
s.sso = cfg.SSO
s.deviceACL = cfg.DeviceACL
s.deviceNotes = cfg.DeviceNotes
s.transferTarget = cfg.TransferTarget
s.transferDays = cfg.TransferDays
s.transferTransport = cfg.TransferTransport
@@ -166,6 +174,7 @@ func (s *Server) Start() error {
withLoginRateLimiters(s.loginIPLimit, s.loginUserLimit).
withTrustForwardedFor(s.trustForwardedFor).
withDeviceACL(s.deviceACL).
withDeviceNotes(s.deviceNotes).
withTransferDefaults(s.transferTarget, s.transferDays, s.transferTransport)
mux := http.NewServeMux()