Skip to content

Commit 8e71f05

Browse files
kemzebGiteaBot
authored andcommitted
Properly filter issue list given no assignees filter (go-gitea#31522)
Quick fix go-gitea#31520. This issue is related to go-gitea#31337.
1 parent 17b0464 commit 8e71f05

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

modules/indexer/issues/dboptions.go

Lines changed: 6 additions & 1 deletion
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.ProjectBoardID = convertID(opts.ProjectBoardID)
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)

modules/indexer/issues/indexer_test.go

Lines changed: 6 additions & 0 deletions
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"
@@ -150,6 +151,11 @@ func searchIssueByID(t *testing.T) {
150151
},
151152
expectedIDs: []int64{6, 1},
152153
},
154+
{
155+
// NOTE: This tests no assignees filtering and also ToSearchOptions() to ensure it will set AssigneeID to 0 when it is passed as -1.
156+
opts: *ToSearchOptions("", &issues.IssuesOptions{AssigneeID: -1}),
157+
expectedIDs: []int64{22, 21, 16, 15, 14, 13, 12, 11, 20, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2},
158+
},
153159
{
154160
opts: SearchOptions{
155161
MentionID: optional.Some(int64(4)),

0 commit comments

Comments
 (0)