A platform for community discussion. Free, open, simple.
FIX: Skip post validations for system revisions when author deletes post (#14824)
Osama Sayeghe2afa1b799b2
diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rbindex f87a191918d..9d09c7ee32d 100644--- a/lib/post_destroyer.rb+++ b/lib/post_destroyer.rb@@ -205,7 +205,8 @@ class PostDestroyer@post.revise(@user,{ raw: I18n.t(key) },force_new_version: true,- deleting_post: true+ deleting_post: true,+ skip_validations: true)Post.transaction dodiff --git a/spec/components/post_destroyer_spec.rb b/spec/components/post_destroyer_spec.rbindex a1e3b989f36..530df2385ce 100644--- a/spec/components/post_destroyer_spec.rb+++ b/spec/components/post_destroyer_spec.rb@@ -473,6 +473,18 @@ describe PostDestroyer doexpect_job_enqueued(job: :sync_topic_user_bookmarked, args: { topic_id: post2.topic_id })end+ it "skips post revise validations when post is marked for deletion by the author" do+ SiteSetting.min_first_post_length = 100+ post = create_post(raw: "this is a long post what passes the min_first_post_length validation " * 3)+ PostDestroyer.new(post.user, post).destroy+ post.reload+ expect(post.errors).to be_blank+ expect(post.revisions.count).to eq(1)+ expect(post.raw).to eq(I18n.t("js.topic.deleted_by_author_simple"))+ expect(post.user_deleted).to eq(true)+ expect(post.topic.closed).to eq(true)+ end+context "as a moderator" doit "deletes the post" doauthor = post.user