A platform for community discussion. Free, open, simple.
FIX: use PostRevisor with Topic context when revising posts from deleted topics (#36168)
Gabriel Grubba2f78101ce2f8
diff --git a/plugins/automation/lib/discourse_automation/scripts/remove_upload_markup_from_deleted_posts.rb b/plugins/automation/lib/discourse_automation/scripts/remove_upload_markup_from_deleted_posts.rbindex a9ccaec2d59..ebab4736805 100644--- a/plugins/automation/lib/discourse_automation/scripts/remove_upload_markup_from_deleted_posts.rb+++ b/plugins/automation/lib/discourse_automation/scripts/remove_upload_markup_from_deleted_posts.rb@@ -33,12 +33,18 @@ DiscourseAutomation::Scriptable.add(.limit(DiscourseAutomation::REMOVE_UPLOAD_MARKUP_FROM_DELETED_POSTS_BATCH_SIZE).each do |post|if updated_raw = post.raw.gsub!(upload_and_attachment_regex, "")+ topic =+ if post.topic.nil?+ Topic.with_deleted.find_by_id(post.topic_id)+ else+ post.topic+ end+if ok =- post.revise(+ PostRevisor.new(post, topic).revise!(Discourse.system_user,{ raw: updated_raw, edit_reason: edit_reason },- force_new_version: true,- skip_validations: true,+ { force_new_version: true, skip_validations: true },)post.custom_fields["uploads_removed_at"] = uploads_removed_atpost.save_custom_fieldsdiff --git a/plugins/automation/spec/scripts/remove_upload_markup_from_deleted_posts_spec.rb b/plugins/automation/spec/scripts/remove_upload_markup_from_deleted_posts_spec.rbindex 326e620bfc3..6c8fa261a5f 100644--- a/plugins/automation/spec/scripts/remove_upload_markup_from_deleted_posts_spec.rb+++ b/plugins/automation/spec/scripts/remove_upload_markup_from_deleted_posts_spec.rb@@ -50,6 +50,18 @@ describe "RemoveUploadMarkupFromDeletedPosts" doexpect(post.raw).to eq(raw)end+ it "works even if the topic is deleted" do+ topic.deleted_at = 1.month.ago+ topic.save!++ expect {+ automation.trigger!+ deleted_post.reload+ }.to change { deleted_post.raw }.from(raw).to(+ "Hey it is a regular post with a link to [Discourse](https://www.discourse.org) and a",+ )+ end+it "does not remove uploads from non-deleted posts" doexpect {automation.trigger!