FIX: remove post-action when a post is permanently deleted (#11242)

Followup of https://github.com/discourse/discourse/pull/11115

When we permanently remove the post, we should remove related post-actions as well.
This commit is contained in:
Krzysztof Kotlarek 2020-11-17 07:40:36 +11:00 committed by GitHub
parent 475b4892e3
commit 7f56abac90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -254,7 +254,7 @@ class PostDestroyer
.limit(1)
.first
if last_post.present? && @post.topic.present?
if last_post.present?
topic = @post.topic
topic.last_posted_at = last_post.created_at
topic.last_post_user_id = last_post.user_id
@ -277,7 +277,9 @@ class PostDestroyer
def trash_public_post_actions
if 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_fields

View File

@ -965,6 +965,7 @@ describe PostDestroyer do
describe "permanent destroy" do
fab!(: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" do
PostDestroyer.new(reply.user, reply, permanent: true).destroy
@ -974,6 +975,7 @@ describe PostDestroyer do
PostDestroyer.new(private_post.user, private_post, permanent: true).destroy
expect { 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)
end
it 'soft delete if not creator of post or not private message' do