From d3827d51bf4ac8ac9ae98149933f1f6b34d228aa Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Wed, 9 Apr 2025 13:21:52 +0200 Subject: syz-cluster: filter by series with findings Add a checkbox to only display the series for which there are findings. --- syz-cluster/dashboard/handler.go | 9 +++++---- syz-cluster/dashboard/templates/index.html | 7 +++++++ syz-cluster/pkg/db/series_repo.go | 13 +++++++++---- syz-cluster/pkg/db/series_repo_test.go | 7 +++++++ 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/syz-cluster/dashboard/handler.go b/syz-cluster/dashboard/handler.go index 318705e7f..fe9129373 100644 --- a/syz-cluster/dashboard/handler.go +++ b/syz-cluster/dashboard/handler.go @@ -100,10 +100,11 @@ func (h *dashboardHandler) seriesList(w http.ResponseWriter, r *http.Request) er baseURL := r.URL.RequestURI() data := MainPageData{ Filter: db.SeriesFilter{ - Cc: r.FormValue("cc"), - Status: db.SessionStatus(r.FormValue("status")), - Limit: perPage, - Offset: offset, + Cc: r.FormValue("cc"), + Status: db.SessionStatus(r.FormValue("status")), + WithFindings: r.FormValue("with_findings") != "", + Limit: perPage, + Offset: offset, }, // If the filters are changed, the old offset value is irrelevant. FilterFormURL: urlutil.DropParam(baseURL, "offset", ""), diff --git a/syz-cluster/dashboard/templates/index.html b/syz-cluster/dashboard/templates/index.html index c87285b58..d5f5102b0 100644 --- a/syz-cluster/dashboard/templates/index.html +++ b/syz-cluster/dashboard/templates/index.html @@ -15,6 +15,13 @@ {{end}} +
+ + +
diff --git a/syz-cluster/pkg/db/series_repo.go b/syz-cluster/pkg/db/series_repo.go index 5f414b7cc..00043f1a8 100644 --- a/syz-cluster/pkg/db/series_repo.go +++ b/syz-cluster/pkg/db/series_repo.go @@ -133,10 +133,11 @@ type SeriesWithSession struct { } type SeriesFilter struct { - Cc string - Status SessionStatus - Limit int - Offset int + Cc string + Status SessionStatus + WithFindings bool + Limit int + Offset int } // ListLatest() returns the list of series ordered by the decreasing PublishedAt value. @@ -174,6 +175,10 @@ func (repo *SeriesRepository) ListLatest(ctx context.Context, filter SeriesFilte } stmt.SQL += ")" } + if filter.WithFindings { + stmt.SQL += " AND Series.LatestSessionID IS NOT NULL " + + "AND EXISTS(SELECT 1 FROM Findings WHERE Findings.SessionID = Series.LatestSessionID)" + } stmt.SQL += " ORDER BY PublishedAt DESC, ID" if filter.Limit > 0 { stmt.SQL += " LIMIT @limit" diff --git a/syz-cluster/pkg/db/series_repo_test.go b/syz-cluster/pkg/db/series_repo_test.go index ca84b70a8..ab13b8e12 100644 --- a/syz-cluster/pkg/db/series_repo_test.go +++ b/syz-cluster/pkg/db/series_repo_test.go @@ -153,6 +153,13 @@ func TestSeriesRepositoryList(t *testing.T) { assert.Len(t, list, 1) assert.Equal(t, 1, list[0].Findings, "there must be just one finding") }) + + t.Run("query_with_findings", func(t *testing.T) { + list, err := repo.ListLatest(ctx, SeriesFilter{WithFindings: true}, time.Time{}) + assert.NoError(t, err) + assert.Len(t, list, 1) + assert.Equal(t, "Series 2", list[0].Series.Title) + }) } func TestSeriesRepositoryUpdate(t *testing.T) { -- cgit mrf-deployment