diff options
author | Ethan Koenig <etk39@cornell.edu> | 2016-12-24 05:33:21 -0500 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2016-12-24 18:33:21 +0800 |
commit | d0932ef1473b9ce27474ccf24acfca106dd93fec (patch) | |
tree | 3dd05ef666f43ad9e32e6305793b18c3cbfbd0ca /models/issue.go | |
parent | 8a4161c72335900407b8f111027ad9ed53c0b631 (diff) | |
download | gitea-d0932ef1473b9ce27474ccf24acfca106dd93fec.tar.gz gitea-d0932ef1473b9ce27474ccf24acfca106dd93fec.zip |
Bug fixes for Issues filters (#413)
Correctly handle simultaneous assignee/poster filters, and conflicting assignee filters
Diffstat (limited to 'models/issue.go')
-rw-r--r-- | models/issue.go | 79 |
1 files changed, 29 insertions, 50 deletions
diff --git a/models/issue.go b/models/issue.go index 13d27b22c6..57490bbc5b 100644 --- a/models/issue.go +++ b/models/issue.go @@ -855,15 +855,14 @@ func GetIssueByID(id int64) (*Issue, error) { // IssuesOptions represents options of an issue. type IssuesOptions struct { - UserID int64 - AssigneeID int64 RepoID int64 + AssigneeID int64 PosterID int64 + MentionedID int64 MilestoneID int64 RepoIDs []int64 Page int IsClosed bool - IsMention bool IsPull bool Labels string SortType string @@ -887,10 +886,18 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) { if opts.AssigneeID > 0 { sess.And("issue.assignee_id=?", opts.AssigneeID) - } else if opts.PosterID > 0 { + } + + if opts.PosterID > 0 { sess.And("issue.poster_id=?", opts.PosterID) } + if opts.MentionedID > 0 { + sess.Join("INNER", "issue_user", "issue.id = issue_user.issue_id"). + And("issue_user.is_mentioned = ?", true). + And("issue_user.uid = ?", opts.MentionedID) + } + if opts.MilestoneID > 0 { sess.And("issue.milestone_id=?", opts.MilestoneID) } @@ -926,16 +933,6 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) { } } - if opts.IsMention { - sess. - Join("INNER", "issue_user", "issue.id = issue_user.issue_id"). - And("issue_user.is_mentioned = ?", true) - - if opts.UserID > 0 { - sess.And("issue_user.uid = ?", opts.UserID) - } - } - issues := make([]*Issue, 0, setting.UI.IssuePagingNum) if err := sess.Find(&issues); err != nil { return nil, fmt.Errorf("Find: %v", err) @@ -1156,11 +1153,11 @@ func parseCountResult(results []map[string][]byte) int64 { // IssueStatsOptions contains parameters accepted by GetIssueStats. type IssueStatsOptions struct { RepoID int64 - UserID int64 Labels string MilestoneID int64 AssigneeID int64 - FilterMode int + MentionedID int64 + PosterID int64 IsPull bool } @@ -1191,43 +1188,25 @@ func GetIssueStats(opts *IssueStatsOptions) *IssueStats { sess.And("assignee_id = ?", opts.AssigneeID) } - return sess - } - - switch opts.FilterMode { - case FilterModeAll, FilterModeAssign: - stats.OpenCount, _ = countSession(opts). - And("is_closed = ?", false). - Count(&Issue{}) + if opts.PosterID > 0 { + sess.And("poster_id = ?", opts.PosterID) + } - stats.ClosedCount, _ = countSession(opts). - And("is_closed = ?", true). - Count(&Issue{}) - case FilterModeCreate: - stats.OpenCount, _ = countSession(opts). - And("poster_id = ?", opts.UserID). - And("is_closed = ?", false). - Count(&Issue{}) - - stats.ClosedCount, _ = countSession(opts). - And("poster_id = ?", opts.UserID). - And("is_closed = ?", true). - Count(&Issue{}) - case FilterModeMention: - stats.OpenCount, _ = countSession(opts). - Join("INNER", "issue_user", "issue.id = issue_user.issue_id"). - And("issue_user.uid = ?", opts.UserID). - And("issue_user.is_mentioned = ?", true). - And("issue.is_closed = ?", false). - Count(&Issue{}) + if opts.MentionedID > 0 { + sess.Join("INNER", "issue_user", "issue.id = issue_user.issue_id"). + And("issue_user.uid = ?", opts.MentionedID). + And("issue_user.is_mentioned = ?", true) + } - stats.ClosedCount, _ = countSession(opts). - Join("INNER", "issue_user", "issue.id = issue_user.issue_id"). - And("issue_user.uid = ?", opts.UserID). - And("issue_user.is_mentioned = ?", true). - And("issue.is_closed = ?", true). - Count(&Issue{}) + return sess } + + stats.OpenCount, _ = countSession(opts). + And("is_closed = ?", false). + Count(&Issue{}) + stats.ClosedCount, _ = countSession(opts). + And("is_closed = ?", true). + Count(&Issue{}) return stats } |