diff --git a/zerver/lib/notifications.py b/zerver/lib/notifications.py index 062886d52d..d677345dcc 100644 --- a/zerver/lib/notifications.py +++ b/zerver/lib/notifications.py @@ -17,7 +17,7 @@ from zerver.models import ( Stream, get_display_recipient, UserProfile, - get_user_profile_by_email, + get_user, get_user_profile_by_id, receives_offline_notifications, get_context_for_message, @@ -400,8 +400,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): - # type: (Text, Text) -> None +def enqueue_welcome_emails(email, name, realm): + # type: (Text, Text, Realm) -> None from zerver.context_processors import common_context if settings.WELCOME_EMAIL_SENDER is not None: # line break to avoid triggering lint rule @@ -411,7 +411,7 @@ def enqueue_welcome_emails(email, name): from_name = None from_address = FromAddress.SUPPORT - user_profile = get_user_profile_by_email(email) + user_profile = get_user(email, realm) unsubscribe_link = one_click_unsubscribe_link(user_profile, "welcome") context = common_context(user_profile) context.update({ diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py index 4d0978abfe..c7cbebdf80 100644 --- a/zerver/tests/test_signup.py +++ b/zerver/tests/test_signup.py @@ -787,9 +787,9 @@ 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") + enqueue_welcome_emails(email, "King Hamlet", realm) self.assertEqual(2, len(ScheduledJob.objects.filter( type=ScheduledJob.EMAIL, filter_string__iexact=email))) diff --git a/zerver/worker/queue_processors.py b/zerver/worker/queue_processors.py index 981b0241b5..673c500852 100644 --- a/zerver/worker/queue_processors.py +++ b/zerver/worker/queue_processors.py @@ -157,6 +157,7 @@ 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) @@ -170,7 +171,7 @@ class SignupWorker(QueueProcessingWorker): else: r.raise_for_status() - enqueue_welcome_emails(data['email_address'], data['merge_fields']['NAME']) + enqueue_welcome_emails(data['email_address'], data['merge_fields']['NAME'], realm) @assign_queue('invites') class ConfirmationEmailWorker(QueueProcessingWorker):