From 2cfe6f8c60033989fa141b415080fc4416f03c5b Mon Sep 17 00:00:00 2001 From: ExMex Date: Sun, 7 Feb 2016 10:20:58 +0100 Subject: [PATCH 1/2] Admins and user itself sees private org relations on profile --- models/org.go | 15 +++++++++------ routers/user/profile.go | 5 +++-- templates/user/profile.tmpl | 6 +++++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/models/org.go b/models/org.go index 020284d8d2..8b773b2d04 100644 --- a/models/org.go +++ b/models/org.go @@ -254,24 +254,27 @@ func IsPublicMembership(orgId, uid int64) bool { return has } -func getPublicOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) { +func getOrgsByUserID(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). + return orgs, sess.Where("`org_user`.uid=?", userID). 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) { +func GetOrgsByUserID(userID int64) ([]*User, error) { sess := x.NewSession() - return getPublicOrgsByUserID(sess, userID) + return getOrgsByUserID(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) { +func GetOrgsByUserIDDesc(userID int64, desc string, all bool) ([]*User, error) { sess := x.NewSession() - return getPublicOrgsByUserID(sess.Desc(desc), userID) + if !all { + sess.And("`org_user`.is_public=?", true) + } + return getOrgsByUserID(sess.Desc(desc), userID) } func getOwnedOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) { diff --git a/routers/user/profile.go b/routers/user/profile.go index 0a876610ed..c18a104be9 100644 --- a/routers/user/profile.go +++ b/routers/user/profile.go @@ -75,11 +75,12 @@ func Profile(ctx *middleware.Context) { ctx.Data["PageIsUserProfile"] = true ctx.Data["Owner"] = u - orgs, err := models.GetPublicOrgsByUserIDDesc(u.Id, "updated") + orgs, err := models.GetOrgsByUserIDDesc(u.Id, "updated", ctx.User.IsAdmin || ctx.User.Id == u.Id) if err != nil { - ctx.Handle(500, "GetPublicOrgsByUserIDDesc", err) + ctx.Handle(500, "GetOrgsByUserIDDesc", err) return } + ctx.Data["Orgs"] = orgs tab := ctx.Query("tab") diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index c037b0ad13..07f5c1b0e5 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -60,7 +60,11 @@ {{if .Orgs}}
  • {{range .Orgs}} - + {{if $.Owner.IsPublicMember .Id}} + + {{else}} + + {{end}} {{end}}
  • {{end}} From 40f9d4f920c481db8dc8bf1a5b29c7005ea06f29 Mon Sep 17 00:00:00 2001 From: ExMex Date: Sun, 7 Feb 2016 20:30:15 +0100 Subject: [PATCH 2/2] Reverted showing (private) on private org relations --- templates/user/profile.tmpl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index 07f5c1b0e5..c037b0ad13 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -60,11 +60,7 @@ {{if .Orgs}}
  • {{range .Orgs}} - {{if $.Owner.IsPublicMember .Id}} - - {{else}} - - {{end}} + {{end}}
  • {{end}}