@@ -214,14 +214,35 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
214
214
}
215
215
216
216
if opts .Collaborate != util .OptionalBoolFalse {
217
+ // A Collaboration is:
217
218
collaborateCond := builder .And (
219
+ // 1. Repository we don't own
220
+ builder.Neq {"owner_id" : opts .OwnerID },
221
+ // 2. But we can see because of:
218
222
builder .Or (
219
- builder .Expr ("repository.id IN (SELECT repo_id FROM `access` WHERE access.user_id = ?)" , opts .OwnerID ),
220
- builder .In ("id" , builder .Select ("`team_repo`.repo_id" ).
223
+ // A. We have access
224
+ builder .In ("`repository`.id" ,
225
+ builder .Select ("`access`.repo_id" ).
226
+ From ("access" ).
227
+ Where (builder.Eq {"`access`.user_id" : opts .OwnerID })),
228
+ // B. We are in a team for
229
+ builder .In ("`repository`.id" , builder .Select ("`team_repo`.repo_id" ).
221
230
From ("team_repo" ).
222
231
Where (builder.Eq {"`team_user`.uid" : opts .OwnerID }).
223
- Join ("INNER" , "team_user" , "`team_user`.team_id = `team_repo`.team_id" ))),
224
- builder.Neq {"owner_id" : opts .OwnerID })
232
+ Join ("INNER" , "team_user" , "`team_user`.team_id = `team_repo`.team_id" )),
233
+ // C. Public repositories in private organizations that we are member of
234
+ builder .And (
235
+ builder.Eq {"`repository`.is_private" : false },
236
+ builder .In ("`repository`.owner_id" ,
237
+ builder .Select ("`org_user`.org_id" ).
238
+ From ("org_user" ).
239
+ Join ("INNER" , "`user`" , "`user`.id = `org_user`.org_id" ).
240
+ Where (builder.Eq {
241
+ "`org_user`.uid" : opts .OwnerID ,
242
+ "`user`.type" : UserTypeOrganization ,
243
+ "`user`.visibility" : structs .VisibleTypePrivate ,
244
+ })))),
245
+ )
225
246
if ! opts .Private {
226
247
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 ))
227
248
}
0 commit comments