diff options
author | Unknwon <u@gogs.io> | 2016-02-19 18:10:03 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2016-02-19 18:10:03 -0500 |
commit | aa12135b975ff2ebf04acb12cf3b3fd52b6c024a (patch) | |
tree | 967c5e6c0cb0c4e56cf08132b95c3d27ca3c681b /models | |
parent | f38d5e57dd0ea4841b1592044a500c2a2399229d (diff) |
Fix panic when view profile without signin
Also fix that no matter who, still able to see organizations with private membership.
Diffstat (limited to 'models')
-rw-r--r-- | models/org.go | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/models/org.go b/models/org.go index de66af66..9d86df10 100644 --- a/models/org.go +++ b/models/org.go @@ -254,27 +254,25 @@ func IsPublicMembership(orgId, uid int64) bool { return has } -func getOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) { +func getOrgsByUserID(sess *xorm.Session, userID int64, showAll bool) ([]*User, error) { orgs := make([]*User, 0, 10) - return orgs, sess.Where("`org_user`.uid=?", userID). + if !showAll { + sess.And("`org_user`.is_public=?", true) + } + return orgs, sess.And("`org_user`.uid=?", userID). Join("INNER", "`org_user`", "`org_user`.org_id=`user`.id").Find(&orgs) } // GetOrgsByUserID returns a list of organizations that the given user ID // has joined. -func GetOrgsByUserID(userID int64) ([]*User, error) { - sess := x.NewSession() - return getOrgsByUserID(sess, userID) +func GetOrgsByUserID(userID int64, showAll bool) ([]*User, error) { + return getOrgsByUserID(x.NewSession(), userID, showAll) } // GetOrgsByUserIDDesc returns a list of organizations that the given user ID // has joined, ordered descending by the given condition. -func GetOrgsByUserIDDesc(userID int64, desc string, all bool) ([]*User, error) { - sess := x.NewSession() - if !all { - sess.And("`org_user`.is_public=?", true) - } - return getOrgsByUserID(sess.Desc(desc), userID) +func GetOrgsByUserIDDesc(userID int64, desc string, showAll bool) ([]*User, error) { + return getOrgsByUserID(x.NewSession().Desc(desc), userID, showAll) } func getOwnedOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) { |