FIX: Delete fast typer reviewable when deleting user (#23162)

In most cases, deleting a user from outside the review UI will also delete any pending reviewables for that user. This was not working in some cases, e.g. for reviewables created due to "fast typer" violations.

This was happening because UserDestroyer only automatically resolves flagged posts.

After this change, in addition to existing checks, look for ReviewablePost where the post was created by the user and reject them if present.
This commit is contained in:
Ted Johansson 2023-08-21 18:03:03 +08:00 committed by GitHub
parent db40941deb
commit 928a6cd143
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View File

@ -137,6 +137,14 @@ class UserDestroyer
reviewable.perform(@actor, :agree_and_keep)
end
end
ReviewablePost
.where(target_created_by: user)
.find_each do |reviewable|
if reviewable.actions_for(@guardian).has?(:reject_and_delete)
reviewable.perform(@actor, :reject_and_delete)
end
end
end
def delete_posts(user, category_topic_ids, opts)

View File

@ -203,6 +203,26 @@ RSpec.describe UserDestroyer do
reviewable.reload
expect(reviewable).to be_approved
end
it "rejects pending posts" do
post = Fabricate(:post, user: user)
reviewable =
Fabricate(
:reviewable,
type: "ReviewablePost",
target_type: "Post",
target_id: post.id,
created_by: Discourse.system_user,
target_created_by: user,
)
expect(reviewable).to be_pending
destroy
reviewable.reload
expect(reviewable).to be_rejected
end
end
end