mirror of https://github.com/zulip/zulip.git
create_user: Send a group DM to admins for low licenses warning.
Earlier, low licenses warning message was sent to the "New user announcements" stream. We plan to disable the stream by default as a part of improving onboarding experience. Now, we send a group DM to admins for low licenses warning to make it independent of the setting. These warning messages are important and shouldn't be missed.
This commit is contained in:
parent
db214c8377
commit
2abc25ac4c
|
@ -11,7 +11,11 @@ from django.utils.translation import override as override_language
|
||||||
from analytics.lib.counts import COUNT_STATS, do_increment_logging_stat
|
from analytics.lib.counts import COUNT_STATS, do_increment_logging_stat
|
||||||
from confirmation import settings as confirmation_settings
|
from confirmation import settings as confirmation_settings
|
||||||
from zerver.actions.invites import notify_invites_changed
|
from zerver.actions.invites import notify_invites_changed
|
||||||
from zerver.actions.message_send import internal_send_private_message, internal_send_stream_message
|
from zerver.actions.message_send import (
|
||||||
|
internal_send_huddle_message,
|
||||||
|
internal_send_private_message,
|
||||||
|
internal_send_stream_message,
|
||||||
|
)
|
||||||
from zerver.actions.streams import bulk_add_subscriptions, send_peer_subscriber_events
|
from zerver.actions.streams import bulk_add_subscriptions, send_peer_subscriber_events
|
||||||
from zerver.actions.user_groups import do_send_user_group_members_update_event
|
from zerver.actions.user_groups import do_send_user_group_members_update_event
|
||||||
from zerver.actions.users import change_user_is_active, get_service_dicts_for_bot
|
from zerver.actions.users import change_user_is_active, get_service_dicts_for_bot
|
||||||
|
@ -81,6 +85,16 @@ def send_message_to_signup_notification_stream(
|
||||||
internal_send_stream_message(sender, signup_announcements_stream, topic_name, message)
|
internal_send_stream_message(sender, signup_announcements_stream, topic_name, message)
|
||||||
|
|
||||||
|
|
||||||
|
def send_group_direct_message_to_admins(sender: UserProfile, realm: Realm, content: str) -> None:
|
||||||
|
administrators = list(realm.get_human_admin_users())
|
||||||
|
internal_send_huddle_message(
|
||||||
|
realm,
|
||||||
|
sender,
|
||||||
|
content,
|
||||||
|
recipient_users=administrators,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def notify_new_user(user_profile: UserProfile) -> None:
|
def notify_new_user(user_profile: UserProfile) -> None:
|
||||||
user_count = realm_user_count(user_profile.realm)
|
user_count = realm_user_count(user_profile.realm)
|
||||||
sender_email = settings.NOTIFICATION_BOT
|
sender_email = settings.NOTIFICATION_BOT
|
||||||
|
@ -92,6 +106,7 @@ def notify_new_user(user_profile: UserProfile) -> None:
|
||||||
message = _("{user} joined this organization.").format(
|
message = _("{user} joined this organization.").format(
|
||||||
user=silent_mention_syntax_for_user(user_profile), user_count=user_count
|
user=silent_mention_syntax_for_user(user_profile), user_count=user_count
|
||||||
)
|
)
|
||||||
|
send_message_to_signup_notification_stream(sender, user_profile.realm, message)
|
||||||
|
|
||||||
if settings.BILLING_ENABLED:
|
if settings.BILLING_ENABLED:
|
||||||
from corporate.lib.registration import generate_licenses_low_warning_message_if_required
|
from corporate.lib.registration import generate_licenses_low_warning_message_if_required
|
||||||
|
@ -102,8 +117,7 @@ def notify_new_user(user_profile: UserProfile) -> None:
|
||||||
if licenses_low_warning_message is not None:
|
if licenses_low_warning_message is not None:
|
||||||
message += "\n"
|
message += "\n"
|
||||||
message += licenses_low_warning_message
|
message += licenses_low_warning_message
|
||||||
|
send_group_direct_message_to_admins(sender, user_profile.realm, message)
|
||||||
send_message_to_signup_notification_stream(sender, user_profile.realm, message)
|
|
||||||
|
|
||||||
|
|
||||||
def set_up_streams_for_new_human_user(
|
def set_up_streams_for_new_human_user(
|
||||||
|
|
|
@ -16,6 +16,8 @@ from zerver.lib.test_classes import ZulipTestCase
|
||||||
from zerver.lib.timezone import canonicalize_timezone
|
from zerver.lib.timezone import canonicalize_timezone
|
||||||
from zerver.models import Message, Realm, Recipient, Stream, UserProfile
|
from zerver.models import Message, Realm, Recipient, Stream, UserProfile
|
||||||
from zerver.models.realms import get_realm
|
from zerver.models.realms import get_realm
|
||||||
|
from zerver.models.recipients import get_huddle_user_ids
|
||||||
|
from zerver.models.users import get_system_bot
|
||||||
from zerver.signals import JUST_CREATED_THRESHOLD, get_device_browser, get_device_os
|
from zerver.signals import JUST_CREATED_THRESHOLD, get_device_browser, get_device_os
|
||||||
|
|
||||||
|
|
||||||
|
@ -294,10 +296,14 @@ class TestNotifyNewUser(ZulipTestCase):
|
||||||
|
|
||||||
def test_notify_realm_of_new_user_in_manual_license_management(self) -> None:
|
def test_notify_realm_of_new_user_in_manual_license_management(self) -> None:
|
||||||
realm = get_realm("zulip")
|
realm = get_realm("zulip")
|
||||||
|
admin_user_ids = set(realm.get_human_admin_users().values_list("id", flat=True))
|
||||||
|
notification_bot = get_system_bot(settings.NOTIFICATION_BOT, realm.id)
|
||||||
|
expected_group_direct_message_user_ids = admin_user_ids | {notification_bot.id}
|
||||||
|
|
||||||
user_count = get_latest_seat_count(realm)
|
user_count = get_latest_seat_count(realm)
|
||||||
|
extra_licenses = 5
|
||||||
self.subscribe_realm_to_monthly_plan_on_manual_license_management(
|
self.subscribe_realm_to_monthly_plan_on_manual_license_management(
|
||||||
realm, user_count + 5, user_count + 5
|
realm, user_count + extra_licenses, user_count + extra_licenses
|
||||||
)
|
)
|
||||||
|
|
||||||
user_no = 0
|
user_no = 0
|
||||||
|
@ -316,8 +322,24 @@ class TestNotifyNewUser(ZulipTestCase):
|
||||||
notify_new_user(new_user)
|
notify_new_user(new_user)
|
||||||
|
|
||||||
message = self.get_last_message()
|
message = self.get_last_message()
|
||||||
|
if extra_licenses - user_no > 3:
|
||||||
|
# More than 3 licenses remaining. No group DM.
|
||||||
actual_stream = Stream.objects.get(id=message.recipient.type_id)
|
actual_stream = Stream.objects.get(id=message.recipient.type_id)
|
||||||
self.assertEqual(actual_stream, realm.signup_announcements_stream)
|
self.assertEqual(actual_stream, realm.signup_announcements_stream)
|
||||||
|
else:
|
||||||
|
# Stream message
|
||||||
|
second_to_last_message = self.get_second_to_last_message()
|
||||||
|
actual_stream = Stream.objects.get(id=second_to_last_message.recipient.type_id)
|
||||||
|
self.assertEqual(actual_stream, realm.signup_announcements_stream)
|
||||||
|
self.assertIn(
|
||||||
|
f"@_**new user {user_no}|{new_user.id}** joined this organization.",
|
||||||
|
second_to_last_message.content,
|
||||||
|
)
|
||||||
|
# Group DM
|
||||||
|
self.assertEqual(
|
||||||
|
set(get_huddle_user_ids(message.recipient)),
|
||||||
|
expected_group_direct_message_user_ids,
|
||||||
|
)
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
f"@_**new user {user_no}|{new_user.id}** joined this organization.",
|
f"@_**new user {user_no}|{new_user.id}** joined this organization.",
|
||||||
message.content,
|
message.content,
|
||||||
|
|
Loading…
Reference in New Issue