From 9cd16c5b12d093dd694e146d6c845ee4c405c774 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Thu, 17 Dec 2015 02:28:47 -0500 Subject: #1692 add organization APIs --- models/org.go | 11 ++++++++--- models/user.go | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'models') diff --git a/models/org.go b/models/org.go index 6cc951bef0..fa26b59e66 100644 --- a/models/org.go +++ b/models/org.go @@ -274,10 +274,15 @@ func GetOwnedOrgsByUserIDDesc(userID int64, desc string) ([]*User, error) { return getOwnedOrgsByUserID(sess.Desc(desc), userID) } -// GetOrgUsersByUserId returns all organization-user relations by user ID. -func GetOrgUsersByUserId(uid int64) ([]*OrgUser, error) { +// GetOrgUsersByUserID returns all organization-user relations by user ID. +func GetOrgUsersByUserID(uid int64, all bool) ([]*OrgUser, error) { ous := make([]*OrgUser, 0, 10) - err := x.Where("uid=?", uid).Find(&ous) + sess := x.Where("uid=?", uid) + if !all { + // Only show public organizations + sess.And("is_public=?", true) + } + err := sess.Find(&ous) return ous, err } diff --git a/models/user.go b/models/user.go index 71729a4e3e..ebdc3c47fe 100644 --- a/models/user.go +++ b/models/user.go @@ -376,8 +376,8 @@ func (u *User) GetOwnedOrganizations() (err error) { } // GetOrganizations returns all organizations that user belongs to. -func (u *User) GetOrganizations() error { - ous, err := GetOrgUsersByUserId(u.Id) +func (u *User) GetOrganizations(all bool) error { + ous, err := GetOrgUsersByUserID(u.Id, all) if err != nil { return err } -- cgit v1.2.3