Skip to content

Commit

Permalink
notifications.py: Merge send_local_email_template_with_delay into cal…
Browse files Browse the repository at this point in the history
…lers.

Note that the correctness of this commit relies on the fact that
send_future_email also sets the sender to settings.NOREPLY_EMAIL_ADDRESS by
default (in the body of the function).
  • Loading branch information
rishig authored and timabbott committed May 5, 2017
1 parent a413b0d commit 7741e09
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 41 deletions.
34 changes: 10 additions & 24 deletions zerver/lib/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,13 +485,6 @@ def send_future_email(template_prefix, recipients, sender=None, context={},
% (subject, problems))
return

def send_local_email_template_with_delay(recipients, template_prefix,
template_payload, delay,
tags=[], sender={'email': settings.NOREPLY_EMAIL_ADDRESS, 'name': 'Zulip'}):
# type: (List[Dict[str, Any]], Text, Dict[str, Text], datetime.timedelta, Iterable[Text], Dict[str, Text]) -> None
send_future_email(template_prefix, recipients, sender=sender, context=template_payload,
delay=delay, tags=tags)

def enqueue_welcome_emails(email, name):
# type: (Text, Text) -> None
from zerver.context_processors import common_context
Expand All @@ -502,26 +495,19 @@ def enqueue_welcome_emails(email, name):

user_profile = get_user_profile_by_email(email)
unsubscribe_link = one_click_unsubscribe_link(user_profile, "welcome")
template_payload = common_context(user_profile)
template_payload.update({
context = common_context(user_profile)
context.update({
'verbose_support_offers': settings.VERBOSE_SUPPORT_OFFERS,
'unsubscribe_link': unsubscribe_link
})

# Send day 1 email
send_local_email_template_with_delay([{'email': email, 'name': name}],
"zerver/emails/followup_day1",
template_payload,
datetime.timedelta(hours=1),
tags=["followup-emails"],
sender=sender)
# Send day 2 email
send_local_email_template_with_delay([{'email': email, 'name': name}],
"zerver/emails/followup_day2",
template_payload,
datetime.timedelta(days=1),
tags=["followup-emails"],
sender=sender)
send_future_email(
"zerver/emails/followup_day1", [{'email': email, 'name': name}],
sender=sender, context=context, delay=datetime.timedelta(hours=1),
tags=["followup-emails"])
send_future_email(
"zerver/emails/followup_day2", [{'email': email, 'name': name}],
sender=sender, context=context, delay=datetime.timedelta(days=1),
tags=["followup-emails"])

def convert_html_to_markdown(html):
# type: (Text) -> Text
Expand Down
14 changes: 5 additions & 9 deletions zerver/tests/test_signup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
from zerver.lib.mobile_auth_otp import xor_hex_strings, ascii_to_hex, \
otp_encrypt_api_key, is_valid_otp, hex_to_ascii, otp_decrypt_api_key
from zerver.lib.notifications import enqueue_welcome_emails, \
one_click_unsubscribe_link, send_local_email_template_with_delay, \
send_future_email
one_click_unsubscribe_link, send_future_email
from zerver.lib.test_helpers import find_pattern_in_email, find_key_by_email, queries_captured, \
HostRequestMock, unsign_subdomain_cookie
from zerver.lib.test_classes import (
Expand Down Expand Up @@ -738,13 +737,10 @@ def test_invitation_reminder_email(self):
'support_email': settings.ZULIP_ADMINISTRATOR
})
with self.settings(EMAIL_BACKEND='django.core.mail.backends.console.EmailBackend'):
send_local_email_template_with_delay(
[{'email': data["email"], 'name': ""}],
"zerver/emails/invitation_reminder",
context,
datetime.timedelta(days=0),
tags=["invitation-reminders"],
sender={'email': settings.ZULIP_ADMINISTRATOR, 'name': 'Zulip'})
send_future_email(
"zerver/emails/invitation_reminder", [{'email': data["email"], 'name': ""}],
sender={'email': settings.ZULIP_ADMINISTRATOR, 'name': 'Zulip'},
context=context, tags=["invitation-reminders"])
email_jobs_to_deliver = ScheduledJob.objects.filter(
type=ScheduledJob.EMAIL,
scheduled_timestamp__lte=timezone_now())
Expand Down
15 changes: 7 additions & 8 deletions zerver/worker/queue_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
from zerver.lib.queue import SimpleQueueClient, queue_json_publish
from zerver.lib.timestamp import timestamp_to_datetime
from zerver.lib.notifications import handle_missedmessage_emails, enqueue_welcome_emails, \
clear_followup_emails_queue, send_local_email_template_with_delay, \
send_missedmessage_email
clear_followup_emails_queue, send_future_email, send_missedmessage_email
from zerver.lib.push_notifications import handle_push_notification
from zerver.lib.actions import do_send_confirmation_email, \
do_update_user_activity, do_update_user_activity_interval, do_update_user_presence, \
Expand Down Expand Up @@ -164,13 +163,13 @@ def consume(self, data):
'verbose_support_offers': settings.VERBOSE_SUPPORT_OFFERS,
'support_email': settings.ZULIP_ADMINISTRATOR
})
send_local_email_template_with_delay(
[{'email': data["email"], 'name': ""}],
send_future_email(
"zerver/emails/invitation_reminder",
context,
datetime.timedelta(days=2),
tags=["invitation-reminders"],
sender={'email': settings.ZULIP_ADMINISTRATOR, 'name': 'Zulip'})
[{'email': data["email"], 'name': ""}],
sender={'email': settings.ZULIP_ADMINISTRATOR, 'name': 'Zulip'},
context=context,
delay=datetime.timedelta(days=2),
tags=["invitation-reminders"])

@assign_queue('user_activity')
class UserActivityWorker(QueueProcessingWorker):
Expand Down

0 comments on commit 7741e09

Please sign in to comment.