A platform for community discussion. Free, open, simple.
FIX: Queue staged email topics with media for review (#42515)
Ethan M507a52f4619c
diff --git a/lib/new_post_manager.rb b/lib/new_post_manager.rbindex 15905c65b62..253f50ae92a 100644--- a/lib/new_post_manager.rb+++ b/lib/new_post_manager.rb@@ -168,15 +168,18 @@ class NewPostManagerendelsif manager.args[:category]category = Category.find_by(id: manager.args[:category])+ skip_topic_validations =+ manager.args[:via_email] && manager.user.staged? && manager.args[:skip_validations]- unless manager.user.guardian.can_create_topic_on_category?(category)+ unless skip_topic_validations || manager.user.guardian.can_create_topic_on_category?(category)result = NewPostResult.new(:created_post, false)result.errors.add(:base, I18n.t("js.errors.reasons.forbidden"))return resultendend- result = manager.enqueue(reason)+ creator_opts = skip_topic_validations ? { skip_validations: true } : {}+ result = manager.enqueue(reason, creator_opts: creator_opts)if result.success? || (reason == :email_spam && is_first_post?(manager))I18n.with_locale(SiteSetting.default_locale) dodiff --git a/spec/fixtures/emails/new_user_with_media.eml b/spec/fixtures/emails/new_user_with_media.emlnew file mode 100644index 00000000000..293d58f1a75--- /dev/null+++ b/spec/fixtures/emails/new_user_with_media.eml@@ -0,0 +1,13 @@+Return-Path: <[email protected]>+From: Foo Bar <[email protected]>+To: [email protected]+Subject: This is a topic from a complete stranger with media+Date: Fri, 15 Jan 2016 00:12:43 +0100+Message-ID: <[email protected]>+Mime-Version: 1.0+Content-Type: text/plain; charset=UTF-8+Content-Transfer-Encoding: quoted-printable++Hey, this is a topic from a complete stranger ;)++diff --git a/spec/lib/email/receiver_spec.rb b/spec/lib/email/receiver_spec.rbindex f0fbc235c44..149d5ce173a 100644--- a/spec/lib/email/receiver_spec.rb+++ b/spec/lib/email/receiver_spec.rb@@ -1019,6 +1019,15 @@ RSpec.describe Email::Receiver doexpect { process(:new_user) }.to change(Topic, :count)end+ it "queues an email with media from a stranger for review" do+ SiteSetting.skip_review_media_groups = Group::AUTO_GROUPS[:trust_level_1]++ expect { process(:new_user_with_media) }.to change(ReviewableQueuedPost, :count).by(1)++ reviewable = ReviewableQueuedPost.order(:id).last+ expect(reviewable.reviewable_scores.first.reason).to eq("contains_media")+ end+it "raises an UserNotFoundError if enable_staged_users is false " doSiteSetting.enable_staged_users = falseexpect { process(:new_user) }.to raise_error(Email::Receiver::UserNotFoundError)