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

This commit is contained in:
Bianca Nenciu 2019-05-07 16:25:52 +03:00 committed by GitHub
parent 1b7be1500f
commit 98a75906c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 3 deletions

View File

@ -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;

View File

@ -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

View File

@ -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)