diff options
author | Rémy Boulanouar <rboulanouar@gmail.com> | 2019-02-18 17:00:27 +0100 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2019-02-18 18:00:27 +0200 |
commit | 64ce159a6eacc81962d07a8f5ef7f69c17365363 (patch) | |
tree | d6b94d035de14df8b1a773d97ab35937cce1d00a /models/org.go | |
parent | ae3a913122d3430ccf14da22f09daf6f636a00f8 (diff) | |
download | gitea-64ce159a6eacc81962d07a8f5ef7f69c17365363.tar.gz gitea-64ce159a6eacc81962d07a8f5ef7f69c17365363.zip |
Allow to set organization visibility (public, internal, private) (#1763)
Diffstat (limited to 'models/org.go')
-rw-r--r-- | models/org.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/models/org.go b/models/org.go index daff110cf5..2e22ae987b 100644 --- a/models/org.go +++ b/models/org.go @@ -1,4 +1,5 @@ // Copyright 2014 The Gogs Authors. All rights reserved. +// Copyright 2019 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -11,6 +12,7 @@ import ( "strings" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/structs" "github.com/Unknwon/com" "github.com/go-xorm/builder" @@ -366,6 +368,40 @@ func getOwnedOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) { Find(&orgs) } +// HasOrgVisible tells if the given user can see the given org +func HasOrgVisible(org *User, user *User) bool { + // Not SignedUser + if user == nil { + if org.Visibility == structs.VisibleTypePublic { + return true + } + return false + } + + if user.IsAdmin { + return true + } + + if org.Visibility == structs.VisibleTypePrivate && !org.IsUserPartOfOrg(user.ID) { + return false + } + return true +} + +// HasOrgsVisible tells if the given user can see at least one of the orgs provided +func HasOrgsVisible(orgs []*User, user *User) bool { + if len(orgs) == 0 { + return false + } + + for _, org := range orgs { + if HasOrgVisible(org, user) { + return true + } + } + return false +} + // GetOwnedOrgsByUserID returns a list of organizations are owned by given user ID. func GetOwnedOrgsByUserID(userID int64) ([]*User, error) { sess := x.NewSession() |