Skip to content

Commit

Permalink
new specific Param to include AllLimited Repos
Browse files Browse the repository at this point in the history
  • Loading branch information
6543 committed Jan 5, 2020
1 parent efa0f54 commit ef3e985
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions models/repo_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,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
Expand Down Expand Up @@ -228,7 +229,11 @@ func SearchRepository(opts *SearchRepoOptions) (RepositoryList, int64, error) {
}

if opts.AllPublic {
accessCond = accessCond.Or(builder.Eq{"is_private": false}).And(builder.In("owner_id", builder.Select("`user`.id").From("`user`").Where(builder.Lte{"`user`.visibility": structs.VisibleTypeLimited})))
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)
Expand Down
2 changes: 1 addition & 1 deletion models/repo_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func TestSearchRepository(t *testing.T) {
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, AllPublic: true, Template: util.OptionalBoolFalse},
count: 25},
{name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative",
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, Private: true, AllPublic: true, Template: util.OptionalBoolFalse},
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, Private: true, AllPublic: true, AllLimited: true, Template: util.OptionalBoolFalse},
count: 30},
{name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName",
opts: &SearchRepoOptions{Keyword: "test", Page: 1, PageSize: 10, OwnerID: 15, Private: true, AllPublic: true},
Expand Down
1 change: 1 addition & 0 deletions routers/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
Keyword: keyword,
OwnerID: opts.OwnerID,
AllPublic: true,
AllLimited: true,
TopicOnly: topicOnly,
IncludeDescription: setting.UI.SearchRepoDescription,
})
Expand Down

0 comments on commit ef3e985

Please sign in to comment.