Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
users: Test that deleted users cannot be reactivated.
Agnish Bauri1c00a7f90eb1
diff --git a/zerver/actions/create_user.py b/zerver/actions/create_user.pyindex 55848cbb00d..2261afd01c7 100644--- a/zerver/actions/create_user.py+++ b/zerver/actions/create_user.py@@ -708,14 +708,14 @@ def do_activate_mirror_dummy_user(@transaction.atomic(savepoint=False)def do_reactivate_user(user_profile: UserProfile, *, acting_user: UserProfile | None) -> None:"""Reactivate a user that had previously been deactivated"""+ if user_profile.is_deleted:+ raise JsonableError(_("Cannot reactivate a deleted user"))+if user_profile.is_mirror_dummy:raise JsonableError(_("Cannot activate a placeholder account; ask the user to sign up, instead."))- if user_profile.is_deleted: # nocoverage- raise JsonableError(_("Cannot reactivate a deleted user"))-change_user_is_active(user_profile, True)event_time = timezone_now()diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.pyindex c31aa63bc38..19cf3a1ffc1 100644--- a/zerver/tests/test_users.py+++ b/zerver/tests/test_users.py@@ -3996,6 +3996,16 @@ class DeleteUserTest(ZulipTestCase):result = orjson.loads(self.client_get(f"/json/users/{hamlet_user_id}").content)self.assertEqual(result["user"]["is_deleted"], True)+ def test_reactivate_deleted_user(self) -> None:+ hamlet = self.example_user("hamlet")+ do_delete_user(hamlet, acting_user=None)+ hamlet.refresh_from_db()+ self.assertTrue(hamlet.is_deleted)++ self.login("iago")+ result = self.client_post(f"/json/users/{hamlet.id}/reactivate")+ self.assert_json_error(result, "Cannot reactivate a deleted user")+def test_do_delete_user_preserving_messages(self) -> None:"""Since do_delete_user and do_delete_user_preserving_messages share the same