]> source.dussan.org Git - gitea.git/commitdiff
[BugFix] Hide public repos owned by private orgs (#9609)
author6543 <6543@obermui.de>
Sun, 5 Jan 2020 18:48:47 +0000 (19:48 +0100)
committerzeripath <art27@cantab.net>
Sun, 5 Jan 2020 18:48:47 +0000 (18:48 +0000)
* Restrict AllPublic to actually public repos.
* Add new parameter to add in AllLimited Repos

models/repo_list.go
models/repo_list_test.go
routers/home.go

index 34fac8b05531dc1b6b3261f24bd3e9bc03472fb9..7b48834dba9e23bf2dea6f3907ad0e533d18406a 100644 (file)
@@ -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
@@ -228,7 +229,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)
index a1eed18b83abdc1a593db340c905cb710bf22b9a..07f84207e2002da036b8ce7734bc6e617c8c2065 100644 (file)
@@ -177,8 +177,8 @@ 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},
-                       count: 31},
+                       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},
                        count: 15},
index d223054f4ce3f7b5d14ae3b1df521cc504528ffc..773e0f3d6bebb1288c645096b92f29dce7b084ac 100644 (file)
@@ -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,
        })