From 754fdd8f9c2b1e4e78d507fd414968334cf586fd Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Wed, 24 Nov 2021 04:51:08 +0100 Subject: [PATCH] Fix visibility of org avatars (#17789) * Fix visibility of org avatar * more clear syntax Co-authored-by: Lunny Xiao --- modules/templates/helper.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 8b46ed40c..aec3596bd 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -553,18 +553,24 @@ func SVG(icon string, others ...interface{}) template.HTML { func Avatar(item interface{}, others ...interface{}) template.HTML { size, class := parseOthers(avatars.DefaultAvatarPixelSize, "ui avatar image", others...) - if user, ok := item.(*models.User); ok { - src := user.AvatarLinkWithSize(size * avatars.AvatarRenderedSizeFactor) + switch t := item.(type) { + case *models.User: + src := t.AvatarLinkWithSize(size * avatars.AvatarRenderedSizeFactor) if src != "" { - return AvatarHTML(src, size, class, user.DisplayName()) + return AvatarHTML(src, size, class, t.DisplayName()) } - } - if user, ok := item.(*models.Collaborator); ok { - src := user.AvatarLinkWithSize(size * avatars.AvatarRenderedSizeFactor) + case *models.Collaborator: + src := t.AvatarLinkWithSize(size * avatars.AvatarRenderedSizeFactor) + if src != "" { + return AvatarHTML(src, size, class, t.DisplayName()) + } + case *models.Organization: + src := t.AsUser().AvatarLinkWithSize(size * avatars.AvatarRenderedSizeFactor) if src != "" { - return AvatarHTML(src, size, class, user.DisplayName()) + return AvatarHTML(src, size, class, t.AsUser().DisplayName()) } } + return template.HTML("") }