mirror of
https://github.com/zulip/zulip.git
synced 2025-11-21 15:09:34 +00:00
digest.py: Merge send_digest_email into its callers.
Most of the functionality of send_digest_email is being standardized in zerver.lib.notifications.send_future_email.
This commit is contained in:
@@ -146,16 +146,6 @@ def enough_traffic(unread_pms, hot_conversations, new_streams, new_users):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def send_digest_email(user_profile, subject, html_content, text_content):
|
|
||||||
# type: (UserProfile, Text, Text, Text) -> None
|
|
||||||
recipients = [{'email': user_profile.email, 'name': user_profile.full_name}]
|
|
||||||
sender = {'email': settings.NOREPLY_EMAIL_ADDRESS, 'name': 'Zulip'}
|
|
||||||
|
|
||||||
# Send now, through Mandrill.
|
|
||||||
send_future_email(recipients, html_content, text_content, subject,
|
|
||||||
delay=datetime.timedelta(0), sender=sender,
|
|
||||||
tags=["digest-emails"])
|
|
||||||
|
|
||||||
def handle_digest_email(user_profile_id, cutoff):
|
def handle_digest_email(user_profile_id, cutoff):
|
||||||
# type: (int, float) -> None
|
# type: (int, float) -> None
|
||||||
user_profile = UserProfile.objects.get(id=user_profile_id)
|
user_profile = UserProfile.objects.get(id=user_profile_id)
|
||||||
@@ -218,10 +208,15 @@ def handle_digest_email(user_profile_id, cutoff):
|
|||||||
'zerver/emails/digest.txt', template_payload)
|
'zerver/emails/digest.txt', template_payload)
|
||||||
html_content = loader.render_to_string(
|
html_content = loader.render_to_string(
|
||||||
'zerver/emails/digest.html', template_payload)
|
'zerver/emails/digest.html', template_payload)
|
||||||
|
recipients = [{'email': user_profile.email, 'name': user_profile.full_name}]
|
||||||
|
sender = {'email': settings.NOREPLY_EMAIL_ADDRESS, 'name': 'Zulip'}
|
||||||
|
|
||||||
# We don't want to send emails containing almost no information.
|
# We don't want to send emails containing almost no information.
|
||||||
if enough_traffic(template_payload["unread_pms"],
|
if enough_traffic(template_payload["unread_pms"],
|
||||||
template_payload["hot_conversations"],
|
template_payload["hot_conversations"],
|
||||||
new_streams_count, new_users_count):
|
new_streams_count, new_users_count):
|
||||||
logger.info("Sending digest email for %s" % (user_profile.email,))
|
logger.info("Sending digest email for %s" % (user_profile.email,))
|
||||||
send_digest_email(user_profile, subject, html_content, text_content)
|
# Send now, through Mandrill
|
||||||
|
send_future_email(recipients, html_content, text_content, subject,
|
||||||
|
delay=datetime.timedelta(0), sender=sender,
|
||||||
|
tags=["digest-emails"])
|
||||||
|
|||||||
@@ -42,11 +42,11 @@ from zerver.lib.actions import (
|
|||||||
do_set_realm_property,
|
do_set_realm_property,
|
||||||
add_new_user_history,
|
add_new_user_history,
|
||||||
)
|
)
|
||||||
from zerver.lib.digest import send_digest_email
|
|
||||||
from zerver.lib.mobile_auth_otp import xor_hex_strings, ascii_to_hex, \
|
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
|
otp_encrypt_api_key, is_valid_otp, hex_to_ascii, otp_decrypt_api_key
|
||||||
from zerver.lib.notifications import (
|
from zerver.lib.notifications import enqueue_welcome_emails, \
|
||||||
enqueue_welcome_emails, one_click_unsubscribe_link, send_local_email_template_with_delay)
|
one_click_unsubscribe_link, send_local_email_template_with_delay, \
|
||||||
|
send_future_email
|
||||||
from zerver.lib.test_helpers import find_pattern_in_email, find_key_by_email, queries_captured, \
|
from zerver.lib.test_helpers import find_pattern_in_email, find_key_by_email, queries_captured, \
|
||||||
HostRequestMock, unsign_subdomain_cookie
|
HostRequestMock, unsign_subdomain_cookie
|
||||||
from zerver.lib.test_classes import (
|
from zerver.lib.test_classes import (
|
||||||
@@ -856,7 +856,11 @@ class EmailUnsubscribeTests(ZulipTestCase):
|
|||||||
self.assertTrue(user_profile.enable_digest_emails)
|
self.assertTrue(user_profile.enable_digest_emails)
|
||||||
|
|
||||||
# Enqueue a fake digest email.
|
# Enqueue a fake digest email.
|
||||||
send_digest_email(user_profile, "", "", "")
|
send_future_email([{'email': email, 'name': user_profile.name}], "", "", "",
|
||||||
|
delay=datetime.timedelta(0),
|
||||||
|
sender={'email': settings.NOREPLY_EMAIL_ADDRESS, 'name': 'Zulip'},
|
||||||
|
tags=["digest-emails"])
|
||||||
|
|
||||||
self.assertEqual(1, len(ScheduledJob.objects.filter(
|
self.assertEqual(1, len(ScheduledJob.objects.filter(
|
||||||
type=ScheduledJob.EMAIL, filter_string__iexact=email)))
|
type=ScheduledJob.EMAIL, filter_string__iexact=email)))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user