aboutsummaryrefslogtreecommitdiffstats
path: root/models/issues/issue_search.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/issues/issue_search.go')
-rw-r--r--models/issues/issue_search.go39
1 files changed, 23 insertions, 16 deletions
diff --git a/models/issues/issue_search.go b/models/issues/issue_search.go
index 5948a67d4e..f1cd125d49 100644
--- a/models/issues/issue_search.go
+++ b/models/issues/issue_search.go
@@ -27,8 +27,8 @@ type IssuesOptions struct { //nolint
RepoIDs []int64 // overwrites RepoCond if the length is not 0
AllPublic bool // include also all public repositories
RepoCond builder.Cond
- AssigneeID int64
- PosterID int64
+ AssigneeID optional.Option[int64]
+ PosterID optional.Option[int64]
MentionedID int64
ReviewRequestedID int64
ReviewedID int64
@@ -231,15 +231,8 @@ func applyConditions(sess *xorm.Session, opts *IssuesOptions) {
sess.And("issue.is_closed=?", opts.IsClosed.Value())
}
- if opts.AssigneeID > 0 {
- applyAssigneeCondition(sess, opts.AssigneeID)
- } else if opts.AssigneeID == db.NoConditionID {
- sess.Where("issue.id NOT IN (SELECT issue_id FROM issue_assignees)")
- }
-
- if opts.PosterID > 0 {
- applyPosterCondition(sess, opts.PosterID)
- }
+ applyAssigneeCondition(sess, opts.AssigneeID)
+ applyPosterCondition(sess, opts.PosterID)
if opts.MentionedID > 0 {
applyMentionedCondition(sess, opts.MentionedID)
@@ -359,13 +352,27 @@ func issuePullAccessibleRepoCond(repoIDstr string, userID int64, org *organizati
return cond
}
-func applyAssigneeCondition(sess *xorm.Session, assigneeID int64) {
- sess.Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
- And("issue_assignees.assignee_id = ?", assigneeID)
+func applyAssigneeCondition(sess *xorm.Session, assigneeID optional.Option[int64]) {
+ // old logic: 0 is also treated as "not filtering assignee", because the "assignee" was read as FormInt64
+ if !assigneeID.Has() || assigneeID.Value() == 0 {
+ return
+ }
+ if assigneeID.Value() == db.NoConditionID {
+ sess.Where("issue.id NOT IN (SELECT issue_id FROM issue_assignees)")
+ } else {
+ sess.Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
+ And("issue_assignees.assignee_id = ?", assigneeID.Value())
+ }
}
-func applyPosterCondition(sess *xorm.Session, posterID int64) {
- sess.And("issue.poster_id=?", posterID)
+func applyPosterCondition(sess *xorm.Session, posterID optional.Option[int64]) {
+ if !posterID.Has() {
+ return
+ }
+ // poster doesn't need to support db.NoConditionID(-1), so just use the value as-is
+ if posterID.Has() {
+ sess.And("issue.poster_id=?", posterID.Value())
+ }
}
func applyMentionedCondition(sess *xorm.Session, mentionedID int64) {