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 {
|
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{
|
return Post{
|
||||||
ID: p.ID,
|
ID: p.ID,
|
||||||
|
|
||||||
|
@ -26,7 +20,7 @@ func PostToTemplate(p *models.Post, author *models.User, currentTheme string) Po
|
||||||
Preview: p.Preview,
|
Preview: p.Preview,
|
||||||
ReadOnly: p.ReadOnly,
|
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.
|
// No content. A lot of the time we don't have this handy and don't need it. See AddContentVersion.
|
||||||
PostDate: p.PostDate,
|
PostDate: p.PostDate,
|
||||||
}
|
}
|
||||||
|
@ -131,7 +125,7 @@ func UserAvatarUrl(u *models.User, currentTheme string) string {
|
||||||
currentTheme = "light"
|
currentTheme = "light"
|
||||||
}
|
}
|
||||||
avatar := ""
|
avatar := ""
|
||||||
if u.Avatar != nil && len(*u.Avatar) > 0 {
|
if u != nil && u.Avatar != nil && len(*u.Avatar) > 0 {
|
||||||
avatar = hmnurl.BuildUserFile(*u.Avatar)
|
avatar = hmnurl.BuildUserFile(*u.Avatar)
|
||||||
} else {
|
} else {
|
||||||
avatar = hmnurl.BuildTheme("empty-avatar.svg", currentTheme, true)
|
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 {
|
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 := ""
|
email := ""
|
||||||
if u.ShowEmail {
|
if u.ShowEmail {
|
||||||
|
|
|
@ -9,53 +9,48 @@
|
||||||
{{ range .Posts }}
|
{{ range .Posts }}
|
||||||
<div class="post background-even pa3">
|
<div class="post background-even pa3">
|
||||||
<div class="fl w-100 w-25-l pt3 pa3-l flex tc-l">
|
<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">
|
||||||
<div class="fl w-20 mw3 dn-l w3">
|
<!-- Mobile avatar -->
|
||||||
<!-- Mobile avatar -->
|
<div class="aspect-ratio--1x1 contain bg-center" style="background-image:url('{{ .Author.AvatarUrl }}');"></div>
|
||||||
<div class="aspect-ratio--1x1 contain bg-center" style="background-image:url('{{ .Author.AvatarUrl }}');"></div>
|
</div>
|
||||||
</div>
|
<div class="w-100-l pl3 pl0-l flex flex-column items-center-l">
|
||||||
<div class="w-100-l pl3 pl0-l flex flex-column items-center-l">
|
<div>
|
||||||
<div>
|
<a class="username" href="{{ .Author.ProfileUrl }}" target="_blank">{{ .Author.Username }}</a> {{/* TODO: Text scale stuff? Seems unnecessary. */}}
|
||||||
<a class="username" href="{{ .Author.ProfileUrl }}" target="_blank">{{ .Author.Username }}</a> {{/* TODO: Text scale stuff? Seems unnecessary. */}}
|
<!-- Mobile badges -->
|
||||||
<!-- Mobile badges -->
|
<div class="di dn-l ph1">
|
||||||
<div class="di dn-l ph1">
|
|
||||||
{{ if .Author.IsStaff }}
|
|
||||||
<div class="badge staff"></div>
|
|
||||||
{{ end }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{{ if and .Author.Name (ne .Author.Name .Author.Username) }}
|
|
||||||
<div class="c--dim f7"> {{ .Author.Name }} </div>
|
|
||||||
{{ end }}
|
|
||||||
<!-- Large avatar -->
|
|
||||||
<div class="dn db-l w-60 pv2">
|
|
||||||
<div class="aspect-ratio--1x1 contain bg-center" style="background-image:url('{{ .Author.AvatarUrl }}');"></div>
|
|
||||||
</div>
|
|
||||||
{{/* TODO: Aggregate user data
|
|
||||||
<div class="c--dim f7">
|
|
||||||
{{ post.author.posts }} posts
|
|
||||||
{% if post.author.public_projects.values|length > 0 %}
|
|
||||||
/ {{ post.author.public_projects.values|length }} project{%if post.author.public_projects.values|length > 1 %}s{% endif %}
|
|
||||||
{% endif %}
|
|
||||||
</div> */}}
|
|
||||||
<!-- Large badges -->
|
|
||||||
<div class="dn db-l pv2">
|
|
||||||
{{ if .Author.IsStaff }}
|
{{ if .Author.IsStaff }}
|
||||||
<div class="badge staff"></div>
|
<div class="badge staff"></div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
<div class="i c--dim f7">
|
|
||||||
{{ if .Author.Blurb }}
|
|
||||||
{{ .Author.Blurb }} {{/* TODO: Linebreaks? */}}
|
|
||||||
{{ else if .Author.Bio }}
|
|
||||||
{{ .Author.Bio }}
|
|
||||||
{{ end }}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{{ else }}
|
{{ if and .Author.Name (ne .Author.Name .Author.Username) }}
|
||||||
<div class="username">Deleted member</div>
|
<div class="c--dim f7"> {{ .Author.Name }} </div>
|
||||||
<div class="avatar" style="background-image:url('{{ .Author.AvatarUrl }}');"></div>
|
{{ end }}
|
||||||
{{ end }}
|
<!-- Large avatar -->
|
||||||
|
<div class="dn db-l w-60 pv2">
|
||||||
|
<div class="aspect-ratio--1x1 contain bg-center" style="background-image:url('{{ .Author.AvatarUrl }}');"></div>
|
||||||
|
</div>
|
||||||
|
{{/* TODO: Aggregate user data
|
||||||
|
<div class="c--dim f7">
|
||||||
|
{{ post.author.posts }} posts
|
||||||
|
{% if post.author.public_projects.values|length > 0 %}
|
||||||
|
/ {{ post.author.public_projects.values|length }} project{%if post.author.public_projects.values|length > 1 %}s{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
</div> */}}
|
||||||
|
<!-- Large badges -->
|
||||||
|
<div class="dn db-l pv2">
|
||||||
|
{{ if .Author.IsStaff }}
|
||||||
|
<div class="badge staff"></div>
|
||||||
|
{{ end }}
|
||||||
|
</div>
|
||||||
|
<div class="i c--dim f7">
|
||||||
|
{{ if .Author.Blurb }}
|
||||||
|
{{ .Author.Blurb }} {{/* TODO: Linebreaks? */}}
|
||||||
|
{{ else if .Author.Bio }}
|
||||||
|
{{ .Author.Bio }}
|
||||||
|
{{ end }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="fl w-100 w-75-l pv3 pa3-l">
|
<div class="fl w-100 w-75-l pv3 pa3-l">
|
||||||
<div class="w-100 flex-l flex-row-reverse-l">
|
<div class="w-100 flex-l flex-row-reverse-l">
|
||||||
|
|
|
@ -77,7 +77,7 @@ type Post struct {
|
||||||
Preview string
|
Preview string
|
||||||
ReadOnly bool
|
ReadOnly bool
|
||||||
|
|
||||||
Author *User
|
Author User
|
||||||
Content template.HTML
|
Content template.HTML
|
||||||
PostDate time.Time
|
PostDate time.Time
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue