FIX: Use correct group out of multiple for SMTP sender (#14957)

When there are multiple groups on a topic, we were selecting
the first from the topic allowed groups to act as the sender
email address when sending group SMTP replies via PostAlerter.
However, this was not ordered, and since there is no created_at
column on TopicAllowedGroup we cannot order this nicely, which
caused just a random group to be used (based on whatever postgres
decided it felt like that morning).

This commit changes the group used for SMTP sending to be the
group using the email_username of the to address of the first
incoming email for the topic, if there are more than one allowed
groups on the topic. Otherwise it just uses the only SMTP enabled
group.
This commit is contained in:
Martin Brennan
2021-11-16 10:21:49 +10:00
committed by GitHub
parent f4d1fe18f8
commit 31035010af
3 changed files with 30 additions and 1 deletions

View File

@@ -1777,6 +1777,10 @@ class Topic < ActiveRecord::Base
end
end
def first_smtp_enabled_group
self.allowed_groups.where(smtp_enabled: true).first
end
private
def invite_to_private_message(invited_by, target_user, guardian)