def _process(self): if not self.plugin.can_manage_vc_rooms(session.user, self.event): flash( _('You are not allowed to create {plugin_name} rooms for this event.' ).format(plugin_name=self.plugin.friendly_name), 'error') raise Forbidden form = self.plugin.create_form(event=self.event) if form.validate_on_submit(): vc_room = VCRoom(created_by_user=session.user) vc_room.type = self.plugin.service_name vc_room.status = VCRoomStatus.created event_vc_room = process_vc_room_association( self.plugin, self.event, vc_room, form) if not event_vc_room: return jsonify_data(flash=False) with db.session.no_autoflush: self.plugin.update_data_vc_room(vc_room, form.data, is_new=True) try: # avoid flushing the incomplete vc room to the database with db.session.no_autoflush: self.plugin.create_room(vc_room, self.event) notify_created(self.plugin, vc_room, event_vc_room, self.event, session.user) except VCRoomError as err: if err.field is None: raise field = getattr(form, err.field) field.errors.append(str(err)) db.session.rollback( ) # otherwise the incomplete vc room would be added to the db! else: db.session.add(vc_room) flash( _("{plugin_name} room '{room.name}' created").format( plugin_name=self.plugin.friendly_name, room=vc_room), 'success') return jsonify_data(flash=False) form_html = self.plugin.render_form(plugin=self.plugin, event=self.event, form=form, skip_fields=form.skip_fields | {'name'}) return jsonify(html=form_html, js=_pop_injected_js())
def _process(self): if not self.plugin.can_manage_vc_rooms(session.user, self.event_new): flash( _('You are not allowed to create {plugin_name} rooms for this event.' ).format(plugin_name=self.plugin.friendly_name), 'error') return redirect(url_for('.manage_vc_rooms', self.event_new)) form = self.plugin.create_form(event=self.event_new) if form.validate_on_submit(): vc_room = VCRoom(created_by_user=session.user) vc_room.type = self.plugin.service_name vc_room.status = VCRoomStatus.created event_vc_room = process_vc_room_association( self.plugin, self.event_new, vc_room, form) if not event_vc_room: return redirect(url_for('.manage_vc_rooms', self.event_new)) with db.session.no_autoflush: self.plugin.update_data_vc_room(vc_room, form.data) try: # avoid flushing the incomplete vc room to the database with db.session.no_autoflush: self.plugin.create_room(vc_room, self.event_new) notify_created(self.plugin, vc_room, event_vc_room, self.event_new, session.user) except VCRoomError as err: if err.field is None: raise field = getattr(form, err.field) field.errors.append(err.message) transaction.abort( ) # otherwise the incomplete vc room would be added to the db! else: db.session.add(vc_room) # TODO: notify_created(vc_room, self.event_new, session.user) flash( _("{plugin_name} room '{room.name}' created").format( plugin_name=self.plugin.friendly_name, room=vc_room), 'success') return redirect(url_for('.manage_vc_rooms', self.event_new)) form_html = self.plugin.render_form(plugin=self.plugin, event=self.event_new, form=form, skip_fields=form.skip_fields | {'name'}) return WPVCManageEvent.render_string(form_html, self.event)
def _process(self): if not self.plugin.can_manage_vc_rooms(session.user, self.event_new): flash( _("You are not allowed to create {plugin_name} rooms for this event.").format( plugin_name=self.plugin.friendly_name ), "error", ) return redirect(url_for(".manage_vc_rooms", self.event_new)) form = self.plugin.create_form(event=self.event_new) if form.validate_on_submit(): vc_room = VCRoom(created_by_user=session.user) vc_room.type = self.plugin.service_name vc_room.status = VCRoomStatus.created event_vc_room = process_vc_room_association(self.plugin, self.event_new, vc_room, form) if not event_vc_room: return redirect(url_for(".manage_vc_rooms", self.event_new)) with db.session.no_autoflush: self.plugin.update_data_vc_room(vc_room, form.data) try: # avoid flushing the incomplete vc room to the database with db.session.no_autoflush: self.plugin.create_room(vc_room, self.event_new) notify_created(self.plugin, vc_room, event_vc_room, self.event_new, session.user) except VCRoomError as err: if err.field is None: raise field = getattr(form, err.field) field.errors.append(err.message) transaction.abort() # otherwise the incomplete vc room would be added to the db! else: db.session.add(vc_room) # TODO: notify_created(vc_room, self.event_new, session.user) flash( _("{plugin_name} room '{room.name}' created").format( plugin_name=self.plugin.friendly_name, room=vc_room ), "success", ) return jsonify_data(flash=False) form_html = self.plugin.render_form( plugin=self.plugin, event=self.event_new, form=form, skip_fields=form.skip_fields | {"name"} ) return jsonify(html=form_html, js=_pop_injected_js())
def migrate_vidyo_room(self, booking): booking_params = booking._bookingParams vc_room = VCRoom(created_by_id=Config.getInstance().getJanitorUserId()) vc_room.type = 'vidyo' vc_room.status = VCRoomStatus.created if booking._created else VCRoomStatus.deleted vc_room.name = booking_params['roomName'] vc_room.data = { 'description': booking_params['roomDescription'], 'room_pin': booking._pin, 'moderation_pin': getattr(booking, '_moderatorPin', ''), 'vidyo_id': booking._roomId, 'url': booking._url, 'owner': ('User', int(booking._owner.id)), 'owner_identity': booking._ownerVidyoAccount, 'auto_mute': booking_params.get('autoMute', True) } vc_room.modified_dt = booking._modificationDate vc_room.created_dt = booking._creationDate db.session.add(vc_room) vidyo_ext = VidyoExtension(vc_room=vc_room, extension=int(booking._extension), owned_by_id=int(booking._owner.id)) db.session.add(vidyo_ext) db.session.flush() self.vc_rooms_by_extension[vidyo_ext.extension] = vc_room print cformat( '%{green}+++%{reset} %{cyan}{}%{reset} [%{yellow!}{}%{reset}]' ).format(vc_room.name, booking._roomId) return vc_room
def _create_room(name, extension, data, **kwargs): vc_room = VCRoom(name=name, data=data, type='vidyo', status=kwargs.pop('status', VCRoomStatus.created), created_by_user=dummy_user, **kwargs) db.session.add(vc_room) db.session.flush() extension = VidyoExtension(vc_room_id=vc_room.id, extension=extension, owned_by_user=dummy_user) vc_room.vidyo_extension = extension return vc_room
def _create_room(name, extension, owner, data, **kwargs): vc_room = VCRoom(name=name, data=data, type="vidyo", status=kwargs.pop('status', VCRoomStatus.created), created_by_id=kwargs.pop('created_by_id', dummy_avatar.id), **kwargs) db.session.add(vc_room) db.session.flush() extension = VidyoExtension(vc_room_id=vc_room.id, extension=extension, owned_by_id=owner.id) vc_room.vidyo_extension = extension return vc_room
def migrate_vidyo_room(self, booking): booking_params = booking._bookingParams vc_room = VCRoom(created_by_id=Config.getInstance().getJanitorUserId()) vc_room.type = 'vidyo' vc_room.status = VCRoomStatus.created if booking._created else VCRoomStatus.deleted vc_room.name = booking_params['roomName'] vc_room.data = { 'description': booking_params['roomDescription'], 'room_pin': booking._pin, 'moderation_pin': getattr(booking, '_moderatorPin', ''), 'vidyo_id': booking._roomId, 'url': booking._url, 'owner': ('User', int(booking._owner.id)), 'owner_identity': booking._ownerVidyoAccount, 'auto_mute': booking_params.get('autoMute', True) } vc_room.modified_dt = booking._modificationDate vc_room.created_dt = booking._creationDate db.session.add(vc_room) vidyo_ext = VidyoExtension(vc_room=vc_room, extension=int(booking._extension), owned_by_id=int(booking._owner.id)) db.session.add(vidyo_ext) db.session.flush() self.vc_rooms_by_extension[vidyo_ext.extension] = vc_room print cformat('%{green}+++%{reset} %{cyan}{}%{reset} [%{yellow!}{}%{reset}]').format( vc_room.name, booking._roomId) return vc_room
def _create_room(name, extension, owner, data, **kwargs): vc_room = VCRoom( name=name, data=data, type="vidyo", status=kwargs.pop('status', VCRoomStatus.created), created_by_id=kwargs.pop('created_by_id', dummy_avatar.id), **kwargs ) db.session.add(vc_room) db.session.flush() extension = VidyoExtension( vc_room_id=vc_room.id, extension=extension, owned_by_id=owner.id ) vc_room.vidyo_extension = extension return vc_room
def _create_room(name, extension, data, **kwargs): vc_room = VCRoom( name=name, data=data, type='vidyo', status=kwargs.pop('status', VCRoomStatus.created), created_by_user=dummy_user, **kwargs ) db.session.add(vc_room) db.session.flush() extension = VidyoExtension( vc_room_id=vc_room.id, extension=extension, owned_by_user=dummy_user ) vc_room.vidyo_extension = extension return vc_room
def _process(self): if not self.plugin.can_manage_vc_rooms(session.avatar, self.event): flash(_('You are not allowed to create {plugin_name} rooms for this event.').format( plugin_name=self.plugin.friendly_name), 'error') return redirect(url_for('.manage_vc_rooms', self.event)) form = self.plugin.create_form(event=self.event) if form.validate_on_submit(): vc_room = VCRoom(created_by_user=session.avatar) vc_room.type = self.plugin.service_name vc_room.status = VCRoomStatus.created event_vc_room = process_vc_room_association(self.plugin, self.event, vc_room, form) if not event_vc_room: return redirect(url_for('.manage_vc_rooms', self.event)) self.plugin.update_data_vc_room(vc_room, form.data) try: self.plugin.create_room(vc_room, self.event) notify_created(self.plugin, vc_room, event_vc_room, self.event, session.avatar) except VCRoomError as err: if err.field is None: raise field = getattr(form, err.field) field.errors.append(err.message) else: db.session.add_all((vc_room, event_vc_room)) # TODO: notify_created(vc_room, self.event, session.avatar) flash(_("{plugin_name} room '{room.name}' created").format( plugin_name=self.plugin.friendly_name, room=vc_room), 'success') return redirect(url_for('.manage_vc_rooms', self.event)) form_html = self.plugin.render_form(plugin=self.plugin, event=self.event, form=form, skip_fields=form.skip_fields | {'name'}) return WPVCManageEvent.render_string(form_html, self.event)
def find_old_vidyo_rooms(max_room_event_age): """Finds all Vidyo rooms that are: - linked to no events - linked only to events whose start date precedes today - max_room_event_age days """ recently_used = (db.session.query(VCRoom.id) .filter(VCRoom.type == 'vidyo', Event.end_dt > (now_utc() - timedelta(days=max_room_event_age))) .join(VCRoom.events) .join(VCRoomEventAssociation.event_new) .group_by(VCRoom.id)) # non-deleted rooms with no recent associations return VCRoom.find_all(VCRoom.status != VCRoomStatus.deleted, ~VCRoom.id.in_(recently_used))
def find_old_vidyo_rooms(max_room_event_age): """Finds all Vidyo rooms that are: - linked to no events - linked only to events whose start date precedes today - max_room_event_age days """ recently_used = (db.session.query(VCRoom.id).filter( VCRoom.type == 'vidyo', Event.end_dt > (now_utc() - timedelta(days=max_room_event_age))).join( VCRoom.events).join(VCRoomEventAssociation.event_new).group_by( VCRoom.id)) # non-deleted rooms with no recent associations return VCRoom.find_all(VCRoom.status != VCRoomStatus.deleted, ~VCRoom.id.in_(recently_used))
def rooms(status=None): """Lists all Vidyo rooms""" room_query = VCRoom.find(type='vidyo') table_data = [['ID', 'Name', 'Status', 'Vidyo ID', 'Extension']] if status: room_query = room_query.filter(VCRoom.status == VCRoomStatus.get(status)) for room in room_query: table_data.append([unicode(room.id), room.name, room.status.name, unicode(room.data['vidyo_id']), unicode(room.vidyo_extension.extension)]) table = AsciiTable(table_data) for col in (0, 3, 4): table.justify_columns[col] = 'right' print table.table
def rooms(status=None): """Lists all Zoom rooms""" room_query = VCRoom.find(type='zoom') table_data = [['ID', 'Name', 'Status', 'Zoom ID', 'Meeting']] if status: room_query = room_query.filter(VCRoom.status == VCRoomStatus.get(status)) for room in room_query: table_data.append([unicode(room.id), room.name, room.status.name, unicode(room.data['zoom_id']), unicode(room.zoom_meeting.meeting)]) table = AsciiTable(table_data) for col in (0, 3, 4): table.justify_columns[col] = 'right' print table.table
def _create_meeting(name='New Room'): user_joe = create_user(1, email='*****@*****.**') vc_room = VCRoom(type='zoom', status=VCRoomStatus.created, name=name, created_by_id=0, data={ 'description': 'something something', 'password': '******', 'host': user_joe.identifier, 'meeting_type': 'meeting', 'mute_host_video': False, 'mute_audio': False, 'mute_participant_video': False, 'waiting_room': False }) VCRoomEventAssociation(linked_event=dummy_event, vc_room=vc_room, link_type=VCRoomLinkType.event, data={}) db.session.flush() zoom_plugin.create_room(vc_room, dummy_event) return vc_room
def _merge_users(user, merged, **kwargs): new_id = int(user.id) old_id = int(merged.id) VCRoom.find(created_by_id=old_id).update({'created_by_id': new_id})
def has_data(self): return VCRoom.find(type='vidyo').count() or VidyoExtension.find().count()
def _merge_users(target, source, **kwargs): VCRoom.find(created_by_id=source.id).update( {VCRoom.created_by_id: target.id})
def _merge_users(target, source, **kwargs): VCRoom.find(created_by_id=source.id).update({VCRoom.created_by_id: target.id})
def has_data(self): return VCRoom.find( type='vidyo').count() or VidyoExtension.find().count()