emails: Change welcome emails to use to_user_id.

This commit is contained in:
Rishi Gupta 2017-07-10 20:48:09 -07:00 committed by Tim Abbott
parent b0d325b8c5
commit eacdb0b302
4 changed files with 9 additions and 9 deletions

View File

@ -355,6 +355,7 @@ def process_new_human_user(user_profile, prereg_user=None, newsletter_data=None)
"signups",
{
'email_address': user_profile.email,
'user_id': user_profile.id,
'merge_fields': {
'NAME': user_profile.full_name,
'REALM_ID': user_profile.realm_id,

View File

@ -407,8 +407,8 @@ def log_digest_event(msg):
logging.basicConfig(filename=settings.DIGEST_LOG_PATH, level=logging.INFO)
logging.info(msg)
def enqueue_welcome_emails(email, name, realm):
# type: (Text, Text, Realm) -> None
def enqueue_welcome_emails(user_id):
# type: (int) -> None
from zerver.context_processors import common_context
if settings.WELCOME_EMAIL_SENDER is not None:
# line break to avoid triggering lint rule
@ -418,17 +418,17 @@ def enqueue_welcome_emails(email, name, realm):
from_name = None
from_address = FromAddress.SUPPORT
user_profile = get_user(email, realm)
user_profile = get_user_profile_by_id(user_id)
unsubscribe_link = one_click_unsubscribe_link(user_profile, "welcome")
context = common_context(user_profile)
context.update({
'unsubscribe_link': unsubscribe_link
})
send_future_email(
"zerver/emails/followup_day1", to_email='%s <%s>' % (name, email), from_name=from_name,
"zerver/emails/followup_day1", to_user_id=user_id, from_name=from_name,
from_address=from_address, context=context, delay=datetime.timedelta(hours=1))
send_future_email(
"zerver/emails/followup_day2", to_email='%s <%s>' % (name, email), from_name=from_name,
"zerver/emails/followup_day2", to_user_id=user_id, from_name=from_name,
from_address=from_address, context=context, delay=datetime.timedelta(days=1))
def convert_html_to_markdown(html):

View File

@ -792,9 +792,8 @@ class EmailUnsubscribeTests(ZulipTestCase):
"""
email = self.example_email("hamlet")
user_profile = self.example_user('hamlet')
realm = get_realm("zulip")
# Simulate a new user signing up, which enqueues 2 welcome e-mails.
enqueue_welcome_emails(email, "King Hamlet", realm)
enqueue_welcome_emails(user_profile.id)
self.assertEqual(2, len(ScheduledJob.objects.filter(
type=ScheduledJob.EMAIL, filter_string__iexact=email)))

View File

@ -157,11 +157,11 @@ class SignupWorker(QueueProcessingWorker):
# type: (Mapping[str, Any]) -> None
# This should clear out any invitation reminder emails
clear_followup_emails_queue(data['email_address'])
realm = Realm.objects.get(id=data['merge_fields']['REALM_ID'])
if settings.MAILCHIMP_API_KEY and settings.PRODUCTION:
endpoint = "https://%s.api.mailchimp.com/3.0/lists/%s/members" % \
(settings.MAILCHIMP_API_KEY.split('-')[1], settings.ZULIP_FRIENDS_LIST_ID)
params = dict(data)
del params['user_id']
params['list_id'] = settings.ZULIP_FRIENDS_LIST_ID
params['status'] = 'subscribed'
r = requests.post(endpoint, auth=('apikey', settings.MAILCHIMP_API_KEY), json=params, timeout=10)
@ -171,7 +171,7 @@ class SignupWorker(QueueProcessingWorker):
else:
r.raise_for_status()
enqueue_welcome_emails(data['email_address'], data['merge_fields']['NAME'], realm)
enqueue_welcome_emails(data['user_id'])
@assign_queue('invites')
class ConfirmationEmailWorker(QueueProcessingWorker):