diff options
Diffstat (limited to 'models/repo_list.go')
-rw-r--r-- | models/repo_list.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/models/repo_list.go b/models/repo_list.go index 049d1834f7..83d2665e8c 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -8,9 +8,11 @@ import ( "fmt" "strings" + "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/util" "github.com/go-xorm/builder" + "github.com/go-xorm/core" ) // RepositoryListDefaultPageSize is the default number of repositories @@ -171,6 +173,10 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err if !opts.Private { cond = cond.And(builder.Eq{"is_private": false}) + accessCond := builder.Or( + builder.NotIn("owner_id", builder.Select("id").From("`user`").Where(builder.Or(builder.Eq{"visibility": structs.VisibleTypeLimited}, builder.Eq{"visibility": structs.VisibleTypePrivate}))), + builder.NotIn("owner_id", builder.Select("id").From("`user`").Where(builder.Eq{"type": UserTypeOrganization}))) + cond = cond.And(accessCond) } if opts.OwnerID > 0 { @@ -193,6 +199,35 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err accessCond = accessCond.Or(collaborateCond) } + var exprCond builder.Cond + if DbCfg.Type == core.POSTGRES { + exprCond = builder.Expr("org_user.org_id = \"user\".id") + } else if DbCfg.Type == core.MSSQL { + exprCond = builder.Expr("org_user.org_id = [user].id") + } else { + exprCond = builder.Eq{"org_user.org_id": "user.id"} + } + + visibilityCond := builder.Or( + builder.In("owner_id", + builder.Select("org_id").From("org_user"). + LeftJoin("`user`", exprCond). + Where( + builder.And( + builder.Eq{"uid": opts.OwnerID}, + builder.Eq{"visibility": structs.VisibleTypePrivate})), + ), + builder.In("owner_id", + builder.Select("id").From("`user`"). + Where( + builder.Or( + builder.Eq{"visibility": structs.VisibleTypePublic}, + builder.Eq{"visibility": structs.VisibleTypeLimited})), + ), + builder.NotIn("owner_id", builder.Select("id").From("`user`").Where(builder.Eq{"type": UserTypeOrganization})), + ) + cond = cond.And(visibilityCond) + if opts.AllPublic { accessCond = accessCond.Or(builder.Eq{"is_private": false}) } |