From e019045abefdd178a8a482fb43ee9743de3e39a9 Mon Sep 17 00:00:00 2001 From: Vishnu KS Date: Mon, 25 Jan 2021 23:43:52 +0530 Subject: [PATCH] actions: Create send_message_to_signup_notification_stream. --- corporate/tests/test_stripe.py | 15 +++++++++------ zerver/lib/actions.py | 31 +++++++++++++++++++------------ 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py index 0e1c0b1088..6df00d0e27 100644 --- a/corporate/tests/test_stripe.py +++ b/corporate/tests/test_stripe.py @@ -1815,12 +1815,15 @@ class StripeTest(StripeTestCase): mock_customer = Mock(email=user.delivery_email, default_source=None) with patch("corporate.views.stripe_get_customer", return_value=mock_customer): response = self.client_get("/billing/") - self.assert_in_success_response([ - "Your plan will be downgraded to Zulip Limited on " - "January 2, 2013", - "You plan is scheduled for downgrade on January 2, 2013", - "Cancel downgrade", - ], response) + self.assert_in_success_response( + [ + "Your plan will be downgraded to Zulip Limited on " + "January 2, 2013", + "You plan is scheduled for downgrade on January 2, 2013", + "Cancel downgrade", + ], + response, + ) # Verify that we still write LicenseLedger rows during the remaining # part of the cycle diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index c956f197aa..42abb6a2ba 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -344,20 +344,27 @@ def get_signups_stream(realm: Realm) -> Stream: return get_stream("signups", realm) -def notify_new_user(user_profile: UserProfile) -> None: - sender_email = settings.NOTIFICATION_BOT - sender = get_system_bot(sender_email) +def send_message_to_signup_notification_stream( + sender: UserProfile, realm: Realm, message: str, topic_name: str = _("signups") +) -> None: + signup_notifications_stream = realm.get_signup_notifications_stream() + if signup_notifications_stream is None: + return + with override_language(realm.default_language): + internal_send_stream_message(sender, signup_notifications_stream, topic_name, message) + + +def notify_new_user(user_profile: UserProfile) -> None: user_count = realm_user_count(user_profile.realm) - signup_notifications_stream = user_profile.realm.get_signup_notifications_stream() - # Send notification to realm signup notifications stream if it exists - # Don't send notification for the first user in a realm - if signup_notifications_stream is not None and user_count > 1: - with override_language(user_profile.realm.default_language): - message = _("{user} just signed up for Zulip. (total: {user_count})").format( - user=f"@_**{user_profile.full_name}|{user_profile.id}**", user_count=user_count - ) - internal_send_stream_message(sender, signup_notifications_stream, _("signups"), message) + sender = get_system_bot(settings.NOTIFICATION_BOT) + + is_first_user = user_count == 1 + if not is_first_user: + message = _("{user} just signed up for Zulip. (total: {user_count})").format( + user=f"@_**{user_profile.full_name}|{user_profile.id}**", user_count=user_count + ) + send_message_to_signup_notification_stream(sender, user_profile.realm, message) # We also send a notification to the Zulip administrative realm admin_realm = sender.realm