FIX: Destroy all posts when hard deleting topic (#17359)

Hard deleting topics that contained soft deleted posts or small actions
used to create orphan posts because only the first post was hard
deleted. This commit adds an error message if there are still posts left
in the topic that must be hard deleted first or hard deletes all small
actions too immediately (there is no other way of hard deleting a small
action because there is no wrench menu).
This commit is contained in:
Bianca Nenciu
2022-08-10 12:11:50 +03:00
committed by GitHub
parent 590a13377b
commit a0537816fb
7 changed files with 88 additions and 13 deletions

View File

@@ -1786,7 +1786,12 @@ class Topic < ActiveRecord::Base
end
def cannot_permanently_delete_reason(user)
if self.posts_count > 0
all_posts_count = Post.with_deleted
.where(topic_id: self.id)
.where(post_type: [Post.types[:regular], Post.types[:moderator_action], Post.types[:whisper]])
.count
if posts_count > 0 || all_posts_count > 1
I18n.t('post.cannot_permanently_delete.many_posts')
elsif self.deleted_by_id == user&.id && self.deleted_at >= Post::PERMANENT_DELETE_TIMER.ago
time_left = RateLimiter.time_left(Post::PERMANENT_DELETE_TIMER.to_i - Time.zone.now.to_i + self.deleted_at.to_i)