From ccfa40889adf9f676f1c54cec5997e9356d42c70 Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 10 Dec 2020 06:44:13 +0100 Subject: [PATCH] Fix avatar template error on repo collaborator page (#13924) Fixes error `template: repo/settings/collaboration:16:16: executing "repo/settings/collaboration" at <.>: wrong type for value; expected *models.User; got *models.Collaborator` seen on repo collaborator page. Co-authored-by: techknowlogick --- modules/templates/helper.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/templates/helper.go b/modules/templates/helper.go index a7063d7b8dc5..15cbeb81513a 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -550,12 +550,20 @@ func SVG(icon string, others ...interface{}) template.HTML { } // Avatar renders user avatars. args: user, size (int), class (string) -func Avatar(user *models.User, others ...interface{}) template.HTML { +func Avatar(item interface{}, others ...interface{}) template.HTML { size, class := parseOthers(models.DefaultAvatarPixelSize, "ui avatar image", others...) - src := user.RealSizedAvatarLink(size * models.AvatarRenderedSizeFactor) - if src != "" { - return AvatarHTML(src, size, class, user.DisplayName()) + if user, ok := item.(*models.User); ok { + src := user.RealSizedAvatarLink(size * models.AvatarRenderedSizeFactor) + if src != "" { + return AvatarHTML(src, size, class, user.DisplayName()) + } + } + if user, ok := item.(*models.Collaborator); ok { + src := user.RealSizedAvatarLink(size * models.AvatarRenderedSizeFactor) + if src != "" { + return AvatarHTML(src, size, class, user.DisplayName()) + } } return template.HTML("") }