mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
emails: Don't send day2 email if user already has an account.
This commit is contained in:
@@ -504,6 +504,8 @@ def enqueue_welcome_emails(user: UserProfile, realm_creation: bool=False) -> Non
|
||||
from_name = None
|
||||
from_address = FromAddress.SUPPORT
|
||||
|
||||
other_account_count = UserProfile.objects.filter(
|
||||
email__iexact=user.email).exclude(id=user.id).count()
|
||||
unsubscribe_link = one_click_unsubscribe_link(user, "welcome")
|
||||
context = common_context(user)
|
||||
context.update({
|
||||
@@ -527,9 +529,11 @@ def enqueue_welcome_emails(user: UserProfile, realm_creation: bool=False) -> Non
|
||||
send_future_email(
|
||||
"zerver/emails/followup_day1", user.realm, to_user_id=user.id, from_name=from_name,
|
||||
from_address=from_address, context=context)
|
||||
send_future_email(
|
||||
"zerver/emails/followup_day2", user.realm, to_user_id=user.id, from_name=from_name,
|
||||
from_address=from_address, context=context, delay=followup_day2_email_delay(user))
|
||||
|
||||
if other_account_count == 0:
|
||||
send_future_email(
|
||||
"zerver/emails/followup_day2", user.realm, to_user_id=user.id, from_name=from_name,
|
||||
from_address=from_address, context=context, delay=followup_day2_email_delay(user))
|
||||
|
||||
def convert_html_to_markdown(html: str) -> str:
|
||||
# On Linux, the tool installs as html2markdown, and there's a command called
|
||||
|
||||
@@ -87,6 +87,26 @@ class TestFollowupEmails(ZulipTestCase):
|
||||
email_data = ujson.loads(scheduled_emails[0].data)
|
||||
self.assertEqual(email_data["context"]["ldap_username"], True)
|
||||
|
||||
def test_followup_emails_count(self) -> None:
|
||||
hamlet = self.example_user("hamlet")
|
||||
cordelia = self.example_user("cordelia")
|
||||
|
||||
enqueue_welcome_emails(self.example_user("hamlet"))
|
||||
# Hamlet has account only in Zulip realm so both day1 and day2 emails should be sent
|
||||
scheduled_emails = ScheduledEmail.objects.filter(user=hamlet)
|
||||
self.assertEqual(2, len(scheduled_emails))
|
||||
self.assertEqual(ujson.loads(scheduled_emails[0].data)["template_prefix"], 'zerver/emails/followup_day2')
|
||||
self.assertEqual(ujson.loads(scheduled_emails[1].data)["template_prefix"], 'zerver/emails/followup_day1')
|
||||
|
||||
ScheduledEmail.objects.all().delete()
|
||||
|
||||
enqueue_welcome_emails(cordelia)
|
||||
scheduled_emails = ScheduledEmail.objects.filter(user=cordelia)
|
||||
# Cordelia has account in more than 1 realm so day2 email should not be sent
|
||||
self.assertEqual(len(scheduled_emails), 1)
|
||||
email_data = ujson.loads(scheduled_emails[0].data)
|
||||
self.assertEqual(email_data["template_prefix"], 'zerver/emails/followup_day1')
|
||||
|
||||
class TestMissedMessages(ZulipTestCase):
|
||||
def normalize_string(self, s: str) -> str:
|
||||
s = s.strip()
|
||||
|
||||
Reference in New Issue
Block a user