示例#1
0
        def create_new_user_and_verify_strings_in_notification_message(
                strings_present: Sequence[str] = [],
                strings_absent: Sequence[str] = []) -> None:
            user_no = random.randrange(100000)
            new_user = UserProfile.objects.create(
                realm=realm,
                full_name=f"new user {user_no}",
                email=f"user-{user_no}[email protected]",
                delivery_email=f"user-{user_no}[email protected]",
            )
            notify_new_user(new_user)

            message = self.get_last_message()
            actual_stream = Stream.objects.get(id=message.recipient.type_id)
            self.assertEqual(actual_stream, realm.signup_notifications_stream)
            self.assertIn(
                f"@_**new user {user_no}|{new_user.id}** just signed up for Zulip.",
                message.content,
            )
            for string_present in strings_present:
                self.assertIn(
                    string_present,
                    message.content,
                )
            for string_absent in strings_absent:
                self.assertNotIn(string_absent, message.content)
示例#2
0
    def test_notify_of_new_user_internally(self) -> None:
        new_user = self.example_user('cordelia')
        self.make_stream('signups')
        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)
示例#3
0
    def test_notify_realm_of_new_user(self) -> None:
        new_user = self.example_user('cordelia')
        stream = self.make_stream(Realm.INITIAL_PRIVATE_STREAM_NAME)
        new_user.realm.signup_notifications_stream_id = stream.id
        new_user.realm.save()
        new_user = self.example_user('cordelia')
        notify_new_user(new_user)

        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, Realm.INITIAL_PRIVATE_STREAM_NAME)
示例#4
0
    def test_notify_realm_of_new_user(self):
        # type: () -> None
        new_user = self.example_user('cordelia')
        stream = self.make_stream('announce')
        new_user.realm.notifications_stream_id = stream.id
        new_user.realm.save()
        new_user = self.example_user('cordelia')
        notify_new_user(new_user)

        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')
示例#5
0
    def test_notify_realm_of_new_user(self):
        # type: () -> None
        new_user = self.example_user('cordelia')
        stream = self.make_stream('announce')
        new_user.realm.notifications_stream_id = stream.id
        new_user.realm.save()
        new_user = self.example_user('cordelia')
        notify_new_user(new_user)

        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')
示例#6
0
    def handle(self, *args, **options):
        # type: (*Any, **Any) -> None
        if not options["tos"]:
            raise CommandError(
                """You must confirm that this user has accepted the
Terms of Service by passing --this-user-has-accepted-the-tos.""")

        if not options["string_id"]:
            raise CommandError(
                """Please specify a realm by passing --realm.""")

        try:
            realm = get_realm(options["string_id"])
        except Realm.DoesNotExist:
            raise CommandError("Realm does not exist.")

        try:
            email = options['email']
            full_name = options['full_name']
            try:
                validators.validate_email(email)
            except ValidationError:
                raise CommandError("Invalid email address.")
        except KeyError:
            if 'email' in options or 'full_name' in options:
                raise CommandError(
                    """Either specify an email and full name as two
parameters, or specify no parameters for interactive user creation.""")
            else:
                while True:
                    email = input("Email: ")
                    try:
                        validators.validate_email(email)
                        break
                    except ValidationError:
                        print("Invalid email address.", file=sys.stderr)
                full_name = input("Full name: ")

        try:
            if 'password' in options:
                pw = options['password']
            if 'password_file' in options:
                pw = open(options['password_file'], 'r').read()
            else:
                pw = initial_password(email).encode()
            notify_new_user(do_create_user(email, pw, realm, full_name,
                                           email_to_username(email)),
                            internal=True)
        except IntegrityError:
            raise CommandError("User already exists.")
    def test_notify_realm_of_new_user(self) -> None:
        new_user = self.example_user("cordelia")
        stream = self.make_stream(Realm.INITIAL_PRIVATE_STREAM_NAME)
        new_user.realm.signup_notifications_stream_id = stream.id
        new_user.realm.save()
        new_user = self.example_user("cordelia")
        notify_new_user(new_user)

        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, Realm.INITIAL_PRIVATE_STREAM_NAME)
        self.assertIn(
            f"@_**Cordelia Lear|{new_user.id}** just signed up for Zulip.",
            message.content)
示例#8
0
    def handle(self, *args: Any, **options: Any) -> None:
        if not options["tos"]:
            raise CommandError(
                """You must confirm that this user has accepted the
Terms of Service by passing --this-user-has-accepted-the-tos.""")
        realm = self.get_realm(options)
        assert realm is not None  # Should be ensured by parser

        try:
            email = options['email']
            full_name = options['full_name']
            try:
                validators.validate_email(email)
            except ValidationError:
                raise CommandError("Invalid email address.")
        except KeyError:
            if 'email' in options or 'full_name' in options:
                raise CommandError(
                    """Either specify an email and full name as two
parameters, or specify no parameters for interactive user creation.""")
            else:
                while True:
                    email = input("Email: ")
                    try:
                        validators.validate_email(email)
                        break
                    except ValidationError:
                        print("Invalid email address.", file=sys.stderr)
                full_name = input("Full name: ")

        try:
            if 'password' in options:
                pw = options['password']
            if 'password_file' in options:
                pw = open(options['password_file'], 'r').read()
            else:
                user_initial_password = initial_password(email)
                if user_initial_password is None:
                    raise CommandError("Password is unusable.")
                pw = user_initial_password.encode()
            notify_new_user(do_create_user(email, pw, realm, full_name,
                                           email_to_username(email)),
                            internal=True)
        except IntegrityError:
            raise CommandError("User already exists.")
示例#9
0
    def handle(self, *args: Any, **options: Any) -> None:
        if not options["tos"]:
            raise CommandError("""You must confirm that this user has accepted the
Terms of Service by passing --this-user-has-accepted-the-tos.""")
        realm = self.get_realm(options)
        assert realm is not None  # Should be ensured by parser

        try:
            email = options['email']
            full_name = options['full_name']
            try:
                validators.validate_email(email)
            except ValidationError:
                raise CommandError("Invalid email address.")
        except KeyError:
            if 'email' in options or 'full_name' in options:
                raise CommandError("""Either specify an email and full name as two
parameters, or specify no parameters for interactive user creation.""")
            else:
                while True:
                    email = input("Email: ")
                    try:
                        validators.validate_email(email)
                        break
                    except ValidationError:
                        print("Invalid email address.", file=sys.stderr)
                full_name = input("Full name: ")

        try:
            if 'password' in options:
                pw = options['password']
            if 'password_file' in options:
                pw = open(options['password_file'], 'r').read()
            else:
                user_initial_password = initial_password(email)
                if user_initial_password is None:
                    raise CommandError("Password is unusable.")
                pw = user_initial_password.encode()
            notify_new_user(do_create_user(email, pw,
                                           realm, full_name, email_to_username(email)),
                            internal=True)
        except IntegrityError:
            raise CommandError("User already exists.")
示例#10
0
    def handle(self, *args, **options):
        # type: (*Any, **Any) -> None
        if not options["tos"]:
            raise CommandError("""You must confirm that this user has accepted the
Terms of Service by passing --this-user-has-accepted-the-tos.""")

        if not options["string_id"]:
            raise CommandError("""Please specify a realm by passing --realm.""")

        try:
            realm = get_realm(options["string_id"])
        except Realm.DoesNotExist:
            raise CommandError("Realm does not exist.")

        try:
            email = options['email']
            full_name = options['full_name']
            try:
                validators.validate_email(email)
            except ValidationError:
                raise CommandError("Invalid email address.")
        except KeyError:
            if 'email' in options or 'full_name' in options:
                raise CommandError("""Either specify an email and full name as two
parameters, or specify no parameters for interactive user creation.""")
            else:
                while True:
                    email = input("Email: ")
                    try:
                        validators.validate_email(email)
                        break
                    except ValidationError:
                        print("Invalid email address.", file=sys.stderr)
                full_name = input("Full name: ")

        try:
            pw = options.get('password', initial_password(email))
            notify_new_user(do_create_user(email, pw,
                                           realm, full_name, email_to_username(email)),
                            internal=True)
        except IntegrityError:
            raise CommandError("User already exists.")
示例#11
0
    def test_notify_realm_of_new_user(self) -> None:
        realm = get_realm("zulip")
        new_user = self.example_user("cordelia")
        admin_realm = get_realm("zulipinternal")
        admin_realm_signups_stream, created = create_stream_if_needed(
            admin_realm, "signups")
        message_count = self.get_message_count()

        notify_new_user(new_user)
        self.assertEqual(self.get_message_count(), message_count + 2)
        message = self.get_second_to_last_message()
        self.assertEqual(message.recipient.type, Recipient.STREAM)
        actual_stream = Stream.objects.get(id=message.recipient.type_id)
        self.assertEqual(actual_stream.name, Realm.INITIAL_PRIVATE_STREAM_NAME)
        self.assertIn(
            f"@_**Cordelia, Lear's daughter|{new_user.id}** just signed up for Zulip.",
            message.content,
        )
        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, "signups")
        self.assertIn(
            f"Cordelia, Lear's daughter <`{new_user.email}`> just signed up for Zulip. (total:",
            message.content,
        )

        admin_realm_signups_stream.delete()
        notify_new_user(new_user)
        self.assertEqual(self.get_message_count(), message_count + 3)
        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, Realm.INITIAL_PRIVATE_STREAM_NAME)
        self.assertIn(
            f"@_**Cordelia, Lear's daughter|{new_user.id}** just signed up for Zulip.",
            message.content,
        )
        realm.signup_notifications_stream = None
        realm.save(update_fields=["signup_notifications_stream"])
        new_user.refresh_from_db()
        notify_new_user(new_user)
        self.assertEqual(self.get_message_count(), message_count + 3)