summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-05-18 00:27:54 +0100
committerGitHub <noreply@github.com>2020-05-18 00:27:54 +0100
commita4cd1f12f8fee190644c59da79fdd983df3c07b7 (patch)
treefd55fccab84ded6573de2606984ff685f0db1a32 /models
parent9a829b98f0e5a0b21e9b670c4b49f9a381a35e60 (diff)
downloadgitea-a4cd1f12f8fee190644c59da79fdd983df3c07b7.tar.gz
gitea-a4cd1f12f8fee190644c59da79fdd983df3c07b7.zip
Ensure public repositories in private organizations are visible and fix admin organizations list (#11465)
* Ensure that we can see public repositories in private organization Fix #10144 (Again) Signed-off-by: Andrew Thornton <art27@cantab.net> * Fix Admin users and organizations page Signed-off-by: Andrew Thornton <art27@cantab.net> * Update models/repo_list.go Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'models')
-rw-r--r--models/repo_list.go29
1 files changed, 25 insertions, 4 deletions
diff --git a/models/repo_list.go b/models/repo_list.go
index 316e6d084c..3e580a7229 100644
--- a/models/repo_list.go
+++ b/models/repo_list.go
@@ -249,14 +249,35 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
}
if opts.Collaborate != util.OptionalBoolFalse {
+ // A Collaboration is:
collaborateCond := builder.And(
+ // 1. Repository we don't own
+ builder.Neq{"owner_id": opts.OwnerID},
+ // 2. But we can see because of:
builder.Or(
- builder.Expr("repository.id IN (SELECT repo_id FROM `access` WHERE access.user_id = ?)", opts.OwnerID),
- builder.In("id", builder.Select("`team_repo`.repo_id").
+ // A. We have access
+ builder.In("`repository`.id",
+ builder.Select("`access`.repo_id").
+ From("access").
+ Where(builder.Eq{"`access`.user_id": opts.OwnerID})),
+ // B. We are in a team for
+ builder.In("`repository`.id", builder.Select("`team_repo`.repo_id").
From("team_repo").
Where(builder.Eq{"`team_user`.uid": opts.OwnerID}).
- Join("INNER", "team_user", "`team_user`.team_id = `team_repo`.team_id"))),
- builder.Neq{"owner_id": opts.OwnerID})
+ Join("INNER", "team_user", "`team_user`.team_id = `team_repo`.team_id")),
+ // C. Public repositories in private organizations that we are member of
+ builder.And(
+ builder.Eq{"`repository`.is_private": false},
+ builder.In("`repository`.owner_id",
+ builder.Select("`org_user`.org_id").
+ From("org_user").
+ Join("INNER", "`user`", "`user`.id = `org_user`.org_id").
+ Where(builder.Eq{
+ "`org_user`.uid": opts.OwnerID,
+ "`user`.type": UserTypeOrganization,
+ "`user`.visibility": structs.VisibleTypePrivate,
+ })))),
+ )
if !opts.Private {
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))
}