Skip to content

Commit

Permalink
Properly filter issue list given no assignees filter (go-gitea#31522)
Browse files Browse the repository at this point in the history
Quick fix go-gitea#31520. This issue is related to go-gitea#31337.
  • Loading branch information
kemzeb authored and GiteaBot committed Jul 23, 2024
1 parent 17b0464 commit 8e71f05
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion modules/indexer/issues/dboptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions modules/indexer/issues/indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)),
Expand Down

0 comments on commit 8e71f05

Please sign in to comment.