class AddChatroomForm(EditChatroomForm): use_custom_server = BooleanField(_('Use custom server')) custom_server = StringField(_('Custom server'), [UsedIf(lambda form, field: form.use_custom_server.data), DataRequired()], filters=[lambda x: x.lower() if x else x], description=_('External Jabber server.')) def __init__(self, *args, **kwargs): self._date = kwargs.pop('date') super(AddChatroomForm, self).__init__(*args, **kwargs) self.use_custom_server.description = _('Check in case you want to use an external Jabber server and not the ' 'default one ({0}).').format(current_plugin.settings.get('muc_server')) def validate_name(self, field): jid = generate_jid(field.data, self._date) if not jid: # This error is not very helpful to a user, but it is extremely unlikely - only if he uses a name # which does not contain a single char usable in a JID raise ValidationError(_('Could not convert name to a jabber ID')) if Chatroom.find_first(jid_node=jid, custom_server=self.custom_server.data): raise ValidationError(_('A room with this name already exists')) if not self.custom_server.data: tmp_room = Chatroom(jid_node=jid) if room_exists(tmp_room.jid): raise ValidationError(_('A room with this name/JID already exists on the Jabber server ({0})').format( tmp_room.jid )) @generated_data def jid_node(self): return generate_jid(self.name.data, self._date)
def _process(self): logs = self._get_logs() if not logs: if self.date_filter: msg = _('Could not find any logs for the given timeframe.') else: msg = _('Could not find any logs for the chatroom.') return jsonify(success=False, msg=msg) return jsonify(success=True, html=logs, params=request.args.to_dict())
class EditChatroomForm(IndicoForm): event_specific_fields = {'hidden', 'show_password'} # Room-wide options name = StringField(_('Name'), [DataRequired()], description=_('The name of the room')) description = TextAreaField(_('Description'), description=_('The description of the room')) password = StringField(_('Password'), description=_('An optional password required to join the room')) # Event-specific options hidden = BooleanField(_('Hidden'), description=_('Hides the room on public event pages.')) show_password = BooleanField(_('Show password'), description=_('Shows the room password on public event pages.'))
def extend_indico_help(self, sender, **kwargs): return { _('Chat Guides'): { _('Chat User Guide'): (url_for_plugin(self.name + '.static', filename='help/html/ChatUserGuide.html'), url_for_plugin(self.name + '.static', filename='help/pdf/ChatUserGuide.pdf')), _('Recommended Chat Clients'): (url_for_plugin(self.name + '.static', filename='help/html/XMPPClients.html'), url_for_plugin(self.name + '.static', filename='help/pdf/XMPPClients.pdf')) } }
def _process(self): reason = '{} has requested to delete this room.'.format(to_unicode(session.user.full_name)) chatroom_deleted = self.event_chatroom.delete(reason) notify_deleted(self.chatroom, self.event, session.user, chatroom_deleted) if chatroom_deleted: flash(_('Chatroom deleted'), 'success') else: flash(_('Chatroom removed from event'), 'success') self.event.log(EventLogRealm.management, EventLogKind.change, 'Chat', 'Chatroom removed: {}'.format(self.chatroom.name), session.user, data={'Deleted from server': 'Yes' if chatroom_deleted else 'No'}) return redirect(url_for_plugin('.manage_rooms', self.event))
def validate_name(self, field): jid = generate_jid(field.data, self._date) if not jid: # This error is not very helpful to a user, but it is extremely unlikely - only if he uses a name # which does not contain a single char usable in a JID raise ValidationError(_('Could not convert name to a jabber ID')) if Chatroom.find_first(jid_node=jid, custom_server=self.custom_server.data): raise ValidationError(_('A room with this name already exists')) if not self.custom_server.data: tmp_room = Chatroom(jid_node=jid) if room_exists(tmp_room.jid): raise ValidationError(_('A room with this name/JID already exists on the Jabber server ({0})').format( tmp_room.jid ))
def extend_event_menu(self, sender, **kwargs): return MenuEntryData(_('Chat Rooms'), 'chatrooms', 'chat.event_page', position=-1, visible=lambda event: ChatroomEventAssociation. find_for_event(event).has_rows())
def _process(self): form = AddChatroomForm(obj=FormDefaults(name=self.event.title), date=self.event.start_dt_local) if form.validate_on_submit(): chatroom = Chatroom(created_by_user=session.user) event_chatroom = ChatroomEventAssociation(event=self.event, chatroom=chatroom) form.populate_obj(event_chatroom, fields=form.event_specific_fields) form.populate_obj(chatroom, skip=form.event_specific_fields) chatroom.jid_node = form.jid_node.data db.session.add_all((chatroom, event_chatroom)) db.session.flush() create_room(chatroom) notify_created(chatroom, self.event, session.user) self.event.log(EventLogRealm.management, EventLogKind.positive, 'Chat', 'Chatroom created: {}'.format(chatroom.name), session.user) flash(_('Chatroom created'), 'success') return jsonify_data(flash=False) return jsonify_template('manage_event_edit.html', render_plugin_template, form=form, event=self.event)
def _process(self): if not retrieve_logs(self.chatroom): flash(_('There are no logs available for this room.'), 'warning') return redirect(url_for_plugin('.manage_rooms', self.event)) return WPChatEventMgmt.render_template('manage_event_logs.html', self._conf, event_chatroom=self.event_chatroom, start_date=self.event.getAdjustedStartDate(), end_date=self.event.getAdjustedEndDate())
def __init__(self, *args, **kwargs): self._date = kwargs.pop('date') super(AddChatroomForm, self).__init__(*args, **kwargs) self.use_custom_server.description = _( 'Check in case you want to use an external Jabber server and not the ' 'default one ({0}).').format( current_plugin.settings.get('muc_server'))
def _process(self): form = self._get_attach_form() if form.validate_on_submit(): event_chatroom = ChatroomEventAssociation(event=self.event, chatroom=form.chatroom.data) notify_attached(form.chatroom.data, self.event, session.user) flash(_('Chatroom added'), 'success') self.event.log(EventLogRealm.management, EventLogKind.positive, 'Chat', 'Chatroom attached: {}'.format(event_chatroom.chatroom.name), session.user) return redirect(url_for_plugin('.manage_rooms', self.event))
def _process(self): form = self._get_attach_form() if form.validate_on_submit(): event_chatroom = ChatroomEventAssociation(event_id=self.event_id, chatroom=form.chatroom.data) db.session.add(event_chatroom) notify_attached(form.chatroom.data, self.event, session.user) flash(_('Chatroom added'), 'success') self.event.log(EventLogRealm.management, EventLogKind.positive, 'Chat', 'Chatroom attached: {}'.format(event_chatroom.chatroom.name), session.user) return redirect(url_for_plugin('.manage_rooms', self.event))
def check_config(quiet=False): """Checks if all required config options are set :param quiet: if True, return the result as a bool, otherwise raise `IndicoError` if any setting is missing """ from indico_chat.plugin import ChatPlugin settings = ChatPlugin.settings.get_all() missing = not all(settings[x] for x in ('server', 'muc_server', 'bot_jid', 'bot_password')) if missing and not quiet: raise IndicoError(_('Chat plugin is not configured properly')) return not missing
def _process(self): form = AddChatroomForm(obj=FormDefaults(name=to_unicode(self.event.title)), date=self.event.getAdjustedStartDate()) if form.validate_on_submit(): chatroom = Chatroom(created_by_user=session.user) event_chatroom = ChatroomEventAssociation(event_id=self.event_id, chatroom=chatroom) form.populate_obj(event_chatroom, fields=form.event_specific_fields) form.populate_obj(chatroom, skip=form.event_specific_fields) chatroom.jid_node = form.jid_node.data db.session.add_all((chatroom, event_chatroom)) db.session.flush() create_room(chatroom) notify_created(chatroom, self.event, session.user) self.event.log(EventLogRealm.management, EventLogKind.positive, 'Chat', 'Chatroom created: {}'.format(chatroom.name), session.user) flash(_('Chatroom created'), 'success') return redirect(url_for_plugin('.manage_rooms', self.event)) return WPChatEventMgmt.render_template('manage_event_edit.html', self._conf, form=form, event=self.event)
def _process(self): defaults = FormDefaults(self.chatroom) for name in EditChatroomForm.event_specific_fields: defaults[name] = getattr(self.event_chatroom, name) form = EditChatroomForm(obj=defaults) if form.validate_on_submit(): form.populate_obj(self.event_chatroom, fields=form.event_specific_fields) form.populate_obj(self.chatroom, skip=form.event_specific_fields) self.chatroom.modified_dt = now_utc() if attrs_changed(self.chatroom, 'name', 'description', 'password'): update_room(self.chatroom) notify_modified(self.chatroom, self.event, session.user) flash(_('Chatroom updated'), 'success') self.event.log(EventLogRealm.management, EventLogKind.change, 'Chat', 'Chatroom updated: {}'.format(self.chatroom.name), session.user) return redirect(url_for_plugin('.manage_rooms', self.event)) return WPChatEventMgmt.render_template('manage_event_edit.html', self._conf, form=form, event_chatroom=self.event_chatroom, event=self.event)
def _process(self): defaults = FormDefaults(self.chatroom) for name in EditChatroomForm.event_specific_fields: defaults[name] = getattr(self.event_chatroom, name) form = EditChatroomForm(obj=defaults) if form.validate_on_submit(): form.populate_obj(self.event_chatroom, fields=form.event_specific_fields) form.populate_obj(self.chatroom, skip=form.event_specific_fields) self.chatroom.modified_dt = now_utc() if attrs_changed(self.chatroom, 'name', 'description', 'password'): update_room(self.chatroom) notify_modified(self.chatroom, self.event, session.user) flash(_('Chatroom updated'), 'success') self.event.log(EventLogRealm.management, EventLogKind.change, 'Chat', 'Chatroom updated: {}'.format(self.chatroom.name), session.user) return jsonify_data(flash=False) return jsonify_template('manage_event_edit.html', render_plugin_template, form=form, event=self.event, event_chatroom=self.event_chatroom)
def _process(self): if self.chatroom.custom_server: return jsonify(result='') config = get_room_config(self.chatroom.jid) if config is None: if not room_exists(self.chatroom.jid): return jsonify(result='not-found') raise IndicoError(_('Unexpected result from Jabber server')) changed = False for key, value in config.iteritems(): if getattr(self.chatroom, key) != value: changed = True setattr(self.chatroom, key, value) if changed: self.event.log(EventLogRealm.management, EventLogKind.change, 'Chat', 'Chatroom updated during refresh: {}'.format(self.chatroom.name), session.user) return jsonify(result='changed' if changed else '')
class AttachChatroomForm(IndicoForm): chatroom = QuerySelectField(_('Available chatrooms'), [DataRequired()], get_label='name')
def validate_chat_links(self, field): for item in field.data: if not all(item.values()): raise ValidationError(_('All fields must contain a value.'))
def extend_event_menu(self, sender, **kwargs): return MenuEntryData(_('Chat Rooms'), 'chatrooms', 'chat.event_page', position=-1, visible=lambda event: bool(ChatroomEventAssociation.find_for_event(event).count()))
def __init__(self, *args, **kwargs): self._date = kwargs.pop('date') super(AddChatroomForm, self).__init__(*args, **kwargs) self.use_custom_server.description = _('Check in case you want to use an external Jabber server and not the ' 'default one ({0}).').format(current_plugin.settings.get('muc_server'))
def _process(self): logs = self._get_logs() if not logs: return jsonify(success=False, msg=_('No logs found')) self._create_material(logs) return jsonify(success=True)