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:
parent
db40941deb
commit
928a6cd143
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue