@@ -340,41 +340,39 @@ func SearchRepositoryByCondition(opts *SearchRepoOptions, cond builder.Cond) (Re
340
340
// accessibleRepositoryCondition takes a user a returns a condition for checking if a repository is accessible
341
341
func accessibleRepositoryCondition (userID int64 ) builder.Cond {
342
342
if userID <= 0 {
343
+ // Public repositories that are not in private or limited organizations
343
344
return builder .And (
344
345
builder.Eq {"`repository`.is_private" : false },
345
- builder .Or (
346
- // A. Aren't in organisations __OR__
347
- builder .NotIn ("`repository`.owner_id" , builder .Select ("id" ).From ("`user`" ).Where (builder.Eq {"type" : UserTypeOrganization })),
348
- // B. Is a public organisation.
349
- builder .In ("`repository`.owner_id" , builder .Select ("id" ).From ("`user`" ).Where (builder.Eq {"visibility" : structs .VisibleTypePublic }))),
350
- )
346
+ builder .NotIn ("`repository`.owner_id" ,
347
+ builder .Select ("id" ).From ("`user`" ).Where (builder.Eq {"type" : UserTypeOrganization }).And (builder.Neq {"visibility" : structs .VisibleTypePublic })))
351
348
}
352
349
353
350
return builder .Or (
354
- // 1. Be able to see all non-private repositories that either:
351
+ // 1. All public repositories that are not in private organizations
355
352
builder .And (
356
353
builder.Eq {"`repository`.is_private" : false },
357
- builder .Or (
358
- // A. Aren't in organisations __OR__
359
- builder .NotIn ("`repository`.owner_id" , builder .Select ("id" ).From ("`user`" ).Where (builder.Eq {"type" : UserTypeOrganization })),
360
- // B. Isn't a private organisation. (Limited is OK because we're logged in)
361
- builder .NotIn ("`repository`.owner_id" , builder .Select ("id" ).From ("`user`" ).Where (builder.Eq {"visibility" : structs .VisibleTypePrivate }))),
362
- ),
363
- // 2. Be able to see all repositories that we have access to
364
- builder .Or (
365
- builder .In ("`repository`.id" , builder .Select ("repo_id" ).
366
- From ("`access`" ).
367
- Where (builder .And (
368
- builder.Eq {"user_id" : userID },
369
- builder.Gt {"mode" : int (AccessModeNone )}))),
370
- builder .In ("`repository`.id" , builder .Select ("id" ).
371
- From ("`repository`" ).
372
- Where (builder.Eq {"owner_id" : userID }))),
373
- // 3. Be able to see all repositories that we are in a team
354
+ builder .NotIn ("`repository`.owner_id" ,
355
+ builder .Select ("id" ).From ("`user`" ).Where (builder.Eq {"type" : UserTypeOrganization }).And (builder.Eq {"visibility" : structs .VisibleTypePrivate }))),
356
+ // 2. Be able to see all repositories that we own
357
+ builder.Eq {"`repository`.owner_id" : userID },
358
+ // 3. Be able to see all repositories that we have access to
359
+ builder .In ("`repository`.id" , builder .Select ("repo_id" ).
360
+ From ("`access`" ).
361
+ Where (builder .And (
362
+ builder.Eq {"user_id" : userID },
363
+ builder.Gt {"mode" : int (AccessModeNone )}))),
364
+ // 4. Be able to see all repositories that we are in a team
374
365
builder .In ("`repository`.id" , builder .Select ("`team_repo`.repo_id" ).
375
366
From ("team_repo" ).
376
367
Where (builder.Eq {"`team_user`.uid" : userID }).
377
- Join ("INNER" , "team_user" , "`team_user`.team_id = `team_repo`.team_id" )))
368
+ Join ("INNER" , "team_user" , "`team_user`.team_id = `team_repo`.team_id" )),
369
+ // 5. Be able to see all public repos in private organizations that we are an org_user of
370
+ builder .And (builder.Eq {"`repository`.is_private" : false },
371
+ builder .In ("`repository`.owner_id" ,
372
+ builder .Select ("`org_user`.org_id" ).
373
+ From ("org_user" ).
374
+ Where (builder.Eq {"`org_user`.uid" : userID }))),
375
+ )
378
376
}
379
377
380
378
// SearchRepositoryByName takes keyword and part of repository name to search,
0 commit comments