Add handling for deleted users in templates
This commit is contained in:
parent
e9ba9b3dde
commit
a2eacd6d00
|
@ -12,12 +12,6 @@ import (
|
|||
)
|
||||
|
||||
func PostToTemplate(p *models.Post, author *models.User, currentTheme string) Post {
|
||||
var authorUser *User
|
||||
if author != nil {
|
||||
authorTmpl := UserToTemplate(author, currentTheme)
|
||||
authorUser = &authorTmpl
|
||||
}
|
||||
|
||||
return Post{
|
||||
ID: p.ID,
|
||||
|
||||
|
@ -26,7 +20,7 @@ func PostToTemplate(p *models.Post, author *models.User, currentTheme string) Po
|
|||
Preview: p.Preview,
|
||||
ReadOnly: p.ReadOnly,
|
||||
|
||||
Author: authorUser,
|
||||
Author: UserToTemplate(author, currentTheme),
|
||||
// No content. A lot of the time we don't have this handy and don't need it. See AddContentVersion.
|
||||
PostDate: p.PostDate,
|
||||
}
|
||||
|
@ -131,7 +125,7 @@ func UserAvatarUrl(u *models.User, currentTheme string) string {
|
|||
currentTheme = "light"
|
||||
}
|
||||
avatar := ""
|
||||
if u.Avatar != nil && len(*u.Avatar) > 0 {
|
||||
if u != nil && u.Avatar != nil && len(*u.Avatar) > 0 {
|
||||
avatar = hmnurl.BuildUserFile(*u.Avatar)
|
||||
} else {
|
||||
avatar = hmnurl.BuildTheme("empty-avatar.svg", currentTheme, true)
|
||||
|
@ -148,7 +142,12 @@ func UserDisplayName(u *models.User) string {
|
|||
}
|
||||
|
||||
func UserToTemplate(u *models.User, currentTheme string) User {
|
||||
// TODO: Handle deleted users. Maybe not here, but if not, at call sites of this function.
|
||||
if u == nil {
|
||||
return User{
|
||||
Name: "Deleted user",
|
||||
AvatarUrl: UserAvatarUrl(u, currentTheme),
|
||||
}
|
||||
}
|
||||
|
||||
email := ""
|
||||
if u.ShowEmail {
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
{{ range .Posts }}
|
||||
<div class="post background-even pa3">
|
||||
<div class="fl w-100 w-25-l pt3 pa3-l flex tc-l">
|
||||
{{ if .Author }}
|
||||
<div class="fl w-20 mw3 dn-l w3">
|
||||
<!-- Mobile avatar -->
|
||||
<div class="aspect-ratio--1x1 contain bg-center" style="background-image:url('{{ .Author.AvatarUrl }}');"></div>
|
||||
|
@ -52,10 +51,6 @@
|
|||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
{{ else }}
|
||||
<div class="username">Deleted member</div>
|
||||
<div class="avatar" style="background-image:url('{{ .Author.AvatarUrl }}');"></div>
|
||||
{{ end }}
|
||||
</div>
|
||||
<div class="fl w-100 w-75-l pv3 pa3-l">
|
||||
<div class="w-100 flex-l flex-row-reverse-l">
|
||||
|
|
|
@ -77,7 +77,7 @@ type Post struct {
|
|||
Preview string
|
||||
ReadOnly bool
|
||||
|
||||
Author *User
|
||||
Author User
|
||||
Content template.HTML
|
||||
PostDate time.Time
|
||||
|
||||
|
|
Loading…
Reference in New Issue