From 8e71f05af4127968b9d6fbc440e7557553c3a9d0 Mon Sep 17 00:00:00 2001 From: Kemal Zebari <60799661+kemzeb@users.noreply.github.com> Date: Tue, 23 Jul 2024 11:36:32 -0700 Subject: [PATCH] Properly filter issue list given no assignees filter (#31522) Quick fix #31520. This issue is related to #31337. --- modules/indexer/issues/dboptions.go | 7 ++++++- modules/indexer/issues/indexer_test.go | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/indexer/issues/dboptions.go b/modules/indexer/issues/dboptions.go index c323e3588e002..96328455dfea0 100644 --- a/modules/indexer/issues/dboptions.go +++ b/modules/indexer/issues/dboptions.go @@ -44,6 +44,12 @@ func ToSearchOptions(keyword string, opts *issues_model.IssuesOptions) *SearchOp searchOpt.ProjectID = optional.Some[int64](0) // Those issues with no project(projectid==0) } + if opts.AssigneeID > 0 { + searchOpt.AssigneeID = optional.Some(opts.AssigneeID) + } else if opts.AssigneeID == -1 { // FIXME: this is inconsistent from other places + searchOpt.AssigneeID = optional.Some[int64](0) + } + // See the comment of issues_model.SearchOptions for the reason why we need to convert convertID := func(id int64) optional.Option[int64] { if id > 0 { @@ -57,7 +63,6 @@ func ToSearchOptions(keyword string, opts *issues_model.IssuesOptions) *SearchOp searchOpt.ProjectBoardID = convertID(opts.ProjectBoardID) searchOpt.PosterID = convertID(opts.PosterID) - searchOpt.AssigneeID = convertID(opts.AssigneeID) searchOpt.MentionID = convertID(opts.MentionedID) searchOpt.ReviewedID = convertID(opts.ReviewedID) searchOpt.ReviewRequestedID = convertID(opts.ReviewRequestedID) diff --git a/modules/indexer/issues/indexer_test.go b/modules/indexer/issues/indexer_test.go index 0d0cfc851697d..378616ce63c45 100644 --- a/modules/indexer/issues/indexer_test.go +++ b/modules/indexer/issues/indexer_test.go @@ -8,6 +8,7 @@ import ( "testing" "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/models/issues" "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/modules/indexer/issues/internal" "code.gitea.io/gitea/modules/optional" @@ -150,6 +151,11 @@ func searchIssueByID(t *testing.T) { }, expectedIDs: []int64{6, 1}, }, + { + // NOTE: This tests no assignees filtering and also ToSearchOptions() to ensure it will set AssigneeID to 0 when it is passed as -1. + opts: *ToSearchOptions("", &issues.IssuesOptions{AssigneeID: -1}), + expectedIDs: []int64{22, 21, 16, 15, 14, 13, 12, 11, 20, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2}, + }, { opts: SearchOptions{ MentionID: optional.Some(int64(4)),