diff options
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() |