From ec5e05afebae0be75570949a4586e15ee17acca3 Mon Sep 17 00:00:00 2001 From: Pedro Ferreira Date: Wed, 20 Jan 2021 11:43:39 +0100 Subject: [PATCH] VC/Zoom: Do not clone deleted meetings/VCRooms --- vc_zoom/README.md | 1 + vc_zoom/indico_vc_zoom/plugin.py | 39 ++++++++++++++++++++------------ vc_zoom/indico_vc_zoom/util.py | 5 ++++ 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/vc_zoom/README.md b/vc_zoom/README.md index f819585..263cf87 100644 --- a/vc_zoom/README.md +++ b/vc_zoom/README.md @@ -28,6 +28,7 @@ - Remove the "Assistant Zoom ID" logic due to problems with Zoom's API rate limits (all meetings created were counted against the assistant's rate limit instead of the host's); this means the host can no longer be changed, but Indico instead provides an option to event managers to make themselves a co-host. - Fix an error when changing the linked object of a recurring Zoom room in Indico - Include Zoom join links in the event's ical export (note: only Zoom meetings with a public passcode are displayed unless you have at least Indico v2.3.3) +- Skip deleted Zoom meetings when cloning events **Breaking change:** The email domains are now stored as a list of strings instead of a comma-separated list. You need to update them in the plugin settings. diff --git a/vc_zoom/indico_vc_zoom/plugin.py b/vc_zoom/indico_vc_zoom/plugin.py index 764bbdc..227ef6c 100644 --- a/vc_zoom/indico_vc_zoom/plugin.py +++ b/vc_zoom/indico_vc_zoom/plugin.py @@ -21,8 +21,8 @@ from indico.core.auth import multipass from indico.core.plugins import IndicoPlugin, render_plugin_template, url_for_plugin from indico.modules.events.views import WPSimpleEventDisplay from indico.modules.vc import VCPluginMixin, VCPluginSettingsFormBase -from indico.modules.vc.exceptions import VCRoomError -from indico.modules.vc.models.vc_rooms import VCRoom +from indico.modules.vc.exceptions import VCRoomError, VCRoomNotFoundError +from indico.modules.vc.models.vc_rooms import VCRoom, VCRoomStatus from indico.modules.vc.views import WPVCEventPage, WPVCManageEvent from indico.util.user import principal_from_identifier from indico.web.forms.fields import IndicoEnumSelectField, IndicoPasswordField, TextListField @@ -424,20 +424,31 @@ class ZoomPlugin(VCPluginMixin, IndicoPlugin): vc_room = old_event_vc_room.vc_room is_webinar = vc_room.data.get('meeting_type', 'regular') == 'webinar' has_only_one_association = len({assoc.event_id for assoc in vc_room.events}) == 1 - new_assoc = super(ZoomPlugin, self).clone_room(old_event_vc_room, link_object) if has_only_one_association: - update_zoom_meeting(vc_room.data['zoom_id'], { - 'start_time': None, - 'duration': None, - 'type': ( - ZoomMeetingType.recurring_webinar_no_time - if is_webinar - else ZoomMeetingType.recurring_meeting_no_time - ) - }) - - return new_assoc + try: + update_zoom_meeting(vc_room.data['zoom_id'], { + 'start_time': None, + 'duration': None, + 'type': ( + ZoomMeetingType.recurring_webinar_no_time + if is_webinar + else ZoomMeetingType.recurring_meeting_no_time + ) + }) + except VCRoomNotFoundError: + # this check is needed in order to avoid multiple flashes + if vc_room.status != VCRoomStatus.deleted: + # mark room as deleted + vc_room.status = VCRoomStatus.deleted + flash( + _('The room "{}" no longer exists in Zoom and was removed from the event').format(vc_room.name), + 'warning' + ) + # no need to create an association to a room marked as deleted + return None + # return the new association + return super(ZoomPlugin, self).clone_room(old_event_vc_room, link_object) def get_blueprints(self): return blueprint diff --git a/vc_zoom/indico_vc_zoom/util.py b/vc_zoom/indico_vc_zoom/util.py index 40b923a..e9db6a1 100644 --- a/vc_zoom/indico_vc_zoom/util.py +++ b/vc_zoom/indico_vc_zoom/util.py @@ -147,6 +147,11 @@ def update_zoom_meeting(zoom_id, changes, is_webinar=False): except HTTPError as e: from indico_vc_zoom.plugin import ZoomPlugin ZoomPlugin.logger.exception("Error updating meeting '%s': %s", zoom_id, e.response.content) + + if e.response.json()['code'] == 3001: + # "Meeting does not exist" + raise VCRoomNotFoundError(_("Room no longer exists in Zoom")) + raise VCRoomError(_("Can't update meeting. Please contact support if the error persists."))