Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
users: Fix ordering issue with deactivating bots.
Tim Abbott53ed759fc174
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.pyindex 366eafcfa92..2be9fcf5a5b 100644--- a/zerver/lib/actions.py+++ b/zerver/lib/actions.py@@ -1146,6 +1146,16 @@ def do_deactivate_user(if not user_profile.is_active:return+ if _cascade:+ # We need to deactivate bots before the target user, to ensure+ # that a failure partway through this function cannot result+ # in only the user being deactivated.+ bot_profiles = UserProfile.objects.filter(+ is_bot=True, is_active=True, bot_owner=user_profile+ )+ for profile in bot_profiles:+ do_deactivate_user(profile, _cascade=False, acting_user=acting_user)+with transaction.atomic():if user_profile.realm.is_zephyr_mirror_realm: # nocoverage# For zephyr mirror users, we need to make them a mirror dummy@@ -1200,13 +1210,6 @@ def do_deactivate_user()send_event(user_profile.realm, event, bot_owner_user_ids(user_profile))- if _cascade:- bot_profiles = UserProfile.objects.filter(- is_bot=True, is_active=True, bot_owner=user_profile- )- for profile in bot_profiles:- do_deactivate_user(profile, _cascade=False, acting_user=acting_user)-def do_deactivate_stream(stream: Stream, log: bool = True, acting_user: Optional[UserProfile] = None