Campus hello: the same address under a new name replaces its old entry

Woonsocket reported as "new" before its first setup finished, then as ws: NA kept both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-20 16:18:15 -04:00
co-authored by Claude Opus 5.5
parent d7dc931bd4
commit 4dac76f703
2 changed files with 7 additions and 1 deletions
+4 -1
View File
@@ -890,7 +890,10 @@ class Handler(http.server.BaseHTTPRequestHandler):
or not allowed_client(url[7:].split(":")[0]):
return self.send(400, {"error": "an id like ws and an address like http://10.5.1.1:8020"})
data = campuses.load(site.data_dir)
data.setdefault("list", {})[cid] = {"id": cid, "name": str(body.get("name") or cid)[:40], "url": url}
lst = data.setdefault("list", {})
for other in [k for k, e in lst.items() if k != cid and (e or {}).get("url") == url]:
lst.pop(other) # the same Mac under its old name (before its first setup)
lst[cid] = {"id": cid, "name": str(body.get("name") or cid)[:40], "url": url}
campuses.save(site.data_dir, data)
return self.send(200, {"ok": True})
if path == "/api/fleet/hello":
+3
View File
@@ -323,3 +323,6 @@ class TestCampusHello(TestRoutes):
self.assertEqual(get(self.port, "/api/campus/hello", bad)[0], 400, bad)
from settings import campuses as cv
self.assertEqual(cv.load(self.data)["list"]["ws"]["url"], "http://10.5.1.1:8020")
get(self.port, "/api/campus/hello", {"id": "new", "url": "http://10.5.1.9:8020"})
get(self.port, "/api/campus/hello", {"id": "sc", "name": "Southcoast", "url": "http://10.5.1.9:8020"})
self.assertNotIn("new", cv.load(self.data)["list"]) # same Mac, now named: the old entry goes