Skip to content

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

FIX: Unpublish a topic's published page when converting it to a private message (#44069)

Gabriel Grubbac02ca7b231a4
diff --git a/app/models/topic_converter.rb b/app/models/topic_converter.rb
index 4cde42bb953..149c945a34d 100644
--- a/app/models/topic_converter.rb
+++ b/app/models/topic_converter.rb
@@ -70,6 +70,7 @@ class TopicConverter
raise ActiveRecord::Rollback if !revised || [email protected]?
+ PublishedPage.unpublish!(@user, @topic) if @topic.published_page
add_allowed_users
update_post_uploads_secure_status
add_small_action("private_topic") unless @silent
diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb
index 5bdff9c1b4a..ff9c7c0f4c1 100644
--- a/spec/requests/topics_controller_spec.rb
+++ b/spec/requests/topics_controller_spec.rb
@@ -6676,7 +6676,14 @@ RSpec.describe TopicsController do
end
context "with success" do
- it "returns success" do
+ it "revokes a public published page when converting the topic" do
+ SiteSetting.enable_page_publishing = true
+ published_page = Fabricate(:published_page, topic: topic, public: true)
+
+ get published_page.path
+ expect(response.status).to eq(200)
+ expect(response.body).to include(post.raw)
+
sign_in(admin)
put "/t/#{topic.id}/convert-topic/private.json"
@@ -6687,6 +6694,12 @@ RSpec.describe TopicsController do
result = response.parsed_body
expect(result["success"]).to eq(true)
expect(result["url"]).to be_present
+
+ sign_out
+ get published_page.path
+ expect(response.status).to eq(404)
+ expect(response.body).not_to include(post.raw)
+ expect(PublishedPage.exists?(topic: topic)).to eq(false)
end
end
end