mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user