VC/Zoom: code style improvements (review)

Co-authored-by: Adrian Moennich <adrian.moennich@cern.ch>
This commit is contained in:
Pedro Ferreira 2020-11-18 14:53:46 +01:00
parent e56fed04bc
commit f22d545dbc
5 changed files with 17 additions and 28 deletions

View File

@ -28,10 +28,7 @@ def _handle_response(resp, expected_code=200, expects_json=True):
resp.raise_for_status()
if resp.status_code != expected_code:
raise HTTPError("Unexpected status code {}".format(resp.status_code), response=resp)
if expects_json:
return resp.json()
else:
return resp
return resp.json() if expects_json else resp
class APIException(Exception):
@ -150,6 +147,8 @@ class UserComponent(BaseComponent):
class ZoomClient(object):
"""Zoom REST API Python Client."""
BASE_URI = "https://api.zoom.us/v2"
_components = {
'user': UserComponent,
'meeting': MeetingComponent,
@ -163,8 +162,6 @@ class ZoomClient(object):
:param api_secret: the Zoom JWT API Secret
:param timeout: the time out to use for API requests
"""
BASE_URI = "https://api.zoom.us/v2"
# Setup the config details
config = {
"api_key": api_key,
@ -172,38 +169,33 @@ class ZoomClient(object):
}
# Instantiate the components
self.components = {
key: component(base_uri=BASE_URI, config=config, timeout=timeout)
key: component(base_uri=self.BASE_URI, config=config, timeout=timeout)
for key, component in self._components.viewitems()
}
@property
def meeting(self):
"""Get the meeting component."""
return self.components.get("meeting")
return self.components['meeting']
@property
def user(self):
"""Get the user component."""
return self.components.get("user")
return self.components['user']
@property
def webinar(self):
"""Get the user component."""
return self.components.get("webinar")
"""Get the webinar component."""
return self.components['webinar']
class ZoomIndicoClient(object):
def __init__(self):
self._refresh_client()
def _refresh_client(self):
from indico_vc_zoom.plugin import ZoomPlugin
settings = ZoomPlugin.settings
self.client = ZoomClient(
settings.get('api_key'),
settings.get('api_secret')
ZoomPlugin.settings.get('api_key'),
ZoomPlugin.settings.get('api_secret')
)
def create_meeting(self, user_id, **kwargs):
@ -230,9 +222,6 @@ class ZoomIndicoClient(object):
def delete_webinar(self, webinar_id):
return _handle_response(self.client.webinar.delete(webinar_id), 204, expects_json=False)
def check_user_meeting_time(self, user_id, start_dt, end_dt):
pass
def get_user(self, user_id):
return _handle_response(self.client.user.get(user_id))

View File

@ -5,7 +5,7 @@
# them and/or modify them under the terms of the MIT License;
# see the LICENSE file for more details.
from __future__ import unicode_literals
from __future__ import print_function, unicode_literals
import click
from terminaltables import AsciiTable
@ -36,4 +36,4 @@ def rooms(status=None):
table = AsciiTable(table_data)
for col in (0, 3, 4):
table.justify_columns[col] = 'right'
print table.table
print(table.table)

View File

@ -9,7 +9,7 @@ from __future__ import unicode_literals
from flask import session
from wtforms.fields.core import BooleanField, StringField
from wtforms.fields.simple import HiddenField, TextAreaField
from wtforms.fields.simple import TextAreaField
from wtforms.validators import DataRequired, ValidationError
from indico.modules.vc.forms import VCRoomAttachFormBase, VCRoomFormBase

View File

@ -26,7 +26,7 @@ def notify_host_start_url(vc_room):
)
email = make_email(to_list, template=template_module, html=True)
send_email(email, None, 'Zoom')
send_email(email)
def notify_new_host(actor, vc_room):
@ -41,4 +41,4 @@ def notify_new_host(actor, vc_room):
new_host = principal_from_identifier(vc_room.data['host'])
email = make_email({new_host.email}, cc_list={actor.email}, template=template_module, html=True)
send_email(email, None, 'Zoom')
send_email(email)

View File

@ -29,12 +29,12 @@ def find_enterprise_email(user):
:return: the e-mail address if it exists, otherwise `None`
"""
from indico_vc_zoom.plugin import ZoomPlugin
providers = [auth.strip() for auth in ZoomPlugin.settings.get('email_domains').split(',')]
domains = [auth.strip() for auth in ZoomPlugin.settings.get('email_domains').split(',')]
result = UserEmail.query.filter(
UserEmail.user == user,
~User.is_blocked,
~User.is_deleted,
db.or_(UserEmail.email.ilike("%%@{}".format(provider)) for provider in providers)
db.or_(UserEmail.email.ilike('%@{}'.format(domain)) for domain in domains)
).join(User).first()
return result.email if result else None