@@ -642,6 +642,17 @@ func SearchRepositoryIDsByCondition(ctx context.Context, cond builder.Cond) ([]i
642642Find (& repoIDs )
643643}
644644
645+ func userAllPublicRepoCond (cond builder.Cond ,orgVisibilityLimit []structs.VisibleType ) builder.Cond {
646+ return cond .Or (builder .And (
647+ builder.Eq {"`repository`.is_private" :false },
648+ // Aren't in a private organisation or limited organisation if we're not logged in
649+ builder .NotIn ("`repository`.owner_id" ,builder .Select ("id" ).From ("`user`" ).Where (
650+ builder .And (
651+ builder.Eq {"type" :user_model .UserTypeOrganization },
652+ builder .In ("visibility" ,orgVisibilityLimit )),
653+ ))))
654+ }
655+
645656// AccessibleRepositoryCondition takes a user a returns a condition for checking if a repository is accessible
646657func AccessibleRepositoryCondition (user * user_model.User ,unitType unit.Type ) builder.Cond {
647658cond := builder .NewCond ()
@@ -651,15 +662,8 @@ func AccessibleRepositoryCondition(user *user_model.User, unitType unit.Type) bu
651662if user == nil || user .ID <= 0 {
652663orgVisibilityLimit = append (orgVisibilityLimit ,structs .VisibleTypeLimited )
653664}
654- // 1. Be able to see all non-private repositories that either:
655- cond = cond .Or (builder .And (
656- builder.Eq {"`repository`.is_private" :false },
657- // 2. Aren't in an private organisation or limited organisation if we're not logged in
658- builder .NotIn ("`repository`.owner_id" ,builder .Select ("id" ).From ("`user`" ).Where (
659- builder .And (
660- builder.Eq {"type" :user_model .UserTypeOrganization },
661- builder .In ("visibility" ,orgVisibilityLimit )),
662- ))))
665+ // 1. Be able to see all non-private repositories
666+ cond = userAllPublicRepoCond (cond ,orgVisibilityLimit )
663667}
664668
665669if user != nil {
@@ -683,6 +687,9 @@ func AccessibleRepositoryCondition(user *user_model.User, unitType unit.Type) bu
683687if ! user .IsRestricted {
684688// 5. Be able to see all public repos in private organizations that we are an org_user of
685689cond = cond .Or (userOrgPublicRepoCond (user .ID ))
690+ }else {
691+ orgVisibilityLimit := []structs.VisibleType {structs .VisibleTypePrivate ,structs .VisibleTypeLimited }
692+ cond = userAllPublicRepoCond (cond ,orgVisibilityLimit )
686693}
687694}
688695