do_deactivate_user: Use .on_commit around send_event calls.

The previous commit did this for revoking sessions. send_events should
be handled similarly too, to correctly handle calling do_deactivate_user
inside a transaction.
This commit is contained in:
Mateusz Mandera
2022-10-10 20:43:15 +02:00
committed by Tim Abbott
parent a94b2572be
commit 470c0458e6

View File

@@ -165,20 +165,28 @@ def do_deactivate_user(
transaction.on_commit(lambda: delete_user_sessions(user_profile))
event = dict(
type="realm_user",
op="remove",
person=dict(user_id=user_profile.id, full_name=user_profile.full_name),
)
send_event(user_profile.realm, event, active_user_ids(user_profile.realm_id))
if user_profile.is_bot:
event = dict(
type="realm_bot",
event_remove_user = dict(
type="realm_user",
op="remove",
bot=dict(user_id=user_profile.id, full_name=user_profile.full_name),
person=dict(user_id=user_profile.id, full_name=user_profile.full_name),
)
send_event(user_profile.realm, event, bot_owner_user_ids(user_profile))
transaction.on_commit(
lambda: send_event(
user_profile.realm, event_remove_user, active_user_ids(user_profile.realm_id)
)
)
if user_profile.is_bot:
event_remove_bot = dict(
type="realm_bot",
op="remove",
bot=dict(user_id=user_profile.id, full_name=user_profile.full_name),
)
transaction.on_commit(
lambda: send_event(
user_profile.realm, event_remove_bot, bot_owner_user_ids(user_profile)
)
)
@transaction.atomic(durable=True)