A platform for community discussion. Free, open, simple.
FIX: Error when SMTP enabled in PostAlerter with no incoming email (#14981)
Martin Brennan515acb8fc4f4
diff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rbindex 5e394e9417a..c52922d9c09 100644--- a/app/services/post_alerter.rb+++ b/app/services/post_alerter.rb@@ -639,12 +639,17 @@ class PostAlerterenddef group_notifying_via_smtp(post)- return nil if !SiteSetting.enable_smtp || post.post_type != Post.types[:regular]+ return if !SiteSetting.enable_smtp || post.post_type != Post.types[:regular]+ return if post.topic.allowed_groups.none?+if post.topic.allowed_groups.count == 1return post.topic.first_smtp_enabled_groupend- group = Group.find_by_email(post.topic.incoming_email.first.to_addresses)+ topic_incoming_email = post.topic.incoming_email.first+ return if topic_incoming_email.blank?++ group = Group.find_by_email(topic_incoming_email.to_addresses)if !group&.smtp_enabledreturn post.topic.first_smtp_enabled_groupenddiff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rbindex 877db1a3d3e..b2335c81239 100644--- a/spec/services/post_alerter_spec.rb+++ b/spec/services/post_alerter_spec.rb@@ -1362,6 +1362,30 @@ describe PostAlerter doEmail::Receiver.new(raw_mail, {}).process!end+ it "does not error if SMTP is enabled and the topic has no incoming email or allowed groups" do+ topic = Fabricate(:private_message_topic)+ Fabricate(:post, topic: topic)+ post = Fabricate(:post, topic: topic)+ expect { PostAlerter.new.after_save_post(post, true) }.not_to raise_error+ end++ it "does not error if SMTP is enabled and the topic has no incoming email but does have an allowed group" do+ topic = Fabricate(:private_message_topic)+ Fabricate(:post, topic: topic)+ post = Fabricate(:post, topic: topic)+ TopicAllowedGroup.create(topic: topic, group: Fabricate(:group))+ expect { PostAlerter.new.after_save_post(post, true) }.not_to raise_error+ end++ it "does not error if SMTP is enabled and the topic has no incoming email but has multiple allowed groups" do+ topic = Fabricate(:private_message_topic)+ Fabricate(:post, topic: topic)+ post = Fabricate(:post, topic: topic)+ TopicAllowedGroup.create(topic: topic, group: Fabricate(:group))+ TopicAllowedGroup.create(topic: topic, group: Fabricate(:group))+ expect { PostAlerter.new.after_save_post(post, true) }.not_to raise_error+ end+it "sends a group smtp email because SMTP is enabled for the site and the group" doincoming_email_post = create_post_with_incomingtopic = incoming_email_post.topic