From 3eb323901c6ec791294db492783e202558c2824f Mon Sep 17 00:00:00 2001 From: zeripath Date: Thu, 21 May 2020 02:15:30 +0100 Subject: [PATCH] Fix repo-list private and total count bugs (#11500) * Fix repo-list private and total count bugs Signed-off-by: Andrew Thornton * Ensure limited and private org public repos are displayed on "private" Signed-off-by: Andrew Thornton * switch from onlyPrivate to is_private Signed-off-by: Andrew Thornton * Generate swagger Signed-off-by: Andrew Thornton Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> --- models/repo_list.go | 16 +++----- routers/api/v1/repo/repo.go | 9 +++-- templates/swagger/v1_json.tmpl | 4 +- templates/user/dashboard/repolist.tmpl | 2 +- web_src/js/index.js | 54 ++++---------------------- 5 files changed, 23 insertions(+), 62 deletions(-) diff --git a/models/repo_list.go b/models/repo_list.go index 3e580a7229f..dea88d8816c 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -140,10 +140,13 @@ type SearchRepoOptions struct { PriorityOwnerID int64 OrderBy SearchOrderBy Private bool // Include private repositories in results - OnlyPrivate bool // Include only private repositories in results StarredByID int64 AllPublic bool // Include also all public repositories of users and public organisations AllLimited bool // Include also all public repositories of limited organisations + // None -> include public and private + // True -> include just private + // False -> incude just public + IsPrivate util.OptionalBool // None -> include collaborative AND non-collaborative // True -> include just collaborative // False -> incude just non-collaborative @@ -221,15 +224,8 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond { )))) } - if opts.OnlyPrivate { - cond = cond.And( - builder.Or( - builder.Eq{"is_private": true}, - builder.In("owner_id", builder.Select("id").From("`user`").Where( - builder.And( - builder.Eq{"type": UserTypeOrganization}, - builder.Or(builder.Eq{"visibility": structs.VisibleTypeLimited}, builder.Eq{"visibility": structs.VisibleTypePrivate}), - ))))) + if opts.IsPrivate != util.OptionalBoolNone { + cond = cond.And(builder.Eq{"is_private": opts.IsPrivate.IsTrue()}) } if opts.Template != util.OptionalBoolNone { diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index a724ebcc371..e5055daa2b1 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -78,9 +78,9 @@ func Search(ctx *context.APIContext) { // in: query // description: include private repositories this user has access to (defaults to true) // type: boolean - // - name: onlyPrivate + // - name: is_private // in: query - // description: only include private repositories this user has access to (defaults to false) + // description: show only pubic, private or all repositories (defaults to all) // type: boolean // - name: template // in: query @@ -133,7 +133,6 @@ func Search(ctx *context.APIContext) { TopicOnly: ctx.QueryBool("topic"), Collaborate: util.OptionalBoolNone, Private: ctx.IsSigned && (ctx.Query("private") == "" || ctx.QueryBool("private")), - OnlyPrivate: ctx.IsSigned && ctx.QueryBool("onlyPrivate"), Template: util.OptionalBoolNone, StarredByID: ctx.QueryInt64("starredBy"), IncludeDescription: ctx.QueryBool("includeDesc"), @@ -169,6 +168,10 @@ func Search(ctx *context.APIContext) { opts.Archived = util.OptionalBoolOf(ctx.QueryBool("archived")) } + if ctx.Query("is_private") != "" { + opts.IsPrivate = util.OptionalBoolOf(ctx.QueryBool("is_private")) + } + var sortMode = ctx.Query("sort") if len(sortMode) > 0 { var sortOrder = ctx.Query("order") diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index a6b24ed970f..b7fa714a646 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -1771,8 +1771,8 @@ }, { "type": "boolean", - "description": "only include private repositories this user has access to (defaults to false)", - "name": "onlyPrivate", + "description": "show only pubic, private or all repositories (defaults to all)", + "name": "is_private", "in": "query" }, { diff --git a/templates/user/dashboard/repolist.tmpl b/templates/user/dashboard/repolist.tmpl index dc1507403cd..93dda77d24a 100644 --- a/templates/user/dashboard/repolist.tmpl +++ b/templates/user/dashboard/repolist.tmpl @@ -101,7 +101,7 @@