mirror of https://github.com/zulip/zulip.git
actions: Send new user messages to signup_notifications_stream.
This commit is contained in:
parent
42652713c8
commit
a0275a6257
|
@ -386,7 +386,7 @@ def build_custom_checkers(by_lang):
|
|||
# This one in check_message is kinda terrible, since it's
|
||||
# how most instances are written, but better to exclude something than nothing
|
||||
('zerver/lib/actions.py', 'stream = get_stream(stream_name, realm)'),
|
||||
('zerver/lib/actions.py', 'get_stream(signups_stream, admin_realm)'),
|
||||
('zerver/lib/actions.py', 'get_stream(admin_realm_signup_notifications_stream, admin_realm)'),
|
||||
# Here we need get_stream to access streams you've since unsubscribed from.
|
||||
('zerver/views/messages.py', 'stream = get_stream(operand, self.user_profile.realm)'),
|
||||
# Use stream_id to exclude mutes.
|
||||
|
|
|
@ -229,7 +229,7 @@ def get_topic_history_for_stream(user_profile, recipient):
|
|||
|
||||
return history
|
||||
|
||||
def send_signup_message(sender, signups_stream, user_profile,
|
||||
def send_signup_message(sender, admin_realm_signup_notifications_stream, user_profile,
|
||||
internal=False, realm=None):
|
||||
# type: (UserProfile, Text, UserProfile, bool, Optional[Realm]) -> None
|
||||
if internal:
|
||||
|
@ -239,24 +239,26 @@ def send_signup_message(sender, signups_stream, user_profile,
|
|||
internal_blurb = " "
|
||||
|
||||
user_count = realm_user_count(user_profile.realm)
|
||||
notifications_stream = user_profile.realm.get_notifications_stream()
|
||||
# Send notification to realm notifications stream if it exists
|
||||
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 notifications_stream is not None and user_count > 1:
|
||||
if signup_notifications_stream is not None and user_count > 1:
|
||||
internal_send_message(
|
||||
user_profile.realm,
|
||||
sender,
|
||||
"stream",
|
||||
notifications_stream.name,
|
||||
"New users", "%s just signed up for Zulip. Say hello!" % (
|
||||
user_profile.full_name,)
|
||||
signup_notifications_stream.name,
|
||||
"signups",
|
||||
"%s (%s) just signed up for Zulip. (total: %i)" % (
|
||||
user_profile.full_name, user_profile.email, user_count
|
||||
)
|
||||
)
|
||||
|
||||
# We also send a notification to the Zulip administrative realm
|
||||
admin_realm = get_system_bot(sender).realm
|
||||
try:
|
||||
# Check whether the stream exists
|
||||
get_stream(signups_stream, admin_realm)
|
||||
get_stream(admin_realm_signup_notifications_stream, admin_realm)
|
||||
except Stream.DoesNotExist:
|
||||
# If the signups stream hasn't been created in the admin
|
||||
# realm, don't auto-create it to send to it; just do nothing.
|
||||
|
@ -265,7 +267,7 @@ def send_signup_message(sender, signups_stream, user_profile,
|
|||
admin_realm,
|
||||
sender,
|
||||
"stream",
|
||||
signups_stream,
|
||||
admin_realm_signup_notifications_stream,
|
||||
user_profile.realm.display_subdomain,
|
||||
"%s <`%s`> just signed up for Zulip!%s(total: **%i**)" % (
|
||||
user_profile.full_name,
|
||||
|
@ -1795,6 +1797,8 @@ def check_message(sender, client, addressee,
|
|||
elif sender.email == settings.WELCOME_BOT:
|
||||
# The welcome bot welcomes folks to the stream.
|
||||
pass
|
||||
elif sender.email == settings.NEW_USER_BOT:
|
||||
pass
|
||||
else:
|
||||
# All other cases are an error.
|
||||
raise JsonableError(_("Not authorized to send to stream '%s'") % (stream.name,))
|
||||
|
|
|
@ -129,8 +129,8 @@ class TestNotifyNewUser(ZulipTestCase):
|
|||
|
||||
def test_notify_realm_of_new_user(self) -> None:
|
||||
new_user = self.example_user('cordelia')
|
||||
stream = self.make_stream('announce')
|
||||
new_user.realm.notifications_stream_id = stream.id
|
||||
stream = self.make_stream('core team')
|
||||
new_user.realm.signup_notifications_stream_id = stream.id
|
||||
new_user.realm.save()
|
||||
new_user = self.example_user('cordelia')
|
||||
notify_new_user(new_user)
|
||||
|
@ -138,4 +138,4 @@ class TestNotifyNewUser(ZulipTestCase):
|
|||
message = self.get_last_message()
|
||||
self.assertEqual(message.recipient.type, Recipient.STREAM)
|
||||
actual_stream = Stream.objects.get(id=message.recipient.type_id)
|
||||
self.assertEqual(actual_stream.name, 'announce')
|
||||
self.assertEqual(actual_stream.name, 'core team')
|
||||
|
|
|
@ -201,6 +201,17 @@ class RealmTest(ZulipTestCase):
|
|||
do_deactivate_stream(notifications_stream)
|
||||
self.assertIsNone(realm.get_notifications_stream())
|
||||
|
||||
def test_get_default_signup_notifications_stream(self) -> None:
|
||||
realm = get_realm("zulip")
|
||||
verona = get_stream("verona", realm)
|
||||
realm.signup_notifications_stream = verona
|
||||
realm.save()
|
||||
|
||||
signup_notifications_stream = realm.get_signup_notifications_stream()
|
||||
self.assertEqual(signup_notifications_stream, verona)
|
||||
do_deactivate_stream(signup_notifications_stream)
|
||||
self.assertIsNone(realm.get_signup_notifications_stream())
|
||||
|
||||
def test_change_realm_default_language(self) -> None:
|
||||
new_lang = "de"
|
||||
realm = get_realm('zulip')
|
||||
|
|
Loading…
Reference in New Issue