2

Simplify the dashboard recent IP view

This commit is contained in:
2026-03-12 02:15:45 +01:00
parent 7bd3933215
commit a82421ba3f
8 changed files with 404 additions and 57 deletions

View File

@@ -76,6 +76,23 @@ func (s *Service) ListIPs(ctx context.Context, limit int, state string) ([]model
return s.store.ListIPStates(ctx, limit, state)
}
func (s *Service) ListRecentIPs(ctx context.Context, since time.Time, limit int) ([]model.RecentIPRow, error) {
items, err := s.store.ListRecentIPRows(ctx, since, limit)
if err != nil {
return nil, err
}
for index := range items {
state := model.IPState{
IP: items[index].IP,
State: items[index].State,
ManualOverride: items[index].ManualOverride,
}
backend := s.resolveOPNsenseStatus(ctx, state)
items[index].Actions = actionAvailability(state, backend)
}
return items, nil
}
func (s *Service) GetIPDetails(ctx context.Context, ip string) (model.IPDetails, error) {
normalized, err := normalizeIP(ip)
if err != nil {

View File

@@ -126,6 +126,21 @@ sources:
t.Fatalf("expected observed state, got %+v", observedState)
}
recentRows, err := svc.ListRecentIPs(context.Background(), time.Now().UTC().Add(-time.Hour), 10)
if err != nil {
t.Fatalf("list recent ips: %v", err)
}
blockedRow, found := findRecentIPRow(recentRows, "203.0.113.10")
if !found {
t.Fatalf("expected blocked IP row in recent rows: %+v", recentRows)
}
if blockedRow.SourceName != "main" || blockedRow.Events != 1 {
t.Fatalf("unexpected blocked recent row: %+v", blockedRow)
}
if !blockedRow.Actions.CanUnblock || blockedRow.Actions.CanBlock {
t.Fatalf("unexpected blocked recent row actions: %+v", blockedRow.Actions)
}
if err := svc.ForceAllow(context.Background(), "203.0.113.10", "test", "manual unblock"); err != nil {
t.Fatalf("force allow: %v", err)
}
@@ -245,3 +260,12 @@ func waitFor(t *testing.T, timeout time.Duration, condition func() bool) {
}
t.Fatalf("condition was not met within %s", timeout)
}
func findRecentIPRow(items []model.RecentIPRow, ip string) (model.RecentIPRow, bool) {
for _, item := range items {
if item.IP == ip {
return item, true
}
}
return model.RecentIPRow{}, false
}