FIX: Keep ReviewableQueuedPosts even with user delete reviewable actions (#22501)

Performing a `Delete User`/`Delete and Block User` reviewable actions for a
queued post reviewable from the `review.show` route results in an error
popup even if the action completes successfully.

This happens because unlike other reviewable types, a user delete action
on a queued post reviewable results in the deletion of the reviewable
itself. A subsequent attempt to reload the reviewable record results in
404. The deletion happens as part of the call to `UserDestroyer` which
includes a step for destroying reviewables created by the user being
destroyed. At the root of this is the creator of the queued post
being set as the creator of the reviewable as instead of the system
user.

This change assigns the creator of the reviewable to the system user and
uses the more approapriate `target_created_by` column for the creator of the
post being queued.
This commit is contained in:
Selase Krakani
2023-07-18 11:50:31 +00:00
committed by GitHub
parent 3a1dc7ec6d
commit 3d554aa10e
14 changed files with 146 additions and 33 deletions

View File

@ -1105,7 +1105,7 @@ RSpec.describe PostsController do
user.reload
expect(user).to be_silenced
rp = ReviewableQueuedPost.find_by(created_by: user)
rp = ReviewableQueuedPost.find_by(target_created_by: user)
expect(rp.payload["typing_duration_msecs"]).to eq(100)
expect(rp.payload["composer_open_duration_msecs"]).to eq(204)
expect(rp.payload["reply_to_post_number"]).to eq(123)
@ -1199,7 +1199,7 @@ RSpec.describe PostsController do
parsed = response.parsed_body
expect(parsed["action"]).to eq("enqueued")
reviewable = ReviewableQueuedPost.find_by(created_by: user)
reviewable = ReviewableQueuedPost.find_by(target_created_by: user)
score = reviewable.reviewable_scores.first
expect(score.reason).to eq("auto_silence_regex")
@ -1222,7 +1222,7 @@ RSpec.describe PostsController do
parsed = response.parsed_body
expect(parsed["action"]).to eq("enqueued")
reviewable = ReviewableQueuedPost.find_by(created_by: user)
reviewable = ReviewableQueuedPost.find_by(target_created_by: user)
score = reviewable.reviewable_scores.first
expect(score.reason).to eq("auto_silence_regex")