Admins and user itself sees private org relations on profile

This commit is contained in:
ExMex 2016-02-07 10:20:58 +01:00
parent 894946c319
commit 2cfe6f8c60
3 changed files with 17 additions and 9 deletions

View file

@ -254,24 +254,27 @@ func IsPublicMembership(orgId, uid int64) bool {
return has 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) 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) Join("INNER", "`org_user`", "`org_user`.org_id=`user`.id").Find(&orgs)
} }
// GetPublicOrgsByUserID returns a list of organizations that the given user ID // GetPublicOrgsByUserID returns a list of organizations that the given user ID
// has joined publicly. // has joined publicly.
func GetPublicOrgsByUserID(userID int64) ([]*User, error) { func GetOrgsByUserID(userID int64) ([]*User, error) {
sess := x.NewSession() sess := x.NewSession()
return getPublicOrgsByUserID(sess, userID) return getOrgsByUserID(sess, userID)
} }
// GetPublicOrgsByUserID returns a list of organizations that the given user ID // GetPublicOrgsByUserID returns a list of organizations that the given user ID
// has joined publicly, ordered descending by the given condition. // 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() 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) { func getOwnedOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) {

View file

@ -75,11 +75,12 @@ func Profile(ctx *middleware.Context) {
ctx.Data["PageIsUserProfile"] = true ctx.Data["PageIsUserProfile"] = true
ctx.Data["Owner"] = u 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 { if err != nil {
ctx.Handle(500, "GetPublicOrgsByUserIDDesc", err) ctx.Handle(500, "GetOrgsByUserIDDesc", err)
return return
} }
ctx.Data["Orgs"] = orgs ctx.Data["Orgs"] = orgs
tab := ctx.Query("tab") tab := ctx.Query("tab")

View file

@ -60,7 +60,11 @@
{{if .Orgs}} {{if .Orgs}}
<li> <li>
{{range .Orgs}} {{range .Orgs}}
<a href="{{.HomeLink}}"><img class="ui mini image poping up" src="{{.AvatarLink}}" data-content="{{.Name}}" data-position="top center" data-variation="tiny inverted"></a> {{if $.Owner.IsPublicMember .Id}}
<a href="{{.HomeLink}}"><img class="ui mini image poping up" src="{{.AvatarLink}}" data-content="{{.Name}}" data-position="top center" data-variation="tiny inverted"></a>
{{else}}
<a href="{{.HomeLink}}"><img class="ui mini image poping up" src="{{.AvatarLink}}" data-content="{{.Name}} (Private)" data-position="top center" data-variation="tiny inverted"></a>
{{end}}
{{end}} {{end}}
</li> </li>
{{end}} {{end}}