summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorEthan Koenig <etk39@cornell.edu>2016-12-24 05:33:21 -0500
committerLunny Xiao <xiaolunwen@gmail.com>2016-12-24 18:33:21 +0800
commitd0932ef1473b9ce27474ccf24acfca106dd93fec (patch)
tree3dd05ef666f43ad9e32e6305793b18c3cbfbd0ca /routers
parent8a4161c72335900407b8f111027ad9ed53c0b631 (diff)
downloadgitea-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 'routers')
-rw-r--r--routers/repo/issue.go84
-rw-r--r--routers/user/home.go1
2 files changed, 47 insertions, 38 deletions
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 343b93e273..14c1ea1aa7 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -130,38 +130,42 @@ func Issues(ctx *context.Context) {
var (
assigneeID = ctx.QueryInt64("assignee")
- posterID int64
+ posterID int64
+ mentionedID int64
+ forceEmpty bool
)
- filterMode := models.FilterModeAll
switch viewType {
case "assigned":
- filterMode = models.FilterModeAssign
- assigneeID = ctx.User.ID
+ if assigneeID > 0 && ctx.User.ID != assigneeID {
+ // two different assignees, must be empty
+ forceEmpty = true
+ } else {
+ assigneeID = ctx.User.ID
+ }
case "created_by":
- filterMode = models.FilterModeCreate
posterID = ctx.User.ID
case "mentioned":
- filterMode = models.FilterModeMention
- }
-
- var uid int64 = -1
- if ctx.IsSigned {
- uid = ctx.User.ID
+ mentionedID = ctx.User.ID
}
repo := ctx.Repo.Repository
selectLabels := ctx.Query("labels")
milestoneID := ctx.QueryInt64("milestone")
isShowClosed := ctx.Query("state") == "closed"
- issueStats := models.GetIssueStats(&models.IssueStatsOptions{
- RepoID: repo.ID,
- UserID: uid,
- Labels: selectLabels,
- MilestoneID: milestoneID,
- AssigneeID: assigneeID,
- FilterMode: filterMode,
- IsPull: isPullList,
- })
+
+ var issueStats *models.IssueStats
+ if forceEmpty {
+ issueStats = &models.IssueStats{}
+ } else {
+ issueStats = models.GetIssueStats(&models.IssueStatsOptions{
+ RepoID: repo.ID,
+ Labels: selectLabels,
+ MilestoneID: milestoneID,
+ AssigneeID: assigneeID,
+ MentionedID: mentionedID,
+ IsPull: isPullList,
+ })
+ }
page := ctx.QueryInt("page")
if page <= 1 {
@@ -177,22 +181,28 @@ func Issues(ctx *context.Context) {
pager := paginater.New(total, setting.UI.IssuePagingNum, page, 5)
ctx.Data["Page"] = pager
- issues, err := models.Issues(&models.IssuesOptions{
- UserID: uid,
- AssigneeID: assigneeID,
- RepoID: repo.ID,
- PosterID: posterID,
- MilestoneID: milestoneID,
- Page: pager.Current(),
- IsClosed: isShowClosed,
- IsMention: filterMode == models.FilterModeMention,
- IsPull: isPullList,
- Labels: selectLabels,
- SortType: sortType,
- })
- if err != nil {
- ctx.Handle(500, "Issues", err)
- return
+
+ var issues []*models.Issue
+ if forceEmpty {
+ issues = []*models.Issue{}
+ } else {
+ var err error
+ issues, err = models.Issues(&models.IssuesOptions{
+ AssigneeID: assigneeID,
+ RepoID: repo.ID,
+ PosterID: posterID,
+ MentionedID: mentionedID,
+ MilestoneID: milestoneID,
+ Page: pager.Current(),
+ IsClosed: isShowClosed,
+ IsPull: isPullList,
+ Labels: selectLabels,
+ SortType: sortType,
+ })
+ if err != nil {
+ ctx.Handle(500, "Issues", err)
+ return
+ }
}
// Get issue-user relations.
@@ -233,7 +243,7 @@ func Issues(ctx *context.Context) {
return
}
- if viewType == "assigned" {
+ if ctx.QueryInt64("assignee") == 0 {
assigneeID = 0 // Reset ID to prevent unexpected selection of assignee.
}
diff --git a/routers/user/home.go b/routers/user/home.go
index 513dd9ce06..571849df30 100644
--- a/routers/user/home.go
+++ b/routers/user/home.go
@@ -272,7 +272,6 @@ func Issues(ctx *context.Context) {
// Get issues.
issues, err := models.Issues(&models.IssuesOptions{
- UserID: ctxUser.ID,
AssigneeID: assigneeID,
RepoID: repoID,
PosterID: posterID,