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

* FIX: Welcome topic should be hidden on the /categories page as well

* add tests
This commit is contained in:
Blake Erickson 2022-11-07 09:24:55 -07:00 committed by GitHub
parent 8700c5ee6b
commit fd207f8730
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 0 deletions

View File

@ -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"

View File

@ -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)