1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-24 08:57:03 -05:00

Fix project filter bugs (#26490) (#26558)

Backport  #26490

related: #26012

1. missing project filter on the issue page.

1e76a824bc/modules/indexer/issues/dboptions.go (L11-L15)
2. incorrect SQL condition: some issue does not belong to a project but
exists on the project_issue table.

f5dbac9d36/models/issues/issue_search.go (L233)

![before](https://github.com/go-gitea/gitea/assets/50507092/1dcde39e-3e2f-4151-b2c6-4d67bf493c2f)

![after](https://github.com/go-gitea/gitea/assets/50507092/badfb81f-056d-4a2f-9838-1cba9c15768d)

(cherry picked from commit 94f86964b4)
This commit is contained in:
CaiCandong 2023-08-19 18:21:45 +08:00 committed by Earl Warren
parent c8f437b316
commit 28acd6e262
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
2 changed files with 14 additions and 10 deletions

View file

@ -155,6 +155,18 @@ func applyMilestoneCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Sess
return sess return sess
} }
func applyProjectCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
if opts.ProjectID > 0 { // specific project
sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id").
And("project_issue.project_id=?", opts.ProjectID)
} else if opts.ProjectID == db.NoConditionID { // show those that are in no project
sess.And(builder.NotIn("issue.id", builder.Select("issue_id").From("project_issue").And(builder.Neq{"project_id": 0})))
}
// opts.ProjectID == 0 means all projects,
// do not need to apply any condition
return sess
}
func applyRepoConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session { func applyRepoConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
if len(opts.RepoIDs) == 1 { if len(opts.RepoIDs) == 1 {
opts.RepoCond = builder.Eq{"issue.repo_id": opts.RepoIDs[0]} opts.RepoCond = builder.Eq{"issue.repo_id": opts.RepoIDs[0]}
@ -213,12 +225,7 @@ func applyConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
sess.And(builder.Lte{"issue.updated_unix": opts.UpdatedBeforeUnix}) sess.And(builder.Lte{"issue.updated_unix": opts.UpdatedBeforeUnix})
} }
if opts.ProjectID > 0 { applyProjectCondition(sess, opts)
sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id").
And("project_issue.project_id=?", opts.ProjectID)
} else if opts.ProjectID == db.NoConditionID { // show those that are in no project
sess.And(builder.NotIn("issue.id", builder.Select("issue_id").From("project_issue")))
}
if opts.ProjectBoardID != 0 { if opts.ProjectBoardID != 0 {
if opts.ProjectBoardID > 0 { if opts.ProjectBoardID > 0 {

View file

@ -133,10 +133,7 @@ func getIssueStatsChunk(opts *IssuesOptions, issueIDs []int64) (*IssueStats, err
applyMilestoneCondition(sess, opts) applyMilestoneCondition(sess, opts)
if opts.ProjectID > 0 { applyProjectCondition(sess, opts)
sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id").
And("project_issue.project_id=?", opts.ProjectID)
}
if opts.AssigneeID > 0 { if opts.AssigneeID > 0 {
applyAssigneeCondition(sess, opts.AssigneeID) applyAssigneeCondition(sess, opts.AssigneeID)