A platform for community discussion. Free, open, simple.
FIX: Do not send emails to mailing_list_mode subscribers for PMs (#14159)
Martin Brennane43a8af3bd59
diff --git a/app/jobs/regular/notify_mailing_list_subscribers.rb b/app/jobs/regular/notify_mailing_list_subscribers.rbindex 861dc27977c..c535296105f 100644--- a/app/jobs/regular/notify_mailing_list_subscribers.rb+++ b/app/jobs/regular/notify_mailing_list_subscribers.rb@@ -28,7 +28,8 @@ module Jobspost_id = args[:post_id]post = post_id ? Post.with_deleted.find_by(id: post_id) : nil- return if !post || post.trashed? || post.user_deleted? || !post.topic || post.raw.blank?+ return if !post || post.trashed? || post.user_deleted? ||+ !post.topic || post.raw.blank? || post.topic.private_message?users =User.activated.not_silenced.not_suspended.realdiff --git a/lib/post_jobs_enqueuer.rb b/lib/post_jobs_enqueuer.rbindex 80d49c59751..93a29f5663f 100644--- a/lib/post_jobs_enqueuer.rb+++ b/lib/post_jobs_enqueuer.rb@@ -55,10 +55,13 @@ class PostJobsEnqueuerdef after_post_createJobs.enqueue(:post_update_topic_tracking_state, post_id: @post.id)- Jobs.enqueue_in(SiteSetting.email_time_window_mins.minutes,- :notify_mailing_list_subscribers,- post_id: @post.id,- )+ if [email protected]_message?+ Jobs.enqueue_in(+ SiteSetting.email_time_window_mins.minutes,+ :notify_mailing_list_subscribers,+ post_id: @post.id,+ )+ endenddef after_topic_creatediff --git a/spec/jobs/notify_mailing_list_subscribers_spec.rb b/spec/jobs/notify_mailing_list_subscribers_spec.rbindex d0d2f758fd6..8b0421c4b82 100644--- a/spec/jobs/notify_mailing_list_subscribers_spec.rb+++ b/spec/jobs/notify_mailing_list_subscribers_spec.rb@@ -80,6 +80,15 @@ describe Jobs::NotifyMailingListSubscribers doinclude_examples "no emails"end+ context "with a private message" do+ before do+ post.topic.update!(archetype: Archetype.private_message, category: nil)+ TopicAllowedUser.create(topic: post.topic, user: mailing_list_user)+ post.topic.reload+ end+ include_examples "no emails"+ end+context "with a valid post from another user" docontext "to an inactive user" dodiff --git a/spec/lib/post_jobs_enqueuer_spec.rb b/spec/lib/post_jobs_enqueuer_spec.rbnew file mode 100644index 00000000000..a5477cf4468--- /dev/null+++ b/spec/lib/post_jobs_enqueuer_spec.rb@@ -0,0 +1,105 @@+# frozen_string_literal: true++require 'rails_helper'++RSpec.describe PostJobsEnqueuer do+ let!(:post) { Fabricate(:post, topic: topic) }+ let!(:topic) { Fabricate(:topic) }+ let(:new_topic) { false }+ let(:opts) { { post_alert_options: {} } }++ subject { described_class.new(post, topic, new_topic, opts) }++ context "for regular topics" do+ it "enqueues the :post_alert job" do+ expect_enqueued_with(job: :post_alert, args: {+ post_id: post.id,+ new_record: true,+ options: opts[:post_alert_options]+ }) do+ subject.enqueue_jobs+ end+ end++ it "enqueues the :notify_mailing_list_subscribers job" do+ expect_enqueued_with(job: :notify_mailing_list_subscribers, args: { post_id: post.id }) do+ subject.enqueue_jobs+ end+ end++ it "enqueues the :post_update_topic_tracking_state job" do+ expect_enqueued_with(job: :post_update_topic_tracking_state, args: { post_id: post.id }) do+ subject.enqueue_jobs+ end+ end++ it "enqueues the :feature_topic_users job" do+ expect_enqueued_with(job: :feature_topic_users, args: { topic_id: topic.id }) do+ subject.enqueue_jobs+ end+ end++ context "for new topics" do+ let(:new_topic) { true }++ it "calls the correct topic tracking state class to publish_new" do+ TopicTrackingState.expects(:publish_new).with(topic)+ PrivateMessageTopicTrackingState.expects(:publish_new).never+ subject.enqueue_jobs+ end+ end+ end++ context "for private messages" do+ let!(:topic) { Fabricate(:private_message_topic) }++ it "does not enqueue the :notify_mailing_list_subscribers job" do+ expect_not_enqueued_with(job: :notify_mailing_list_subscribers, args: { post_id: post.id }) do+ subject.enqueue_jobs+ end+ end++ it "enqueues the :post_update_topic_tracking_state job" do+ expect_enqueued_with(job: :post_update_topic_tracking_state, args: { post_id: post.id }) do+ subject.enqueue_jobs+ end+ end++ it "enqueues the :feature_topic_users job" do+ expect_enqueued_with(job: :feature_topic_users, args: { topic_id: topic.id }) do+ subject.enqueue_jobs+ end+ end++ context "for new topics" do+ let(:new_topic) { true }++ it "calls the correct topic tracking state class to publish_new" do+ TopicTrackingState.expects(:publish_new).never+ PrivateMessageTopicTrackingState.expects(:publish_new).with(topic)+ subject.enqueue_jobs+ end+ end++ context "for a post > post_number 1" do+ let!(:post) do+ Fabricate(:post, topic: topic)+ Fabricate(:post, topic: topic)+ end++ context "when there is a topic embed" do+ before do+ SiteSetting.embed_unlisted = true+ topic.update(visible: false)+ Fabricate(:topic_embed, post: post, embed_url: "http://test.com")+ end++ it "does not enqueue the :make_embedded_topic_visible job" do+ expect_not_enqueued_with(job: :make_embedded_topic_visible, args: { topic_id: topic.id }) do+ subject.enqueue_jobs+ end+ end+ end+ end+ end+end