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