video_calls: Update do_set_zoom_token to send event on commit.

Earlier, we were using 'send_event' in 'do_set_zoom_token' which
can lead to a situation, if any db operation is added after the
'send_event' in future, where we enqueue events but the action
function fails at a later stage.

Events should not be sent until we know we're not rolling back.

Fixes part of #30489.
This commit is contained in:
Prakhar Pratyush 2024-08-09 12:46:18 +05:30 committed by Tim Abbott
parent 0fddda232d
commit 69a2775e9b
1 changed files with 5 additions and 2 deletions

View File

@ -1,11 +1,14 @@
from django.db import transaction
from zerver.models import UserProfile from zerver.models import UserProfile
from zerver.tornado.django_api import send_event from zerver.tornado.django_api import send_event_on_commit
@transaction.atomic(durable=True)
def do_set_zoom_token(user: UserProfile, token: dict[str, object] | None) -> None: def do_set_zoom_token(user: UserProfile, token: dict[str, object] | None) -> None:
user.zoom_token = token user.zoom_token = token
user.save(update_fields=["zoom_token"]) user.save(update_fields=["zoom_token"])
send_event( send_event_on_commit(
user.realm, user.realm,
dict(type="has_zoom_token", value=token is not None), dict(type="has_zoom_token", value=token is not None),
[user.id], [user.id],