Skip to content

Commit 087719c

Browse files
6543zeripathlafriks
authored
Ensure public repositories in private organizations are visible and fix admin organizations list (#11465) (#11474)
* Ensure that we can see public repositories in private organization Fix #10144 (Again) Signed-off-by: Andrew Thornton <[email protected]> * Fix Admin users and organizations page Signed-off-by: Andrew Thornton <[email protected]> * Update models/repo_list.go Co-authored-by: Lauris BH <[email protected]> Co-authored-by: zeripath <[email protected]> Co-authored-by: Lauris BH <[email protected]>
1 parent bbd9beb commit 087719c

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

models/repo_list.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,35 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
249249
}
250250

251251
if opts.Collaborate != util.OptionalBoolFalse {
252+
// A Collaboration is:
252253
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:
253257
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").
256265
From("team_repo").
257266
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+
)
260281
if !opts.Private {
261282
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))
262283
}

routers/home.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ func RenderUserSearch(ctx *context.Context, opts *models.SearchUserOptions, tplN
194194
if opts.Page <= 1 {
195195
opts.Page = 1
196196
}
197-
opts.Actor = ctx.User
198197

199198
var (
200199
users []*models.User
@@ -252,6 +251,7 @@ func ExploreUsers(ctx *context.Context) {
252251
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
253252

254253
RenderUserSearch(ctx, &models.SearchUserOptions{
254+
Actor: ctx.User,
255255
Type: models.UserTypeIndividual,
256256
ListOptions: models.ListOptions{PageSize: setting.UI.ExplorePagingNum},
257257
IsActive: util.OptionalBoolTrue,
@@ -272,6 +272,7 @@ func ExploreOrganizations(ctx *context.Context) {
272272
}
273273

274274
RenderUserSearch(ctx, &models.SearchUserOptions{
275+
Actor: ctx.User,
275276
Type: models.UserTypeOrganization,
276277
ListOptions: models.ListOptions{PageSize: setting.UI.ExplorePagingNum},
277278
Visible: visibleTypes,

0 commit comments

Comments
 (0)