FIX: Resolve issue where deleted spam topics marked as Not Spam were not being recovered (#10322)

If a user posted a topic and Akismet decided it was spam, the topic gets deleted and put into the review queue. If a category moderator for that category marked the post/topic as "Not Spam" the topic did not get recovered correctly because Guardian.new(@user).can_review_topic?(@post.topic) returned false incorrectly because the topic was deleted.
This commit is contained in:
Martin Brennan 2020-07-28 12:06:15 +10:00 committed by GitHub
parent 4fd59c9b26
commit 2e5b2d20ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -214,7 +214,8 @@ class PostDestroyer
private private
def post_is_reviewable? def post_is_reviewable?
Guardian.new(@user).can_review_topic?(@post.topic) && Reviewable.exists?(target: @post) topic = @post.topic || Topic.with_deleted.find(@post.topic_id)
Guardian.new(@user).can_review_topic?(topic) && Reviewable.exists?(target: @post)
end end
# we need topics to change if ever a post in them is deleted or created # we need topics to change if ever a post in them is deleted or created

View File

@ -289,7 +289,7 @@ describe PostDestroyer do
ReviewableFlaggedPost.needs_review!(target: @reply, created_by: Fabricate(:user)) ReviewableFlaggedPost.needs_review!(target: @reply, created_by: Fabricate(:user))
end end
it "changes deleted_at to nil" do def changes_deleted_at_to_nil
PostDestroyer.new(Discourse.system_user, @reply).destroy PostDestroyer.new(Discourse.system_user, @reply).destroy
@reply.reload @reply.reload
expect(@reply.user_deleted).to eq(false) expect(@reply.user_deleted).to eq(false)
@ -299,6 +299,19 @@ describe PostDestroyer do
@reply.reload @reply.reload
expect(@reply.deleted_at).to eq(nil) expect(@reply.deleted_at).to eq(nil)
end end
it "changes deleted_at to nil" do
changes_deleted_at_to_nil
end
context "when the topic is deleted" do
before do
@reply.topic.trash!
end
it "changes deleted_at to nil" do
changes_deleted_at_to_nil
end
end
end end
context "when the post does not have a Reviewable record" do context "when the post does not have a Reviewable record" do