Skip to content

Commit c642cd0

Browse files
zeripathlafriks
andauthored
Allow all members of private orgs to see public repos (#11442)
* Allow all members of private orgs to see public repos Fix #10144 Signed-off-by: Andrew Thornton <[email protected]> * Update models/repo_list.go Co-authored-by: Lauris BH <[email protected]>
1 parent a0d35fb commit c642cd0

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

models/repo_list.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -401,21 +401,26 @@ func accessibleRepositoryCondition(user *User) builder.Cond {
401401
}
402402

403403
if user != nil {
404-
// 2. Be able to see all repositories that we have access to
405-
cond = cond.Or(builder.Or(
404+
cond = cond.Or(
405+
// 2. Be able to see all repositories that we have access to
406406
builder.In("`repository`.id", builder.Select("repo_id").
407407
From("`access`").
408408
Where(builder.And(
409409
builder.Eq{"user_id": user.ID},
410410
builder.Gt{"mode": int(AccessModeNone)}))),
411-
builder.In("`repository`.id", builder.Select("id").
412-
From("`repository`").
413-
Where(builder.Eq{"owner_id": user.ID}))))
414-
// 3. Be able to see all repositories that we are in a team
415-
cond = cond.Or(builder.In("`repository`.id", builder.Select("`team_repo`.repo_id").
416-
From("team_repo").
417-
Where(builder.Eq{"`team_user`.uid": user.ID}).
418-
Join("INNER", "team_user", "`team_user`.team_id = `team_repo`.team_id")))
411+
// 3. Repositories that we directly own
412+
builder.Eq{"`repository`.owner_id": user.ID},
413+
// 4. Be able to see all repositories that we are in a team
414+
builder.In("`repository`.id", builder.Select("`team_repo`.repo_id").
415+
From("team_repo").
416+
Where(builder.Eq{"`team_user`.uid": user.ID}).
417+
Join("INNER", "team_user", "`team_user`.team_id = `team_repo`.team_id")),
418+
// 5. Be able to see all public repos in private organizations that we are an org_user of
419+
builder.And(builder.Eq{"`repository`.is_private": false},
420+
builder.In("`repository`.owner_id",
421+
builder.Select("`org_user`.org_id").
422+
From("org_user").
423+
Where(builder.Eq{"`org_user`.uid": user.ID}))))
419424
}
420425

421426
return cond

0 commit comments

Comments
 (0)