Skip to content

A platform for community discussion. Free, open, simple.

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

Martin Brennan219b071994a5
diff --git a/app/models/reviewable_queued_post.rb b/app/models/reviewable_queued_post.rb
index d16826888b7..bccce824bc2 100644
--- a/app/models/reviewable_queued_post.rb
+++ b/app/models/reviewable_queued_post.rb
@@ -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?
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index ce1ec74d3b7..cef4041be2b 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -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"
diff --git a/spec/models/reviewable_queued_post_spec.rb b/spec/models/reviewable_queued_post_spec.rb
index 1414a922625..06b22cd3041 100644
--- a/spec/models/reviewable_queued_post_spec.rb
+++ b/spec/models/reviewable_queued_post_spec.rb
@@ -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