actions: Create send_message_to_signup_notification_stream.

This commit is contained in:
Vishnu KS 2021-01-25 23:43:52 +05:30 committed by Tim Abbott
parent 13cf34f283
commit e019045abe
2 changed files with 28 additions and 18 deletions

View File

@ -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 <strong>Zulip Limited</strong> on "
"<strong>January 2, 2013</strong>",
"You plan is scheduled for downgrade on <strong>January 2, 2013</strong>",
"Cancel downgrade",
], response)
self.assert_in_success_response(
[
"Your plan will be downgraded to <strong>Zulip Limited</strong> on "
"<strong>January 2, 2013</strong>",
"You plan is scheduled for downgrade on <strong>January 2, 2013</strong>",
"Cancel downgrade",
],
response,
)
# Verify that we still write LicenseLedger rows during the remaining
# part of the cycle

View File

@ -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