Пример #1
0
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)
Пример #2
0
 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())
Пример #3
0
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.'))
Пример #4
0
 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'))
         }
     }
Пример #5
0
 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))
Пример #6
0
 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))
Пример #7
0
 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
             ))
Пример #8
0
 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())
Пример #9
0
 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)
Пример #10
0
 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())
Пример #11
0
 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'))
Пример #12
0
 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))
Пример #13
0
 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))
Пример #14
0
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
Пример #15
0
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
Пример #16
0
 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)
Пример #17
0
 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)
Пример #18
0
 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)
Пример #19
0
 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)
Пример #20
0
    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 '')
Пример #21
0
    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 '')
Пример #22
0
class AttachChatroomForm(IndicoForm):
    chatroom = QuerySelectField(_('Available chatrooms'), [DataRequired()],
                                get_label='name')
Пример #23
0
 def validate_chat_links(self, field):
     for item in field.data:
         if not all(item.values()):
             raise ValidationError(_('All fields must contain a value.'))
Пример #24
0
 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()))
Пример #25
0
 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'))
Пример #26
0
 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)