From 9cc5a89b8c8654e3e40686323572e69300807629 Mon Sep 17 00:00:00 2001 From: Jimmy Praet Date: Sun, 3 Jan 2021 18:29:12 +0100 Subject: [PATCH] Issue and pull request filters on organization dashboard #14052 (#14072) --- routers/user/home.go | 53 ++++++++++++++++------------ templates/user/dashboard/issues.tmpl | 26 +++++++------- 2 files changed, 43 insertions(+), 36 deletions(-) diff --git a/routers/user/home.go b/routers/user/home.go index 351af1c0d99..952f5cdb3a3 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -364,21 +364,17 @@ func Issues(ctx *context.Context) { filterMode = models.FilterModeAll ) - if ctxUser.IsOrganization() { + viewType = ctx.Query("type") + switch viewType { + case "assigned": + filterMode = models.FilterModeAssign + case "created_by": + filterMode = models.FilterModeCreate + case "mentioned": + filterMode = models.FilterModeMention + case "your_repositories": // filterMode already set to All + default: viewType = "your_repositories" - } else { - viewType = ctx.Query("type") - switch viewType { - case "assigned": - filterMode = models.FilterModeAssign - case "created_by": - filterMode = models.FilterModeCreate - case "mentioned": - filterMode = models.FilterModeMention - case "your_repositories": // filterMode already set to All - default: - viewType = "your_repositories" - } } page := ctx.QueryInt("page") @@ -453,11 +449,15 @@ func Issues(ctx *context.Context) { case models.FilterModeAll: opts.RepoIDs = userRepoIDs case models.FilterModeAssign: - opts.AssigneeID = ctxUser.ID + opts.AssigneeID = ctx.User.ID case models.FilterModeCreate: - opts.PosterID = ctxUser.ID + opts.PosterID = ctx.User.ID case models.FilterModeMention: - opts.MentionedID = ctxUser.ID + opts.MentionedID = ctx.User.ID + } + + if ctxUser.IsOrganization() { + opts.RepoIDs = userRepoIDs } var forceEmpty bool @@ -575,7 +575,7 @@ func Issues(ctx *context.Context) { } userIssueStatsOpts := models.UserIssueStatsOptions{ - UserID: ctxUser.ID, + UserID: ctx.User.ID, UserRepoIDs: userRepoIDs, FilterMode: filterMode, IsPull: isPullList, @@ -585,6 +585,9 @@ func Issues(ctx *context.Context) { if len(repoIDs) > 0 { userIssueStatsOpts.UserRepoIDs = repoIDs } + if ctxUser.IsOrganization() { + userIssueStatsOpts.RepoIDs = userRepoIDs + } userIssueStats, err := models.GetUserIssueStats(userIssueStatsOpts) if err != nil { ctx.ServerError("GetUserIssueStats User", err) @@ -594,7 +597,7 @@ func Issues(ctx *context.Context) { var shownIssueStats *models.IssueStats if !forceEmpty { statsOpts := models.UserIssueStatsOptions{ - UserID: ctxUser.ID, + UserID: ctx.User.ID, UserRepoIDs: userRepoIDs, FilterMode: filterMode, IsPull: isPullList, @@ -604,6 +607,8 @@ func Issues(ctx *context.Context) { } if len(repoIDs) > 0 { statsOpts.RepoIDs = repoIDs + } else if ctxUser.IsOrganization() { + statsOpts.RepoIDs = userRepoIDs } shownIssueStats, err = models.GetUserIssueStats(statsOpts) if err != nil { @@ -616,15 +621,19 @@ func Issues(ctx *context.Context) { var allIssueStats *models.IssueStats if !forceEmpty { - allIssueStats, err = models.GetUserIssueStats(models.UserIssueStatsOptions{ - UserID: ctxUser.ID, + allIssueStatsOpts := models.UserIssueStatsOptions{ + UserID: ctx.User.ID, UserRepoIDs: userRepoIDs, FilterMode: filterMode, IsPull: isPullList, IsClosed: isShowClosed, IssueIDs: issueIDsFromSearch, LabelIDs: opts.LabelIDs, - }) + } + if ctxUser.IsOrganization() { + allIssueStatsOpts.RepoIDs = userRepoIDs + } + allIssueStats, err = models.GetUserIssueStats(allIssueStatsOpts) if err != nil { ctx.ServerError("GetUserIssueStats All", err) return diff --git a/templates/user/dashboard/issues.tmpl b/templates/user/dashboard/issues.tmpl index b8625ec2c15..62428dce423 100644 --- a/templates/user/dashboard/issues.tmpl +++ b/templates/user/dashboard/issues.tmpl @@ -9,20 +9,18 @@ {{.i18n.Tr "home.issues.in_your_repos"}} {{CountFmt .IssueStats.YourRepositoriesCount}} - {{if not .ContextUser.IsOrganization}} - - {{.i18n.Tr "repo.issues.filter_type.assigned_to_you"}} - {{CountFmt .IssueStats.AssignCount}} - - - {{.i18n.Tr "repo.issues.filter_type.created_by_you"}} - {{CountFmt .IssueStats.CreateCount}} - - - {{.i18n.Tr "repo.issues.filter_type.mentioning_you"}} - {{CountFmt .IssueStats.MentionCount}} - - {{end}} + + {{.i18n.Tr "repo.issues.filter_type.assigned_to_you"}} + {{CountFmt .IssueStats.AssignCount}} + + + {{.i18n.Tr "repo.issues.filter_type.created_by_you"}} + {{CountFmt .IssueStats.CreateCount}} + + + {{.i18n.Tr "repo.issues.filter_type.mentioning_you"}} + {{CountFmt .IssueStats.MentionCount}} +
All