VC/Zoom: Use single quotes

This commit is contained in:
Adrian Moennich 2020-12-01 15:04:19 +01:00
parent 601245159f
commit a0bca2e207
4 changed files with 58 additions and 58 deletions

View File

@ -21,14 +21,14 @@ def format_iso_dt(d):
:param d: The :class:`datetime.datetime` to convert to a string
:returns: The string representation of the date
"""
return d.astimezone(utc).strftime("%Y-%m-%dT%H:%M:%SZ")
return d.astimezone(utc).strftime('%Y-%m-%dT%H:%M:%SZ')
def _handle_response(resp, expected_code=200, expects_json=True):
try:
resp.raise_for_status()
if resp.status_code != expected_code:
raise HTTPError("Unexpected status code {}".format(resp.status_code), response=resp)
raise HTTPError('Unexpected status code {}'.format(resp.status_code), response=resp)
except HTTPError:
from indico_vc_zoom.plugin import ZoomPlugin
ZoomPlugin.logger.error('Error in API call to %s : %s', resp.url, resp.content)
@ -48,10 +48,10 @@ class BaseComponent(object):
@property
def token(self):
header = {"alg": "HS256", "typ": "JWT"}
payload = {"iss": self.config['api_key'], "exp": int(time.time() + 3600)}
token = jwt.encode(payload, self.config['api_secret'], algorithm="HS256", headers=header)
return token.decode("utf-8")
header = {'alg': 'HS256', 'typ': 'JWT'}
payload = {'iss': self.config['api_key'], 'exp': int(time.time() + 3600)}
token = jwt.encode(payload, self.config['api_secret'], algorithm='HS256', headers=header)
return token.decode('utf-8')
@property
def session(self):
@ -66,60 +66,60 @@ class BaseComponent(object):
class MeetingComponent(BaseComponent):
def list(self, user_id, **kwargs):
return self.get(
"{}/users/{}/meetings".format(self.base_uri, user_id), params=kwargs
'{}/users/{}/meetings'.format(self.base_uri, user_id), params=kwargs
)
def create(self, user_id, **kwargs):
if kwargs.get("start_time"):
kwargs["start_time"] = format_iso_dt(kwargs["start_time"])
if kwargs.get('start_time'):
kwargs['start_time'] = format_iso_dt(kwargs['start_time'])
return self.session.post(
"{}/users/{}/meetings".format(self.base_uri, user_id),
'{}/users/{}/meetings'.format(self.base_uri, user_id),
json=kwargs
)
def get(self, meeting_id, **kwargs):
return self.session.get("{}/meetings/{}".format(self.base_uri, meeting_id), json=kwargs)
return self.session.get('{}/meetings/{}'.format(self.base_uri, meeting_id), json=kwargs)
def update(self, meeting_id, **kwargs):
if kwargs.get("start_time"):
kwargs["start_time"] = format_iso_dt(kwargs["start_time"])
if kwargs.get('start_time'):
kwargs['start_time'] = format_iso_dt(kwargs['start_time'])
return self.session.patch(
"{}/meetings/{}".format(self.base_uri, meeting_id), json=kwargs
'{}/meetings/{}'.format(self.base_uri, meeting_id), json=kwargs
)
def delete(self, meeting_id, **kwargs):
return self.session.delete(
"{}/meetings/{}".format(self.base_uri, meeting_id), json=kwargs
'{}/meetings/{}'.format(self.base_uri, meeting_id), json=kwargs
)
class WebinarComponent(BaseComponent):
def list(self, user_id, **kwargs):
return self.get(
"{}/users/{}/webinars".format(self.base_uri, user_id), params=kwargs
'{}/users/{}/webinars'.format(self.base_uri, user_id), params=kwargs
)
def create(self, user_id, **kwargs):
if kwargs.get("start_time"):
kwargs["start_time"] = format_iso_dt(kwargs["start_time"])
if kwargs.get('start_time'):
kwargs['start_time'] = format_iso_dt(kwargs['start_time'])
return self.session.post(
"{}/users/{}/webinars".format(self.base_uri, user_id),
'{}/users/{}/webinars'.format(self.base_uri, user_id),
json=kwargs
)
def get(self, meeting_id, **kwargs):
return self.session.get("{}/webinars/{}".format(self.base_uri, meeting_id), json=kwargs)
return self.session.get('{}/webinars/{}'.format(self.base_uri, meeting_id), json=kwargs)
def update(self, meeting_id, **kwargs):
if kwargs.get("start_time"):
kwargs["start_time"] = format_iso_dt(kwargs["start_time"])
if kwargs.get('start_time'):
kwargs['start_time'] = format_iso_dt(kwargs['start_time'])
return self.session.patch(
"{}/webinars/{}".format(self.base_uri, meeting_id), json=kwargs
'{}/webinars/{}'.format(self.base_uri, meeting_id), json=kwargs
)
def delete(self, meeting_id, **kwargs):
return self.session.delete(
"{}/webinars/{}".format(self.base_uri, meeting_id), json=kwargs
'{}/webinars/{}'.format(self.base_uri, meeting_id), json=kwargs
)
@ -128,31 +128,31 @@ class UserComponent(BaseComponent):
return self.get('me')
def list(self, **kwargs):
return self.session.get("{}/users".format(self.base_uri), params=kwargs)
return self.session.get('{}/users'.format(self.base_uri), params=kwargs)
def create(self, **kwargs):
return self.session.post("{}/users".format(self.base_uri), params=kwargs)
return self.session.post('{}/users'.format(self.base_uri), params=kwargs)
def update(self, user_id, **kwargs):
return self.session.patch("{}/users/{}".format(self.base_uri, user_id), params=kwargs)
return self.session.patch('{}/users/{}'.format(self.base_uri, user_id), params=kwargs)
def delete(self, user_id, **kwargs):
return self.session.delete("{}/users/{}".format(self.base_uri, user_id), params=kwargs)
return self.session.delete('{}/users/{}'.format(self.base_uri, user_id), params=kwargs)
def add_assistant(self, user_id, **kwargs):
return self.session.post("{}/users/{}/assistants".format(self.base_uri, user_id), json=kwargs)
return self.session.post('{}/users/{}/assistants'.format(self.base_uri, user_id), json=kwargs)
def get_assistants(self, user_id, **kwargs):
return self.session.get("{}/users/{}/assistants".format(self.base_uri, user_id), params=kwargs)
return self.session.get('{}/users/{}/assistants'.format(self.base_uri, user_id), params=kwargs)
def get(self, user_id, **kwargs):
return self.session.get("{}/users/{}".format(self.base_uri, user_id), params=kwargs)
return self.session.get('{}/users/{}'.format(self.base_uri, user_id), params=kwargs)
class ZoomClient(object):
"""Zoom REST API Python Client."""
BASE_URI = "https://api.zoom.us/v2"
BASE_URI = 'https://api.zoom.us/v2'
_components = {
'user': UserComponent,
@ -169,8 +169,8 @@ class ZoomClient(object):
"""
# Setup the config details
config = {
"api_key": api_key,
"api_secret": api_secret
'api_key': api_key,
'api_secret': api_secret
}
# Instantiate the components

View File

@ -27,13 +27,13 @@ from indico_vc_zoom.util import find_enterprise_email
class VCRoomAttachForm(VCRoomAttachFormBase):
password_visibility = IndicoRadioField(_("Passcode visibility"),
password_visibility = IndicoRadioField(_('Passcode visibility'),
description=_("Who should be able to know this meeting's passcode"),
orientation='horizontal',
choices=[
('everyone', _('Everyone')),
('logged_in', _('Logged-in users')),
('no_one', _("No one"))])
('no_one', _('No one'))])
class VCRoomForm(VCRoomFormBase):
@ -43,30 +43,30 @@ class VCRoomForm(VCRoomFormBase):
skip_fields = advanced_fields | VCRoomFormBase.conditional_fields
meeting_type = IndicoRadioField(_("Meeting Type"),
description=_("The type of Zoom meeting to be created"),
meeting_type = IndicoRadioField(_('Meeting Type'),
description=_('The type of Zoom meeting to be created'),
orientation='horizontal',
choices=[
('regular', _('Regular Meeting')),
('webinar', _('Webinar'))])
host_choice = IndicoRadioField(_("Meeting Host"), [DataRequired()],
choices=[('myself', _("Myself")), ('someone_else', _("Someone else"))])
host_choice = IndicoRadioField(_('Meeting Host'), [DataRequired()],
choices=[('myself', _('Myself')), ('someone_else', _('Someone else'))])
host_user = PrincipalField(_("User"),
host_user = PrincipalField(_('User'),
[HiddenUnless('host_choice', 'someone_else'), DataRequired()])
password = StringField(_("Passcode"),
password = StringField(_('Passcode'),
[DataRequired(), IndicoRegexp(r'^\d{8,}$')],
description=_("Meeting passcode (min. 8 digits)"))
description=_('Meeting passcode (min. 8 digits)'))
password_visibility = IndicoRadioField(_("Passcode visibility"),
password_visibility = IndicoRadioField(_('Passcode visibility'),
description=_("Who should be able to know this meeting's passcode"),
orientation='horizontal',
choices=[
('everyone', _('Everyone')),
('logged_in', _('Logged-in users')),
('no_one', _("No one"))])
('no_one', _('No one'))])
mute_audio = BooleanField(_('Mute audio'),
widget=SwitchWidget(),

View File

@ -54,7 +54,7 @@ class PluginSettingsForm(VCPluginSettingsFormBase):
description=_("Specify Zoom's webhook token if you want live updates"))
email_domains = StringField(_('E-mail domains'), [DataRequired()],
description=_("Comma-separated list of e-mail domains which can use the Zoom API."))
description=_('Comma-separated list of e-mail domains which can use the Zoom API.'))
assistant_id = StringField(_('Assistant Zoom ID'), [DataRequired()],
description=_('Account to be used as owner of all rooms. It will get "assistant" '
@ -232,8 +232,8 @@ class ZoomPlugin(VCPluginMixin, IndicoPlugin):
client.add_assistant_to_user(user_id, assistant_id)
except HTTPError as e:
if e.response.status_code == 404:
raise NotFound(_("No Zoom account found for this user"))
raise VCRoomError(_("Problem setting Zoom account assistants"))
raise NotFound(_('No Zoom account found for this user'))
raise VCRoomError(_('Problem setting Zoom account assistants'))
def create_room(self, vc_room, event):
"""Create a new Zoom room for an event, given a VC room.
@ -298,7 +298,7 @@ class ZoomPlugin(VCPluginMixin, IndicoPlugin):
meeting_obj = client.create_meeting(self.settings.get('assistant_id'), **kwargs)
except HTTPError as e:
self.logger.exception('Error creating Zoom Room: %s', e.response.content)
raise VCRoomError(_("Could not create the room in Zoom. Please contact support if the error persists"))
raise VCRoomError(_('Could not create the room in Zoom. Please contact support if the error persists'))
vc_room.data.update({
'zoom_id': unicode(meeting_obj['id']),
@ -401,7 +401,7 @@ class ZoomPlugin(VCPluginMixin, IndicoPlugin):
flash(_("Room didn't existing in Zoom anymore"), 'warning')
else:
self.logger.error("Can't delete room")
raise VCRoomError(_("Problem deleting room"))
raise VCRoomError(_('Problem deleting room'))
def get_blueprints(self):
return blueprint
@ -457,14 +457,14 @@ class ZoomPlugin(VCPluginMixin, IndicoPlugin):
if any(assoc.vc_room.type == 'zoom' and len(assoc.vc_room.events) == 1 for assoc in obj.vc_room_associations):
if sender == Event:
message = _("There are one or more scheduled Zoom meetings associated with this event which were not "
"automatically updated.")
message = _('There are one or more scheduled Zoom meetings associated with this event which were not '
'automatically updated.')
elif sender == Contribution:
message = _("There are one or more scheduled Zoom meetings associated with contribution '{}' which "
" were not automatically updated.").format(obj.title)
message = _('There are one or more scheduled Zoom meetings associated with the contribution "{}" which '
' were not automatically updated.').format(obj.title)
elif sender == SessionBlock:
message = _("There are one or more scheduled Zoom meetings associated with this session block which "
"were not automatically updated.")
message = _('There are one or more scheduled Zoom meetings associated with this session block which '
'were not automatically updated.')
else:
return

View File

@ -71,11 +71,11 @@ def fetch_zoom_meeting(vc_room, client=None, is_webinar=False):
except HTTPError as e:
if e.response.status_code in {400, 404}:
# Indico will automatically mark this room as deleted
raise VCRoomNotFoundError(_("This room has been deleted from Zoom"))
raise VCRoomNotFoundError(_('This room has been deleted from Zoom'))
else:
from indico_vc_zoom.plugin import ZoomPlugin
ZoomPlugin.logger.exception('Error getting Zoom Room: %s', e.response.content)
raise VCRoomError(_("Problem fetching room from Zoom. Please contact support if the error persists."))
raise VCRoomError(_('Problem fetching room from Zoom. Please contact support if the error persists.'))
def update_zoom_meeting(zoom_id, changes, is_webinar=False):