User profile display organization based on Membership Visibility and Organization Visibility
This commit is contained in:
parent
20e63bb479
commit
15d9e00533
|
@ -1,4 +1,5 @@
|
|||
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
|
@ -368,6 +369,42 @@ func getOwnedOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) {
|
|||
Find(&orgs)
|
||||
}
|
||||
|
||||
// HasOrgVisible tell if the given user can see one of the given orgs
|
||||
func HasOrgVisible(orgs []*User, user *User) bool {
|
||||
if len(orgs) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
// Not SignedUser
|
||||
if user == nil {
|
||||
for _, org := range orgs {
|
||||
if org.Visibility == 1 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
if user.IsAdmin {
|
||||
return true
|
||||
}
|
||||
for _, org := range orgs {
|
||||
switch org.Visibility {
|
||||
case VisibleTypePublic:
|
||||
return true
|
||||
case VisibleTypeLimited:
|
||||
return true
|
||||
case VisibleTypePrivate:
|
||||
if org.IsUserOrgPartOf(user.ID) {
|
||||
return true
|
||||
}
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// GetOwnedOrgsByUserID returns a list of organizations are owned by given user ID.
|
||||
func GetOwnedOrgsByUserID(userID int64) ([]*User, error) {
|
||||
sess := x.NewSession()
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// Copyright 2015 The Gogs Authors. All rights reserved.
|
||||
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
|
@ -95,6 +96,7 @@ func Profile(ctx *context.Context) {
|
|||
}
|
||||
|
||||
ctx.Data["Orgs"] = orgs
|
||||
ctx.Data["HasOrgsVisible"] = models.HasOrgVisible(orgs, ctx.User)
|
||||
|
||||
tab := ctx.Query("tab")
|
||||
ctx.Data["TabName"] = tab
|
||||
|
|
|
@ -61,10 +61,12 @@
|
|||
</a>
|
||||
</li>
|
||||
*/}}
|
||||
{{if .Orgs}}
|
||||
{{if and .Orgs .HasOrgsVisible}}
|
||||
<li>
|
||||
{{range .Orgs}}
|
||||
<a href="{{.HomeLink}}"><img class="ui mini image poping up" src="{{.RelAvatarLink}}" data-content="{{.Name}}" data-position="top center" data-variation="tiny inverted"></a>
|
||||
{{if (or (eq .Visibility 1) (and ($.SignedUser) (or (eq .Visibility 2) (and (.IsUserOrgPartOf $.SignedUserID) (eq .Visibility 3)) ($.IsAdmin))))}}
|
||||
<a href="{{.HomeLink}}"><img class="ui mini image poping up" src="{{.RelAvatarLink}}" data-content="{{.Name}}" data-position="top center" data-variation="tiny inverted"></a>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</li>
|
||||
{{end}}
|
||||
|
|
Loading…
Reference in New Issue
Block a user