summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-01-31 08:56:21 -0500
committerUnknwon <u@gogs.io>2016-01-31 08:56:21 -0500
commit1c1246fcb9c5537bebeb2335b38c0fd2278a8426 (patch)
tree1d7f0bf2f98450ab7ce3a646dc2c86854e991ef6
parent8436d69eaf435ae6bb50f648c1aed3eef7b0850b (diff)
parent295de51b9958703fe1b8da49aa1c13421b318190 (diff)
downloadgitea-1c1246fcb9c5537bebeb2335b38c0fd2278a8426.tar.gz
gitea-1c1246fcb9c5537bebeb2335b38c0fd2278a8426.zip
Merge pull request #2527 from fnkr/hide-private-orgs-from-profile
Show all orgs on user profile, except the private one's
-rw-r--r--models/org.go22
-rw-r--r--routers/user/profile.go6
2 files changed, 24 insertions, 4 deletions
diff --git a/models/org.go b/models/org.go
index b8836c349f..3de89e4bd3 100644
--- a/models/org.go
+++ b/models/org.go
@@ -253,6 +253,26 @@ func IsPublicMembership(orgId, uid int64) bool {
return has
}
+func getPublicOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) {
+ orgs := make([]*User, 0, 10)
+ return orgs, sess.Where("`org_user`.uid=?", userID).And("`org_user`.is_public=?", true).
+ Join("INNER", "`org_user`", "`org_user`.org_id=`user`.id").Find(&orgs)
+}
+
+// GetPublicOrgsByUserID returns a list of organizations that the given user ID
+// has joined publicly.
+func GetPublicOrgsByUserID(userID int64) ([]*User, error) {
+ sess := x.NewSession()
+ return getPublicOrgsByUserID(sess, userID)
+}
+
+// GetPublicOrgsByUserID returns a list of organizations that the given user ID
+// has joined publicly, ordered descending by the given condition.
+func GetPublicOrgsByUserIDDesc(userID int64, desc string) ([]*User, error) {
+ sess := x.NewSession()
+ return getPublicOrgsByUserID(sess.Desc(desc), userID)
+}
+
func getOwnedOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) {
orgs := make([]*User, 0, 10)
return orgs, sess.Where("`org_user`.uid=?", userID).And("`org_user`.is_owner=?", true).
@@ -266,7 +286,7 @@ func GetOwnedOrgsByUserID(userID int64) ([]*User, error) {
}
// GetOwnedOrganizationsByUserIDDesc returns a list of organizations are owned by
-// given user ID and descring order by given condition.
+// given user ID, ordered descending by the given condition.
func GetOwnedOrgsByUserIDDesc(userID int64, desc string) ([]*User, error) {
sess := x.NewSession()
return getOwnedOrgsByUserID(sess.Desc(desc), userID)
diff --git a/routers/user/profile.go b/routers/user/profile.go
index 3a25363818..1452b29733 100644
--- a/routers/user/profile.go
+++ b/routers/user/profile.go
@@ -74,10 +74,10 @@ func Profile(ctx *middleware.Context) {
ctx.Data["Title"] = u.DisplayName()
ctx.Data["PageIsUserProfile"] = true
ctx.Data["Owner"] = u
-
- orgs, err := models.GetOwnedOrgsByUserIDDesc(u.Id, "updated")
+
+ orgs, err := models.GetPublicOrgsByUserIDDesc(u.Id, "updated")
if err != nil {
- ctx.Handle(500, "GetOwnedOrgsByUserIDDesc", err)
+ ctx.Handle(500, "GetPublicOrgsByUserIDDesc", err)
return
}
ctx.Data["Orgs"] = orgs