From ad523b3745c7e04c01b11263f17bf64f8d0be8f8 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 1 Oct 2021 17:13:59 -0500 Subject: [PATCH] Fix #4895: Deleted forum topics visible by default in index. The bug was that since search parameters normally come from URL request parameters, a string value is expected here. --- app/controllers/forum_topics_controller.rb | 2 +- test/functional/forum_topics_controller_test.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/controllers/forum_topics_controller.rb b/app/controllers/forum_topics_controller.rb index cf4082597..ef127a025 100644 --- a/app/controllers/forum_topics_controller.rb +++ b/app/controllers/forum_topics_controller.rb @@ -17,7 +17,7 @@ class ForumTopicsController < ApplicationController def index if request.format.html? limit = params.fetch(:limit, 40) - @forum_topics = authorize ForumTopic.visible(CurrentUser.user).paginated_search(params, limit: limit, defaults: { order: "sticky", is_deleted: false }) + @forum_topics = authorize ForumTopic.visible(CurrentUser.user).paginated_search(params, limit: limit, defaults: { order: "sticky", is_deleted: "false" }) else @forum_topics = authorize ForumTopic.visible(CurrentUser.user).paginated_search(params) end diff --git a/test/functional/forum_topics_controller_test.rb b/test/functional/forum_topics_controller_test.rb index a138f76fa..d59707331 100644 --- a/test/functional/forum_topics_controller_test.rb +++ b/test/functional/forum_topics_controller_test.rb @@ -124,6 +124,15 @@ class ForumTopicsControllerTest < ActionDispatch::IntegrationTest assert_equal(ForumTopic.visible(User.anonymous).count, response.parsed_body.css("urlset url loc").size) end + should "not show deleted topics for HTML responses by default" do + as(@user) { create(:forum_topic, is_deleted: true) } + get forum_topics_path + + assert_response :success + assert_select 'tr[data-is-deleted="true"]', count: 0 + assert_select 'tr[data-is-deleted="false"]', count: 3 + end + context "with private topics" do should "not show private topics to unprivileged users" do as(@user) { @other_topic.update!(min_level: User::Levels::MODERATOR) }