@@ -249,14 +249,35 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
249
249
}
250
250
251
251
if opts .Collaborate != util .OptionalBoolFalse {
252
+ // A Collaboration is:
252
253
collaborateCond := builder .And (
254
+ // 1. Repository we don't own
255
+ builder.Neq {"owner_id" : opts .OwnerID },
256
+ // 2. But we can see because of:
253
257
builder .Or (
254
- builder .Expr ("repository.id IN (SELECT repo_id FROM `access` WHERE access.user_id = ?)" , opts .OwnerID ),
255
- builder .In ("id" , builder .Select ("`team_repo`.repo_id" ).
258
+ // A. We have access
259
+ builder .In ("`repository`.id" ,
260
+ builder .Select ("`access`.repo_id" ).
261
+ From ("access" ).
262
+ Where (builder.Eq {"`access`.user_id" : opts .OwnerID })),
263
+ // B. We are in a team for
264
+ builder .In ("`repository`.id" , builder .Select ("`team_repo`.repo_id" ).
256
265
From ("team_repo" ).
257
266
Where (builder.Eq {"`team_user`.uid" : opts .OwnerID }).
258
- Join ("INNER" , "team_user" , "`team_user`.team_id = `team_repo`.team_id" ))),
259
- builder.Neq {"owner_id" : opts .OwnerID })
267
+ Join ("INNER" , "team_user" , "`team_user`.team_id = `team_repo`.team_id" )),
268
+ // C. Public repositories in private organizations that we are member of
269
+ builder .And (
270
+ builder.Eq {"`repository`.is_private" : false },
271
+ builder .In ("`repository`.owner_id" ,
272
+ builder .Select ("`org_user`.org_id" ).
273
+ From ("org_user" ).
274
+ Join ("INNER" , "`user`" , "`user`.id = `org_user`.org_id" ).
275
+ Where (builder.Eq {
276
+ "`org_user`.uid" : opts .OwnerID ,
277
+ "`user`.type" : UserTypeOrganization ,
278
+ "`user`.visibility" : structs .VisibleTypePrivate ,
279
+ })))),
280
+ )
260
281
if ! opts .Private {
261
282
collaborateCond = collaborateCond .And (builder .Expr ("owner_id NOT IN (SELECT org_id FROM org_user WHERE org_user.uid = ? AND org_user.is_public = ?)" , opts .OwnerID , false ))
262
283
}
0 commit comments