Skip to content

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

FIX: Close topics deleted by users and ensure topic stubs are destroyed. (#7430)

Bianca Nenciu98a75906c85e
diff --git a/app/assets/javascripts/discourse/lib/transform-post.js.es6 b/app/assets/javascripts/discourse/lib/transform-post.js.es6
index eccfb196e6b..90693c3dcee 100644
--- a/app/assets/javascripts/discourse/lib/transform-post.js.es6
+++ b/app/assets/javascripts/discourse/lib/transform-post.js.es6
@@ -227,8 +227,8 @@ export default function transformPost(
}
if (postAtts.post_number === 1) {
- postAtts.canRecoverTopic = topic.deleted_at && details.can_recover;
- postAtts.canDeleteTopic = !topic.deleted_at && details.can_delete;
+ postAtts.canRecoverTopic = postAtts.isDeleted && details.can_recover;
+ postAtts.canDeleteTopic = !postAtts.isDeleted && details.can_delete;
postAtts.expandablePost = topic.expandable_first_post;
} else {
postAtts.canRecover = postAtts.isDeleted && postAtts.canRecover;
diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rb
index e25b9e04620..97ffd52c748 100644
--- a/lib/post_destroyer.rb
+++ b/lib/post_destroyer.rb
@@ -22,7 +22,7 @@ class PostDestroyer
WHERE t.deleted_at IS NOT NULL AND
t.id = posts.topic_id
)")
- .where("updated_at < ? AND post_number > 1", SiteSetting.delete_removed_posts_after.hours.ago)
+ .where("updated_at < ?", SiteSetting.delete_removed_posts_after.hours.ago)
.where("NOT EXISTS (
SELECT 1
FROM post_actions pa
@@ -176,6 +176,7 @@ class PostDestroyer
Post.transaction do
@post.update_column(:user_deleted, true)
@post.topic_links.each(&:destroy)
+ @post.topic.update_column(:closed, true) if @post.is_first_post?
end
end
end
@@ -186,6 +187,7 @@ class PostDestroyer
Post.transaction do
@post.update_column(:user_deleted, false)
@post.skip_unique_check = true
+ @post.topic.update_column(:closed, false) if @post.is_first_post?
end
# has internal transactions, if we nest then there are some very high risk deadlocks
diff --git a/spec/components/post_destroyer_spec.rb b/spec/components/post_destroyer_spec.rb
index 52f9d26fb75..ddba7b20735 100644
--- a/spec/components/post_destroyer_spec.rb
+++ b/spec/components/post_destroyer_spec.rb
@@ -52,6 +52,16 @@ describe PostDestroyer do
end
describe 'destroy_old_stubs' do
+ it 'destroys stubs for deleted by user topics' do
+ SiteSetting.delete_removed_posts_after = 24
+
+ PostDestroyer.new(post.user, post).destroy
+ post.update_column(:updated_at, 2.days.ago)
+
+ PostDestroyer.destroy_stubs
+ expect(post.reload.deleted_at).not_to eq(nil)
+ end
+
it 'destroys stubs for deleted by user posts' do
SiteSetting.delete_removed_posts_after = 24
Fabricate(:admin)