cross realm bots: Simplify notify_new_user.

Instead of having `notify_new_user` delegate
all the heavy lifting to `send_signup_message`,
we just rename `send_signup_message` to be
`notify_new_user` and remove the one-line
wrapper.

We remove a lot of obsolete complexity:

    - `internal` was no longer ever set to True
      by real code, so we kill it off as well
      as well as killing off the internal_blurb code
      and the now-obsolete test

    - the `sender` parameter was actually an
      email, not a UserProfile, but I think
      that got past mypy due to the caller
      passing in something from settings.py

    - we were only passing in NOTIFICATION_BOT
      for the sender, so we just hard code
      that now

    - we eliminate the verbose
      `admin_realm_signup_notifications_stream`
      parameter and just hard code it to
      "signups"

    - we weren't using the optional realm
      parameter

There's also a long ugly comment in
`get_recipient_info` related to this code
that I amended for now.
We should try to take action in a subsequent
commit.
This commit is contained in:
Steve Howell
2020-02-10 14:17:42 +00:00
committed by Tim Abbott
parent 6e40db4b1f
commit b33552997e
3 changed files with 20 additions and 33 deletions

View File

@@ -6,7 +6,7 @@ from django.test import override_settings
from zerver.lib.test_classes import ZulipTestCase
from zerver.signals import get_device_browser, get_device_os, JUST_CREATED_THRESHOLD
from zerver.lib.actions import notify_new_user, do_change_notification_settings
from zerver.models import Recipient, Stream, Realm, get_realm
from zerver.models import Recipient, Stream, Realm
from zerver.lib.initial_password import initial_password
from unittest import mock
from zerver.lib.timezone import get_timezone
@@ -171,17 +171,6 @@ class TestBrowserAndOsUserAgentStrings(ZulipTestCase):
class TestNotifyNewUser(ZulipTestCase):
def test_notify_of_new_user_internally(self) -> None:
new_user = self.example_user('cordelia')
self.make_stream('signups', get_realm(settings.SYSTEM_BOT_REALM))
notify_new_user(new_user, internal=True)
message = self.get_last_message()
actual_stream = Stream.objects.get(id=message.recipient.type_id)
self.assertEqual(actual_stream.name, 'signups')
self.assertEqual(message.recipient.type, Recipient.STREAM)
self.assertIn("**INTERNAL SIGNUP**", message.content)
def test_notify_realm_of_new_user(self) -> None:
new_user = self.example_user('cordelia')
stream = self.make_stream(Realm.INITIAL_PRIVATE_STREAM_NAME)