Skip to content

A platform for community discussion. Free, open, simple.

FIX: Welcome topic should be hidden on the /categories page as well (#18869)

Blake Ericksonfd207f87307a
diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb
index 33325cf61c2..d6e1a6e2ded 100644
--- a/app/controllers/categories_controller.rb
+++ b/app/controllers/categories_controller.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true
class CategoriesController < ApplicationController
+ include TopicQueryParams
requires_login except: [:index, :categories_and_latest, :categories_and_top, :show, :redirect, :find_by_slug, :visible_groups]
@@ -291,6 +292,8 @@ class CategoriesController < ApplicationController
per_page: CategoriesController.topics_per_page,
no_definitions: true,
}
+
+ topic_options.merge!(build_topic_list_options)
style = SiteSetting.desktop_category_page_style
topic_options[:order] = 'created' if style == "categories_and_latest_topics_created_date"
diff --git a/spec/requests/categories_controller_spec.rb b/spec/requests/categories_controller_spec.rb
index 5b927b7d99e..facf7c0cb86 100644
--- a/spec/requests/categories_controller_spec.rb
+++ b/spec/requests/categories_controller_spec.rb
@@ -235,6 +235,54 @@ RSpec.describe CategoriesController do
end
end
+ describe "welcome topic" do
+ fab!(:category) { Fabricate(:category) }
+ fab!(:topic1) { Fabricate(:topic, category: category, created_at: 5.days.ago, updated_at: Time.now, bumped_at: Time.now) }
+ fab!(:topic2) { Fabricate(:topic, category: category, created_at: 2.days.ago, bumped_at: 2.days.ago) }
+ fab!(:topic3) { Fabricate(:topic, category: category, created_at: 1.day.ago, bumped_at: 1.day.ago) }
+ fab!(:welcome_topic) { Fabricate(:topic) }
+ fab!(:post) { Fabricate(:post, topic: welcome_topic) }
+
+ before do
+ SiteSetting.desktop_category_page_style = "categories_and_latest_topics"
+ SiteSetting.welcome_topic_id = welcome_topic.id
+ SiteSetting.editing_grace_period = 1.minute.to_i
+ SiteSetting.bootstrap_mode_enabled = true
+ end
+
+ it "is hidden for non-admins" do
+ get "/categories_and_latest.json"
+ expect(response.status).to eq(200)
+ expect(response.parsed_body['topic_list']['topics'].map { |t| t["id"] }).not_to include(welcome_topic.id)
+ end
+
+ it "is shown to non-admins when there is an edit" do
+ post.revise(post.user, { raw: "#{post.raw}2" }, revised_at: post.updated_at + 2.minutes)
+ post.reload
+ expect(post.version).to eq(2)
+
+ get "/categories_and_latest.json"
+ expect(response.status).to eq(200)
+ expect(response.parsed_body['topic_list']['topics'].map { |t| t["id"] }).to include(welcome_topic.id)
+ end
+
+ it "is hidden to admins" do
+ sign_in(admin)
+
+ get "/categories_and_latest.json"
+ expect(response.status).to eq(200)
+ expect(response.parsed_body['topic_list']['topics'].map { |t| t["id"] }).not_to include(welcome_topic.id)
+ end
+
+ it "is shown to users when bootstrap mode is disabled" do
+ SiteSetting.bootstrap_mode_enabled = false
+
+ get "/categories_and_latest.json"
+ expect(response.status).to eq(200)
+ expect(response.parsed_body['topic_list']['topics'].map { |t| t["id"] }).to include(welcome_topic.id)
+ end
+ end
+
it 'includes subcategories and topics by default when view is subcategories_with_featured_topics' do
SiteSetting.max_category_nesting = 3
subcategory = Fabricate(:category, user: admin, parent_category: category)