Skip to content

Commit 133ae18

Browse files
6543zeripath
authored andcommitted
[BugFix] Hide public repos owned by private orgs (#9609)
* Restrict AllPublic to actually public repos. * Add new parameter to add in AllLimited Repos
1 parent 7e4f490 commit 133ae18

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

models/repo_list.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ type SearchRepoOptions struct {
121121
StarredByID int64
122122
Page int
123123
IsProfile bool
124-
AllPublic bool // Include also all public repositories
124+
AllPublic bool // Include also all public repositories of users and public organisations
125+
AllLimited bool // Include also all public repositories of limited organisations
125126
PageSize int // Can be smaller than or equal to setting.ExplorePagingNum
126127
// None -> include collaborative AND non-collaborative
127128
// True -> include just collaborative
@@ -228,7 +229,11 @@ func SearchRepository(opts *SearchRepoOptions) (RepositoryList, int64, error) {
228229
}
229230

230231
if opts.AllPublic {
231-
accessCond = accessCond.Or(builder.Eq{"is_private": false})
232+
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}))))
233+
}
234+
235+
if opts.AllLimited {
236+
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}))))
232237
}
233238

234239
cond = cond.And(accessCond)

models/repo_list_test.go

+2-2
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, Template: util.OptionalBoolFalse},
178178
count: 25},
179179
{name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative",
180-
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, Private: true, AllPublic: true, Template: util.OptionalBoolFalse},
181-
count: 31},
180+
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, Private: true, AllPublic: true, AllLimited: true, Template: util.OptionalBoolFalse},
181+
count: 30},
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

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
142142
Keyword: keyword,
143143
OwnerID: opts.OwnerID,
144144
AllPublic: true,
145+
AllLimited: true,
145146
TopicOnly: topicOnly,
146147
IncludeDescription: setting.UI.SearchRepoDescription,
147148
})

0 commit comments

Comments
 (0)