From ad545e74beb4ceead9b80c1dc70b3668f6e05534 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Fri, 24 Feb 2023 17:56:03 +0800 Subject: [PATCH 1/2] add isAdmin param to RenderRepoSearch --- routers/web/admin/repos.go | 2 +- routers/web/explore/repo.go | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/routers/web/admin/repos.go b/routers/web/admin/repos.go index dc5432c54998c..17ac253be50e9 100644 --- a/routers/web/admin/repos.go +++ b/routers/web/admin/repos.go @@ -36,7 +36,7 @@ func Repos(ctx *context.Context) { Private: true, PageSize: setting.UI.Admin.RepoPagingNum, TplName: tplRepos, - }) + }, true) } // DeleteRepo delete one repository diff --git a/routers/web/explore/repo.go b/routers/web/explore/repo.go index e9684dd2865d4..77de2f6cbf9b3 100644 --- a/routers/web/explore/repo.go +++ b/routers/web/explore/repo.go @@ -31,7 +31,9 @@ type RepoSearchOptions struct { } // RenderRepoSearch render repositories search page -func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { +// This function is also used to render the Admin Repository Management page. +// The isAdmin param should be set to true when rendering the Admin page. +func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions, isAdmin bool) { // Sitemap index for sitemap paths page := int(ctx.ParamsInt64("idx")) isSitemap := ctx.Params("idx") != "" @@ -84,7 +86,9 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { orderBy = db.SearchOrderByRecentUpdated } - onlyShowRelevant = !ctx.FormBool(relevantReposOnlyParam) + if !isAdmin { + onlyShowRelevant = !ctx.FormBool(relevantReposOnlyParam) + } keyword := ctx.FormTrim("q") @@ -162,5 +166,5 @@ func Repos(ctx *context.Context) { OwnerID: ownerID, Private: ctx.Doer != nil, TplName: tplExploreRepos, - }) + }, false) } From 971cf6267fe285c740ca42ff5e6f0fe85d2422cd Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Fri, 24 Feb 2023 14:21:38 +0000 Subject: [PATCH 2/2] Move OnlyShowRelevant in to RepoSearchOptions Signed-off-by: Andrew Thornton --- routers/web/admin/repos.go | 9 ++++---- routers/web/explore/repo.go | 41 +++++++++++++++++-------------------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/routers/web/admin/repos.go b/routers/web/admin/repos.go index 17ac253be50e9..1c4754f6d8a3e 100644 --- a/routers/web/admin/repos.go +++ b/routers/web/admin/repos.go @@ -33,10 +33,11 @@ func Repos(ctx *context.Context) { ctx.Data["PageIsAdminRepositories"] = true explore.RenderRepoSearch(ctx, &explore.RepoSearchOptions{ - Private: true, - PageSize: setting.UI.Admin.RepoPagingNum, - TplName: tplRepos, - }, true) + Private: true, + PageSize: setting.UI.Admin.RepoPagingNum, + TplName: tplRepos, + OnlyShowRelevant: false, + }) } // DeleteRepo delete one repository diff --git a/routers/web/explore/repo.go b/routers/web/explore/repo.go index 77de2f6cbf9b3..058971b9b89e4 100644 --- a/routers/web/explore/repo.go +++ b/routers/web/explore/repo.go @@ -23,17 +23,18 @@ const ( // RepoSearchOptions when calling search repositories type RepoSearchOptions struct { - OwnerID int64 - Private bool - Restricted bool - PageSize int - TplName base.TplName + OwnerID int64 + Private bool + Restricted bool + PageSize int + OnlyShowRelevant bool + TplName base.TplName } // RenderRepoSearch render repositories search page // This function is also used to render the Admin Repository Management page. // The isAdmin param should be set to true when rendering the Admin page. -func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions, isAdmin bool) { +func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { // Sitemap index for sitemap paths page := int(ctx.ParamsInt64("idx")) isSitemap := ctx.Params("idx") != "" @@ -50,11 +51,10 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions, isAdmin boo } var ( - repos []*repo_model.Repository - count int64 - err error - orderBy db.SearchOrderBy - onlyShowRelevant bool + repos []*repo_model.Repository + count int64 + err error + orderBy db.SearchOrderBy ) ctx.Data["SortType"] = ctx.FormString("sort") @@ -86,13 +86,9 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions, isAdmin boo orderBy = db.SearchOrderByRecentUpdated } - if !isAdmin { - onlyShowRelevant = !ctx.FormBool(relevantReposOnlyParam) - } - keyword := ctx.FormTrim("q") - ctx.Data["OnlyShowRelevant"] = onlyShowRelevant + ctx.Data["OnlyShowRelevant"] = opts.OnlyShowRelevant topicOnly := ctx.FormBool("topic") ctx.Data["TopicOnly"] = topicOnly @@ -115,7 +111,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions, isAdmin boo TopicOnly: topicOnly, Language: language, IncludeDescription: setting.UI.SearchRepoDescription, - OnlyShowRelevant: onlyShowRelevant, + OnlyShowRelevant: opts.OnlyShowRelevant, }) if err != nil { ctx.ServerError("SearchRepository", err) @@ -162,9 +158,10 @@ func Repos(ctx *context.Context) { } RenderRepoSearch(ctx, &RepoSearchOptions{ - PageSize: setting.UI.ExplorePagingNum, - OwnerID: ownerID, - Private: ctx.Doer != nil, - TplName: tplExploreRepos, - }, false) + PageSize: setting.UI.ExplorePagingNum, + OwnerID: ownerID, + Private: ctx.Doer != nil, + TplName: tplExploreRepos, + OnlyShowRelevant: !ctx.FormBool(relevantReposOnlyParam), + }) }