From 90cae59ea6c6ea666cda79b63aba813e3742c66c Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 14 Apr 2022 14:29:39 -0700 Subject: [PATCH] actions: Split out zerver.actions.video_calls. Signed-off-by: Anders Kaseorg --- zerver/actions/video_calls.py | 14 ++++++++++++++ zerver/lib/actions.py | 10 ---------- zerver/signals.py | 2 +- zerver/tests/test_events.py | 2 +- zerver/views/video_calls.py | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 zerver/actions/video_calls.py diff --git a/zerver/actions/video_calls.py b/zerver/actions/video_calls.py new file mode 100644 index 0000000000..f007598509 --- /dev/null +++ b/zerver/actions/video_calls.py @@ -0,0 +1,14 @@ +from typing import Dict, Optional + +from zerver.models import UserProfile +from zerver.tornado.django_api import send_event + + +def do_set_zoom_token(user: UserProfile, token: Optional[Dict[str, object]]) -> None: + user.zoom_token = token + user.save(update_fields=["zoom_token"]) + send_event( + user.realm, + dict(type="has_zoom_token", value=token is not None), + [user.id], + ) diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index e9627da5cc..efa66efc47 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -8742,16 +8742,6 @@ def do_send_realm_reactivation_email(realm: Realm, *, acting_user: Optional[User ) -def do_set_zoom_token(user: UserProfile, token: Optional[Dict[str, object]]) -> None: - user.zoom_token = token - user.save(update_fields=["zoom_token"]) - send_event( - user.realm, - dict(type="has_zoom_token", value=token is not None), - [user.id], - ) - - def notify_realm_export(user_profile: UserProfile) -> None: # In the future, we may want to send this event to all realm admins. event = dict(type="realm_export", exports=get_realm_exports_serialized(user_profile)) diff --git a/zerver/signals.py b/zerver/signals.py index f0835d12fc..c7e96b3a6f 100644 --- a/zerver/signals.py +++ b/zerver/signals.py @@ -107,7 +107,7 @@ def clear_zoom_token_on_logout( sender: object, *, user: Optional[UserProfile], **kwargs: object ) -> None: # Loaded lazily so django.setup() succeeds before static asset generation - from zerver.lib.actions import do_set_zoom_token + from zerver.actions.video_calls import do_set_zoom_token if user is not None and user.zoom_token is not None: do_set_zoom_token(user, None) diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py index 99785861c9..b169315b7b 100644 --- a/zerver/tests/test_events.py +++ b/zerver/tests/test_events.py @@ -13,6 +13,7 @@ from unittest import mock import orjson from django.utils.timezone import now as timezone_now +from zerver.actions.video_calls import do_set_zoom_token from zerver.lib.actions import ( bulk_add_members_to_user_group, bulk_add_subscriptions, @@ -83,7 +84,6 @@ from zerver.lib.actions import ( do_set_realm_property, do_set_realm_signup_notifications_stream, do_set_realm_user_default_setting, - do_set_zoom_token, do_unmute_topic, do_unmute_user, do_update_embedded_data, diff --git a/zerver/views/video_calls.py b/zerver/views/video_calls.py index 40b35423db..c831edf21e 100644 --- a/zerver/views/video_calls.py +++ b/zerver/views/video_calls.py @@ -22,8 +22,8 @@ from django.views.decorators.http import require_POST from oauthlib.oauth2 import OAuth2Error from requests_oauthlib import OAuth2Session +from zerver.actions.video_calls import do_set_zoom_token from zerver.decorator import zulip_login_required -from zerver.lib.actions import do_set_zoom_token from zerver.lib.exceptions import ErrorCode, JsonableError from zerver.lib.outgoing_http import OutgoingSession from zerver.lib.pysa import mark_sanitized