A platform for community discussion. Free, open, simple.
FIX: remove post-action when a post is permanently deleted (#11242)
Krzysztof Kotlarek7f56abac90a4
diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rbindex e5bff487bb0..c85fcbca2f5 100644--- a/lib/post_destroyer.rb+++ b/lib/post_destroyer.rb@@ -254,7 +254,7 @@ class PostDestroyer.limit(1).first- if last_post.present? && @post.topic.present?+ if last_post.present?topic = @post.topictopic.last_posted_at = last_post.created_attopic.last_post_user_id = last_post.user_id@@ -277,7 +277,9 @@ class PostDestroyerdef trash_public_post_actionsif public_post_actions = PostAction.publics.where(post_id: @post.id)- public_post_actions.each { |pa| pa.trash!(@user) }+ public_post_actions.each { |pa| permanent? ? pa.destroy! : pa.trash!(@user) }++ return if permanent?@post.custom_fields["deleted_public_actions"] = public_post_actions.ids@post.save_custom_fieldsdiff --git a/spec/components/post_destroyer_spec.rb b/spec/components/post_destroyer_spec.rbindex be1f3aa9c27..6ec8622ed3f 100644--- a/spec/components/post_destroyer_spec.rb+++ b/spec/components/post_destroyer_spec.rb@@ -965,6 +965,7 @@ describe PostDestroyer dodescribe "permanent destroy" dofab!(:private_message_topic) { Fabricate(:private_message_topic) }fab!(:private_post) { Fabricate(:private_message_post, topic: private_message_topic) }+ fab!(:post_action) { Fabricate(:post_action, post: private_post) }fab!(:reply) { Fabricate(:private_message_post, topic: private_message_topic) }it "destroys the post and topic if deleting first post" doPostDestroyer.new(reply.user, reply, permanent: true).destroy@@ -974,6 +975,7 @@ describe PostDestroyer doPostDestroyer.new(private_post.user, private_post, permanent: true).destroyexpect { private_post.reload }.to raise_error(ActiveRecord::RecordNotFound)expect { private_message_topic.reload }.to raise_error(ActiveRecord::RecordNotFound)+ expect { post_action.reload }.to raise_error(ActiveRecord::RecordNotFound)endit 'soft delete if not creator of post or not private message' do