FIX: deleted topic author in crawler view (#27788)
When a crawler visits a topic that has a deleted author, it would error because the `show.html.erb` view was expecting a user to be always present. This ensure we don't render the "author" meta data when the author of the topic has been deleted. Internal ref t/132508
This commit is contained in:
parent
f44ec18fd2
commit
0846862cb5
|
@ -52,10 +52,12 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% if @topic_view.crawler_posts&.first && !@topic_view.crawler_posts.first.is_first_post? %>
|
<% if @topic_view.crawler_posts&.first && !@topic_view.crawler_posts.first.is_first_post? %>
|
||||||
<span itemprop='author' itemscope itemtype="http://schema.org/Person">
|
<% if @topic_view.topic.user.present? %>
|
||||||
<meta itemprop='name' content='<%= @topic_view.topic.user.username %>'>
|
<span itemprop='author' itemscope itemtype="http://schema.org/Person">
|
||||||
<link itemprop='url' href='<%= Discourse.base_url %>/u/<%= @topic_view.topic.user.username %>'>
|
<meta itemprop='name' content='<%= @topic_view.topic.user.username %>'>
|
||||||
</span>
|
<link itemprop='url' href='<%= Discourse.base_url %>/u/<%= @topic_view.topic.user.username %>'>
|
||||||
|
</span>
|
||||||
|
<% end %>
|
||||||
<meta itemprop='text' content='<%= @topic_view.topic.excerpt %>'>
|
<meta itemprop='text' content='<%= @topic_view.topic.excerpt %>'>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|
|
@ -5382,6 +5382,12 @@ RSpec.describe TopicsController do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "works even when the author has been deleted" do
|
||||||
|
topic.update!(user_id: nil)
|
||||||
|
|
||||||
|
get "#{topic.relative_url}/2"
|
||||||
|
end
|
||||||
|
|
||||||
context "with canonical_url" do
|
context "with canonical_url" do
|
||||||
fab!(:topic_embed) { Fabricate(:topic_embed, embed_url: "https://markvanlan.com") }
|
fab!(:topic_embed) { Fabricate(:topic_embed, embed_url: "https://markvanlan.com") }
|
||||||
let!(:user_agent) do
|
let!(:user_agent) do
|
||||||
|
|
Loading…
Reference in New Issue