[BugFix] Hide public repos owned by private orgs (#9616)
This commit is contained in:
parent
2ccd92407a
commit
a15a644c05
3 changed files with 10 additions and 4 deletions
|
@ -120,7 +120,8 @@ type SearchRepoOptions struct {
|
||||||
StarredByID int64
|
StarredByID int64
|
||||||
Page int
|
Page int
|
||||||
IsProfile bool
|
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
|
PageSize int // Can be smaller than or equal to setting.ExplorePagingNum
|
||||||
// None -> include collaborative AND non-collaborative
|
// None -> include collaborative AND non-collaborative
|
||||||
// True -> include just collaborative
|
// True -> include just collaborative
|
||||||
|
@ -240,7 +241,11 @@ func SearchRepository(opts *SearchRepoOptions) (RepositoryList, int64, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.AllPublic {
|
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)
|
cond = cond.And(accessCond)
|
||||||
|
|
|
@ -177,8 +177,8 @@ func TestSearchRepository(t *testing.T) {
|
||||||
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, AllPublic: true},
|
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, AllPublic: true},
|
||||||
count: 22},
|
count: 22},
|
||||||
{name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative",
|
{name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative",
|
||||||
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, Private: true, AllPublic: true},
|
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, Private: true, AllPublic: true, AllLimited: true},
|
||||||
count: 28},
|
count: 27},
|
||||||
{name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName",
|
{name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName",
|
||||||
opts: &SearchRepoOptions{Keyword: "test", Page: 1, PageSize: 10, OwnerID: 15, Private: true, AllPublic: true},
|
opts: &SearchRepoOptions{Keyword: "test", Page: 1, PageSize: 10, OwnerID: 15, Private: true, AllPublic: true},
|
||||||
count: 15},
|
count: 15},
|
||||||
|
|
|
@ -141,6 +141,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
|
||||||
Keyword: keyword,
|
Keyword: keyword,
|
||||||
OwnerID: opts.OwnerID,
|
OwnerID: opts.OwnerID,
|
||||||
AllPublic: true,
|
AllPublic: true,
|
||||||
|
AllLimited: true,
|
||||||
TopicOnly: topicOnly,
|
TopicOnly: topicOnly,
|
||||||
IncludeDescription: setting.UI.SearchRepoDescription,
|
IncludeDescription: setting.UI.SearchRepoDescription,
|
||||||
})
|
})
|
||||||
|
|
Reference in a new issue