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:
parent
475b4892e3
commit
7f56abac90
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue