Skip to content

Commit a15a644

Browse files
6543lunny
authored andcommitted
[BugFix] Hide public repos owned by private orgs (#9616)
1 parent 2ccd924 commit a15a644

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

models/repo_list.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ type SearchRepoOptions struct {
120120
StarredByID int64
121121
Page int
122122
IsProfile bool
123-
AllPublic bool // Include also all public repositories
123+
AllPublic bool // Include also all public repositories of users and public organisations
124+
AllLimited bool // Include also all public repositories of limited organisations
124125
PageSize int // Can be smaller than or equal to setting.ExplorePagingNum
125126
// None -> include collaborative AND non-collaborative
126127
// True -> include just collaborative
@@ -240,7 +241,11 @@ func SearchRepository(opts *SearchRepoOptions) (RepositoryList, int64, error) {
240241
}
241242

242243
if opts.AllPublic {
243-
accessCond = accessCond.Or(builder.Eq{"is_private": false})
244+
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}))))
245+
}
246+
247+
if opts.AllLimited {
248+
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}))))
244249
}
245250

246251
cond = cond.And(accessCond)

models/repo_list_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ func TestSearchRepository(t *testing.T) {
177177
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, AllPublic: true},
178178
count: 22},
179179
{name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative",
180-
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, Private: true, AllPublic: true},
181-
count: 28},
180+
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, Private: true, AllPublic: true, AllLimited: true},
181+
count: 27},
182182
{name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName",
183183
opts: &SearchRepoOptions{Keyword: "test", Page: 1, PageSize: 10, OwnerID: 15, Private: true, AllPublic: true},
184184
count: 15},

routers/home.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
141141
Keyword: keyword,
142142
OwnerID: opts.OwnerID,
143143
AllPublic: true,
144+
AllLimited: true,
144145
TopicOnly: topicOnly,
145146
IncludeDescription: setting.UI.SearchRepoDescription,
146147
})

0 commit comments

Comments
 (0)