invitations: Don't notify now-deactivated users.

While accepting an invitation from a user, there was no condition in
place to check if the user sending the invitation was now
now-deactivated.

Skip sending notifications about newly-joined users to users who are
now disabled.

Fixes #18569.
This commit is contained in:
parth
2021-11-09 21:20:55 +05:30
committed by Alex Vandiver
parent 1e4593b2ae
commit 4edf029ad5
2 changed files with 31 additions and 1 deletions

View File

@@ -503,7 +503,12 @@ def process_new_human_user(
add_new_user_history(user_profile, streams)
# mit_beta_users don't have a referred_by field
if not mit_beta_user and prereg_user is not None and prereg_user.referred_by is not None:
if (
not mit_beta_user
and prereg_user is not None
and prereg_user.referred_by is not None
and prereg_user.referred_by.is_active
):
# This is a cross-realm private message.
with override_language(prereg_user.referred_by.default_language):
internal_send_private_message(

View File

@@ -1281,6 +1281,31 @@ class InviteUserTest(InviteUserBase):
inviter.email,
)
def test_invite_from_now_deactivated_user(self) -> None:
"""
While accepting an invitation from a user,
processing for a new user account will only
be completed if the inviter is not deactivated
after sending the invite.
"""
inviter = self.example_user("hamlet")
self.login_user(inviter)
invitee = self.nonreg_email("alice")
result = self.invite(invitee, ["Denmark"])
self.assert_json_success(result)
prereg_user = PreregistrationUser.objects.get(email=invitee)
change_user_is_active(inviter, False)
do_create_user(
invitee,
"password",
inviter.realm,
"full name",
prereg_user=prereg_user,
acting_user=None,
)
def test_successful_invite_user_as_owner_from_owner_account(self) -> None:
self.login("desdemona")
invitee = self.nonreg_email("alice")