From c87ef09d6414535cdc957b37a1bfda3cf418e32c Mon Sep 17 00:00:00 2001 From: Pedro Ferreira Date: Mon, 16 Feb 2015 15:53:07 +0100 Subject: [PATCH] VC/Vidyo: Add room name & PIN validation, automute default --- vc_vidyo/indico_vc_vidyo/forms.py | 26 +++++++++++++++++++------- vc_vidyo/indico_vc_vidyo/plugin.py | 29 +++++++++++++++++++---------- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/vc_vidyo/indico_vc_vidyo/forms.py b/vc_vidyo/indico_vc_vidyo/forms.py index dd8adf0..d40b808 100644 --- a/vc_vidyo/indico_vc_vidyo/forms.py +++ b/vc_vidyo/indico_vc_vidyo/forms.py @@ -20,16 +20,20 @@ import re from wtforms.fields.core import BooleanField from wtforms.fields.simple import StringField, TextAreaField -from wtforms.validators import DataRequired, Length, Regexp +from wtforms.validators import DataRequired, Length, Regexp, Optional, ValidationError -from indico.web.forms.base import IndicoForm +from indico.modules.vc.models import VCRoom +from indico.modules.vc.plugins import VCRoomFormBase from indico.util.i18n import _ from indico.web.forms.fields import PrincipalField, IndicoPasswordField ROOM_NAME_RE = re.compile(r'[\w\-]+') +PIN_RE = re.compile(r'^\d+$') + +ERROR_MSG_PIN = _("The PIN must be a number") -class VCRoomForm(IndicoForm): +class VCRoomForm(VCRoomFormBase): name = StringField(_('Name'), [DataRequired(), Length(min=3, max=60), Regexp(ROOM_NAME_RE)], description=_('The name of the room')) description = TextAreaField(_('Description'), [DataRequired()], description=_('The description of the room')) @@ -37,7 +41,15 @@ class VCRoomForm(IndicoForm): auto_mute = BooleanField(_('Auto mute'), description=_('The VidyoDesktop clients will join the meeting muted by default ' '(audio and video)')) - moderator_pin = IndicoPasswordField(_('Moderator PIN'), toggle=True, description=_('Used to moderate the VC Room')) - room_pin = IndicoPasswordField(_('Room PIN'), toggle=True, - description=_('Used to protect the access to the VC Room ' - '(leave blank for open access)')) + moderator_pin = IndicoPasswordField( + _('Moderator PIN'), + [Optional(), Length(min=3, max=10), Regexp(PIN_RE)], + toggle=True, description=_('Used to moderate the VC Room')) + room_pin = IndicoPasswordField( + _('Room PIN'), + [Optional(), Length(min=3, max=10), Regexp(PIN_RE, message=ERROR_MSG_PIN)], + toggle=True, description=_('Used to protect the access to the VC Room (leave blank for open access)')) + + def validate_name(self, field): + if field.data and VCRoom.find_first(name=field.data): + raise ValidationError(_("There is already a room with this name")) diff --git a/vc_vidyo/indico_vc_vidyo/plugin.py b/vc_vidyo/indico_vc_vidyo/plugin.py index f258ca7..4b650cd 100644 --- a/vc_vidyo/indico_vc_vidyo/plugin.py +++ b/vc_vidyo/indico_vc_vidyo/plugin.py @@ -15,17 +15,18 @@ # along with Indico; if not, see . from __future__ import unicode_literals +import re from wtforms.fields import IntegerField, TextAreaField from wtforms.fields.html5 import URLField, EmailField from wtforms.fields.simple import StringField -from wtforms.validators import NumberRange +from wtforms.validators import NumberRange, DataRequired from indico.core.config import Config from indico.core.plugins import IndicoPlugin, url_for_plugin, IndicoPluginBlueprint from indico.modules.vc import VCPluginSettingsFormBase, VCPluginMixin from indico.util.i18n import _ -from indico.web.forms.fields import EmailListField, UnsafePasswordField +from indico.web.forms.fields import EmailListField, IndicoPasswordField from indico.web.forms.widgets import CKEditorWidget from indico_vc_vidyo.forms import VCRoomForm @@ -36,20 +37,21 @@ class PluginSettingsForm(VCPluginSettingsFormBase): _('Notification emails'), description=_('Additional email addresses who will always receive notifications (one per line)') ) - username = StringField(_('Username'), description=_('Indico username for Vidyo')) - password = UnsafePasswordField(_('Password'), description=_('Indico password for Vidyo')) - admin_api_wsdl = URLField(_('Admin API WSDL URL')) - user_api_wsdl = URLField(_('User API WSDL URL')) + username = StringField(_('Username'), [DataRequired()], description=_('Indico username for Vidyo')) + password = IndicoPasswordField(_('Password'), [DataRequired()], toggle=True, + description=_('Indico password for Vidyo')) + admin_api_wsdl = URLField(_('Admin API WSDL URL'), [DataRequired()]) + user_api_wsdl = URLField(_('User API WSDL URL'), [DataRequired()]) indico_room_prefix = IntegerField(_('Indico rooms prefix'), [NumberRange(min=0)], description=_('The prefix for Indico rooms')) - room_group_name = StringField(_("Public rooms' group name"), + room_group_name = StringField(_("Public rooms' group name"), [DataRequired()], description=_('Group name for public video conference rooms created by Indico')) - authenticators = StringField(_('Authenticators'), + authenticators = StringField(_('Authenticators'), [DataRequired()], description=_('Authenticators to convert Indico users to Vidyo accounts')) - num_days_old = IntegerField(_('VC room age threshold'), [NumberRange(min=1)], + num_days_old = IntegerField(_('VC room age threshold'), [NumberRange(min=1), DataRequired()], description=_('Number of days after an Indico event when a video conference room is ' 'considered old')) - max_rooms_warning = IntegerField(_('Max. num. VC rooms before warning'), [NumberRange(min=1)], + max_rooms_warning = IntegerField(_('Max. num. VC rooms before warning'), [NumberRange(min=1), DataRequired()], description=_('Maximum number of rooms until a warning is sent to the managers')) vidyo_phone_link = URLField(_('VidyoVoice phone number'), description=_('Link to the list of VidyoVoice phone numbers')) @@ -86,6 +88,13 @@ class VidyoPlugin(VCPluginMixin, IndicoPlugin): } vc_room_form = VCRoomForm + def get_vc_room_form_defaults(self, event): + return { + # replace invalid chars with underscore + 'name': re.sub(r'[^\w_-]', '_', event.getTitle()), + 'auto_mute': True + } + @property def logo_url(self): return url_for_plugin(self.name + '.static', filename='images/logo.png')