aboutsummaryrefslogtreecommitdiffstats
path: root/models/repo_list.go
diff options
context:
space:
mode:
authorRémy Boulanouar <rboulanouar@gmail.com>2019-02-18 17:00:27 +0100
committerLauris BH <lauris@nix.lv>2019-02-18 18:00:27 +0200
commit64ce159a6eacc81962d07a8f5ef7f69c17365363 (patch)
treed6b94d035de14df8b1a773d97ab35937cce1d00a /models/repo_list.go
parentae3a913122d3430ccf14da22f09daf6f636a00f8 (diff)
downloadgitea-64ce159a6eacc81962d07a8f5ef7f69c17365363.tar.gz
gitea-64ce159a6eacc81962d07a8f5ef7f69c17365363.zip
Allow to set organization visibility (public, internal, private) (#1763)
Diffstat (limited to 'models/repo_list.go')
-rw-r--r--models/repo_list.go35
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})
}