@@ -340,41 +340,37 @@ func SearchRepositoryByCondition(opts *SearchRepoOptions, cond builder.Cond) (Re
340340// accessibleRepositoryCondition takes a user a returns a condition for checking if a repository is accessible
341341func accessibleRepositoryCondition (userID int64 ) builder.Cond {
342342 if userID <= 0 {
343+ // Public repositories that are not in private or limited organizatons
343344 return builder .And (
344345 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 })))
351348 }
352349
353350 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
355352 builder .And (
356353 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- ),
354+ builder .NotIn ("`repository`.owner_id" ,
355+ builder .Select ("id" ).From ("`user`" ).Where (builder.Eq {"type" : UserTypeOrganization }).And (builder.Eq {"visibility" : structs .VisibleTypePrivate }))),
363356 // 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 }))),
357+ builder .In ("`repository`.id" , builder .Select ("repo_id" ).
358+ From ("`access`" ).
359+ Where (builder .And (
360+ builder.Eq {"user_id" : userID },
361+ builder.Gt {"mode" : int (AccessModeNone )}))),
373362 // 3. Be able to see all repositories that we are in a team
374363 builder .In ("`repository`.id" , builder .Select ("`team_repo`.repo_id" ).
375364 From ("team_repo" ).
376365 Where (builder.Eq {"`team_user`.uid" : userID }).
377- Join ("INNER" , "team_user" , "`team_user`.team_id = `team_repo`.team_id" )))
366+ Join ("INNER" , "team_user" , "`team_user`.team_id = `team_repo`.team_id" )),
367+ // 5. Be able to see all public repos in private organizations that we are an org_user of
368+ builder .And (builder.Eq {"`repository`.is_private" : false },
369+ builder .In ("`repository`.owner_id" ,
370+ builder .Select ("`org_user`.org_id" ).
371+ From ("org_user" ).
372+ Where (builder.Eq {"`org_user`.uid" : userID }))),
373+ )
378374}
379375
380376// SearchRepositoryByName takes keyword and part of repository name to search,
0 commit comments