FIX: Revise and reject post breaks on new topics queued (#24109)

Followup to 9762e65758. This
original commit did not take into account the fact that
new topics can end up in the approval queue as a
ReviewableQueuedPost, and so there was a 500 error raised
when accessing `self.topic` when sending a PM to the user.
This commit is contained in:
Martin Brennan 2023-10-27 13:05:41 +10:00 committed by GitHub
parent d0915027a8
commit 219b071994
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 3 deletions

View File

@ -163,8 +163,8 @@ class ReviewableQueuedPost < Reviewable
def perform_revise_and_reject_post(performed_by, args)
pm_translation_args = {
topic_title: self.topic.title,
topic_url: self.topic.url,
topic_title: self.topic&.title || self.payload["title"],
topic_url: self.topic&.url,
reason: args[:revise_custom_reason].presence || args[:revise_reason],
feedback: args[:revise_feedback],
original_post: self.payload["raw"],
@ -172,7 +172,13 @@ class ReviewableQueuedPost < Reviewable
}
SystemMessage.create_from_system_user(
self.target_created_by,
:reviewable_queued_post_revise_and_reject,
(
if self.topic.blank?
:reviewable_queued_post_revise_and_reject_new_topic
else
:reviewable_queued_post_revise_and_reject
end
),
pm_translation_args,
)
StaffActionLogger.new(performed_by).log_post_rejected(self, DateTime.now) if performed_by.staff?

View File

@ -3010,6 +3010,29 @@ en:
Thanks,
%{site_name} Moderators
reviewable_queued_post_revise_and_reject_new_topic:
title: "Feedback on your topic"
subject_template: "Feedback on new topic titled \"%{topic_title}\""
text_body_template: |
Hi %{username},
We've reviewed your new topic titled "%{topic_title}" and have some feedback for you.
Reason: %{reason}
Feedback: %{feedback}
You can edit your topic's original post below and re-submit to make the suggested changes, or reply to this message if you have any questions.
--------
%{original_post}
--------
Thanks,
%{site_name} Moderators
post_hidden_again:
title: "Post Hidden again"
subject_template: "Post hidden by community flags, staff notified"

View File

@ -178,6 +178,40 @@ RSpec.describe ReviewableQueuedPost, type: :model do
expect(topic.first_post.raw).not_to include("Other...")
expect(topic.first_post.raw).to include("Boring")
end
context "when the topic is nil in the case of a new topic being created" do
let(:reviewable) { Fabricate(:reviewable_queued_post_topic) }
it "works" do
args = { revise_reason: "Duplicate", revise_feedback: "This is old news" }
expect { reviewable.perform(moderator, :revise_and_reject_post, args) }.to change {
Topic.where(archetype: Archetype.private_message).count
}
topic = Topic.where(archetype: Archetype.private_message).last
expect(topic.title).to eq(
I18n.t(
"system_messages.reviewable_queued_post_revise_and_reject_new_topic.subject_template",
topic_title: reviewable.payload["title"],
),
)
translation_params = {
username: reviewable.target_created_by.username,
topic_title: reviewable.payload["title"],
topic_url: nil,
reason: args[:revise_reason],
feedback: args[:revise_feedback],
original_post: reviewable.payload["raw"],
site_name: SiteSetting.title,
}
expect(topic.first_post.raw.chomp).to eq(
I18n.t(
"system_messages.reviewable_queued_post_revise_and_reject_new_topic.text_body_template",
translation_params,
).chomp,
)
end
end
end
context "with delete_user" do