FIX: Skip post validations for system revisions when author deletes post (#14824)

This commit is contained in:
Osama Sayegh 2021-11-08 04:33:41 +03:00 committed by GitHub
parent b1dc0dc944
commit e2afa1b799
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -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 do

View File

@ -473,6 +473,18 @@ describe PostDestroyer do
expect_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" do
it "deletes the post" do
author = post.user