Skip to content

Commit c0b5a84

Browse files
authored
Properly filter issue list given no assignees filter (#31522)
Quick fix #31520. This issue is related to #31337.
1 parent bbd1476 commit c0b5a84

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Diff for: modules/indexer/issues/dboptions.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ func ToSearchOptions(keyword string, opts *issues_model.IssuesOptions) *SearchOp
4444
searchOpt.ProjectID = optional.Some[int64](0) // Those issues with no project(projectid==0)
4545
}
4646

47+
if opts.AssigneeID > 0 {
48+
searchOpt.AssigneeID = optional.Some(opts.AssigneeID)
49+
} else if opts.AssigneeID == -1 { // FIXME: this is inconsistent from other places
50+
searchOpt.AssigneeID = optional.Some[int64](0)
51+
}
52+
4753
// See the comment of issues_model.SearchOptions for the reason why we need to convert
4854
convertID := func(id int64) optional.Option[int64] {
4955
if id > 0 {
@@ -57,7 +63,6 @@ func ToSearchOptions(keyword string, opts *issues_model.IssuesOptions) *SearchOp
5763

5864
searchOpt.ProjectColumnID = convertID(opts.ProjectColumnID)
5965
searchOpt.PosterID = convertID(opts.PosterID)
60-
searchOpt.AssigneeID = convertID(opts.AssigneeID)
6166
searchOpt.MentionID = convertID(opts.MentionedID)
6267
searchOpt.ReviewedID = convertID(opts.ReviewedID)
6368
searchOpt.ReviewRequestedID = convertID(opts.ReviewRequestedID)

Diff for: modules/indexer/issues/indexer_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99

1010
"code.gitea.io/gitea/models/db"
11+
"code.gitea.io/gitea/models/issues"
1112
"code.gitea.io/gitea/models/unittest"
1213
"code.gitea.io/gitea/modules/indexer/issues/internal"
1314
"code.gitea.io/gitea/modules/optional"
@@ -188,6 +189,11 @@ func searchIssueByID(t *testing.T) {
188189
},
189190
expectedIDs: []int64{6, 1},
190191
},
192+
{
193+
// NOTE: This tests no assignees filtering and also ToSearchOptions() to ensure it will set AssigneeID to 0 when it is passed as -1.
194+
opts: *ToSearchOptions("", &issues.IssuesOptions{AssigneeID: -1}),
195+
expectedIDs: []int64{22, 21, 16, 15, 14, 13, 12, 11, 20, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2},
196+
},
191197
{
192198
opts: SearchOptions{
193199
MentionID: optional.Some(int64(4)),

0 commit comments

Comments
 (0)