fix(monitors): stop selecting more regions than the limit allows
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 6m31s
ci / test (pull_request) Successful in 13m28s
ci / build (pull_request) Successful in 10m23s
ci / image (pull_request) Successful in 5m51s
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 6m31s
ci / test (pull_request) Successful in 13m28s
ci / build (pull_request) Successful in 10m23s
ci / image (pull_request) Successful in 5m51s
The monitor form let users tick any number of regions and only the save failed with the region limit. The form now knows the organization's regions-per-monitor limit: it says how many regions a monitor may use, counts the ticked ones, and once the limit is reached locks the other regions that count towards it, in the list and on the map, until one is unticked. Own regions stay free unless they count. The server still enforces the limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
e9984f8271
commit
3a7bed5a3e
9 files changed
+1383
-1187
No files matched your search
@@ -941,6 +941,8 @@ func (s *Server) monitorEditor(c *gin.Context, p *principal, page web.Page, me w
|
||||
checked := slices.Contains(assigned, r.ID) || (idParam == "" && i == 0)
|
||||
f.Regions = append(f.Regions, web.RegionOption{ID: r.ID.String(), Name: r.Name, Own: r.OrgID != nil, Checked: checked, Live: live, Lat: r.Latitude, Lon: r.Longitude})
|
||||
}
|
||||
limits := s.orgLimits(ctx, p.Org)
|
||||
f.RegionLimit, f.OwnRegionsCount = limits.RegionsPerMonitor, limits.OwnRegionsCount
|
||||
t, err := s.loadGroupTree(ctx, p.scope())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -52,6 +52,22 @@ func TestLimits(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// The monitor form locks regions beyond the limit; own ones do not count.
|
||||
_, _, html := owner.page("/monitors/new")
|
||||
if !strings.Contains(html, `data-region-limit="1"`) {
|
||||
t.Error("monitor form lacks the region limit")
|
||||
}
|
||||
for id, counted := range map[string]bool{p1: true, o1: false} {
|
||||
i := strings.Index(html, `value="`+id+`"`)
|
||||
if i < 0 {
|
||||
t.Fatalf("monitor form lacks region %s", id)
|
||||
}
|
||||
tag := html[i : i+strings.Index(html[i:], ">")]
|
||||
if strings.Contains(tag, "data-counted") != counted {
|
||||
t.Errorf("region %s counted = %v, want %v", id, !counted, counted)
|
||||
}
|
||||
}
|
||||
|
||||
// Monitors, passive ones included.
|
||||
if st, body := owner.do("POST", "/api/v1/org/monitors", map[string]any{"name": "hb", "type": "heartbeat", "interval_seconds": 3600}); st != http.StatusCreated {
|
||||
t.Fatalf("heartbeat = %d %v", st, body)
|
||||
|
||||
Reference in new issue
Block a user