Skip to content

Open-source live-chat, email support, omni-channel desk. An alternative to Intercom, Zendesk, Salesforce Service Cloud etc. 🔥💬

fix: hide the authors line on category pages when every author is deleted (#16298)

Sivin Varghesee952d7555836
diff --git a/app/views/public/api/v1/portals/_authors.html.erb b/app/views/public/api/v1/portals/_authors.html.erb
index f7dc1eb3ef9..f81b24f219f 100644
--- a/app/views/public/api/v1/portals/_authors.html.erb
+++ b/app/views/public/api/v1/portals/_authors.html.erb
@@ -1,16 +1,17 @@
-<% author_count = category.articles.published.order(position: :asc).map(&:author).uniq.size %>
+<% authors = category.articles.published.order(position: :asc).filter_map(&:author).uniq %>
+<% author_count = authors.size %>
<% if author_count > 0 %>
<div class="flex flex-row items-center gap-1">
<div class="flex items-center ltr:flex-row rtl:flex-row-reverse -space-x-2">
<% z_classes = %w[z-30 z-20 z-10] %>
- <% category.articles.published.order(position: :asc).map(&:author).uniq.take(3).each_with_index do |author, idx| %>
+ <% authors.take(3).each_with_index do |author, idx| %>
<span class="relative <%= z_classes[idx] %>">
<%= render "public/api/v1/portals/thumbnail", author: author, size: 5 %>
</span>
<% end %>
</div>
- <% first_author = category.articles.published.order(position: :asc).map(&:author).uniq.first&.name || '' %>
+ <% first_author = authors.first.name %>
<% author_text = author_count > 1 ? "#{author_count} #{I18n.t('public_portal.common.authors')}" : "#{author_count} #{I18n.t('public_portal.common.author')}" %>
<% other_authors_count = author_count - 1 %>
<% other_authors_text = other_authors_count > 1 ? I18n.t('public_portal.common.others') : I18n.t('public_portal.common.other') %>
@@ -23,5 +24,6 @@
<%= author_text %>
<% end %>
</span>
+ <span class="text-slate-600 dark:text-slate-400">•</span>
</div>
<% end %>
diff --git a/app/views/public/api/v1/portals/_category-block.html+plain.erb b/app/views/public/api/v1/portals/_category-block.html+plain.erb
index 7e4ae037127..be927c45bab 100644
--- a/app/views/public/api/v1/portals/_category-block.html+plain.erb
+++ b/app/views/public/api/v1/portals/_category-block.html+plain.erb
@@ -48,7 +48,6 @@
<div class="flex justify-between flex-row items-center">
<div class="flex flex-row items-center gap-1">
<%= render "public/api/v1/portals/authors", category: category, show_expanded: false %>
- <span class="text-slate-600 dark:text-slate-400">•</span>
<span class="text-sm font-medium text-slate-600 dark:text-slate-400"><%= render 'public/api/v1/portals/article_count', article_count: category.articles.published.order(position: :asc).size %></span>
</div>
<div>
diff --git a/app/views/public/api/v1/portals/_category-block.html.erb b/app/views/public/api/v1/portals/_category-block.html.erb
index 248b77a003a..e7645f69590 100644
--- a/app/views/public/api/v1/portals/_category-block.html.erb
+++ b/app/views/public/api/v1/portals/_category-block.html.erb
@@ -48,7 +48,6 @@
<div class="flex justify-between flex-row items-center px-2">
<div class="flex flex-row items-center gap-1">
<%= render "public/api/v1/portals/authors", category: category, show_expanded: false %>
- <span class="text-slate-600 dark:text-slate-400">•</span>
<span class="text-sm font-medium text-slate-600 dark:text-slate-400"><%= render 'public/api/v1/portals/article_count', article_count: category.articles.published.order(position: :asc).size %></span>
</div>
<div>
diff --git a/app/views/public/api/v1/portals/categories/_category-hero.html.erb b/app/views/public/api/v1/portals/categories/_category-hero.html.erb
index ab00fcf9e7c..469731227c6 100644
--- a/app/views/public/api/v1/portals/categories/_category-hero.html.erb
+++ b/app/views/public/api/v1/portals/categories/_category-hero.html.erb
@@ -24,7 +24,6 @@
</div>
<div class="flex flex-row items-center gap-1">
<%= render "public/api/v1/portals/authors", category: category, show_expanded: true %>
- <span class="text-slate-600 dark:text-slate-400">•</span>
<span class="flex items-center text-base text-slate-600 dark:text-slate-400 font-medium"><%= render 'public/api/v1/portals/article_count', article_count: category.articles.published.size %></span>
</div>
</div>
diff --git a/spec/controllers/public/api/v1/portals/categories_controller_spec.rb b/spec/controllers/public/api/v1/portals/categories_controller_spec.rb
index 6636d9bc083..ea1a2811e4c 100644
--- a/spec/controllers/public/api/v1/portals/categories_controller_spec.rb
+++ b/spec/controllers/public/api/v1/portals/categories_controller_spec.rb
@@ -29,5 +29,16 @@ RSpec.describe 'Public Categories API', type: :request do
expect(response).to have_http_status(:success)
end
+
+ it 'does not show the authors line when the only author has been deleted' do
+ category = portal.categories.first
+ article = create(:article, category: category, portal: portal, account_id: account.id)
+ article.author.destroy!
+
+ get "/hc/#{portal.slug}/#{category.locale}/categories/#{category.slug}"
+
+ expect(response).to have_http_status(:success)
+ expect(response.body).not_to include("#{I18n.t('public_portal.common.by')} ")
+ end
end
end