From a15a644c05d1211e6e306ec2b5f44f71fea4ea24 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 6 Jan 2020 03:12:55 +0100 Subject: [PATCH] [BugFix] Hide public repos owned by private orgs (#9616) --- models/repo_list.go | 9 +++++++-- models/repo_list_test.go | 4 ++-- routers/home.go | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/models/repo_list.go b/models/repo_list.go index 692d4d002..77efb090a 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -120,7 +120,8 @@ type SearchRepoOptions struct { StarredByID int64 Page int IsProfile bool - AllPublic bool // Include also all public repositories + AllPublic bool // Include also all public repositories of users and public organisations + AllLimited bool // Include also all public repositories of limited organisations PageSize int // Can be smaller than or equal to setting.ExplorePagingNum // None -> include collaborative AND non-collaborative // True -> include just collaborative @@ -240,7 +241,11 @@ func SearchRepository(opts *SearchRepoOptions) (RepositoryList, int64, error) { } if opts.AllPublic { - accessCond = accessCond.Or(builder.Eq{"is_private": false}) + accessCond = accessCond.Or(builder.Eq{"is_private": false}.And(builder.In("owner_id", builder.Select("`user`.id").From("`user`").Where(builder.Eq{"`user`.visibility": structs.VisibleTypePublic})))) + } + + if opts.AllLimited { + accessCond = accessCond.Or(builder.Eq{"is_private": false}.And(builder.In("owner_id", builder.Select("`user`.id").From("`user`").Where(builder.Eq{"`user`.visibility": structs.VisibleTypeLimited})))) } cond = cond.And(accessCond) diff --git a/models/repo_list_test.go b/models/repo_list_test.go index e3a7acd4a..836996cac 100644 --- a/models/repo_list_test.go +++ b/models/repo_list_test.go @@ -177,8 +177,8 @@ func TestSearchRepository(t *testing.T) { opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, AllPublic: true}, count: 22}, {name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative", - opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, Private: true, AllPublic: true}, - count: 28}, + opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, Private: true, AllPublic: true, AllLimited: true}, + count: 27}, {name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName", opts: &SearchRepoOptions{Keyword: "test", Page: 1, PageSize: 10, OwnerID: 15, Private: true, AllPublic: true}, count: 15}, diff --git a/routers/home.go b/routers/home.go index eddff28ee..97d5cbf33 100644 --- a/routers/home.go +++ b/routers/home.go @@ -141,6 +141,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { Keyword: keyword, OwnerID: opts.OwnerID, AllPublic: true, + AllLimited: true, TopicOnly: topicOnly, IncludeDescription: setting.UI.SearchRepoDescription, })