Ejemplo n.º 1
0
class RoomAssistancePlugin(IndicoPlugin):
    """Room assistance request

    This plugin lets users request assistance for meeting rooms.
    """

    configurable = True
    settings_form = RoomAssistanceForm
    settings_converters = {'rooms_with_assistance': ModelListConverter(Room)}
    acl_settings = {'room_assistance_support'}
    default_settings = {
        'room_assistance_recipients': [],
        'rooms_with_assistance': [],
    }

    def init(self):
        super(RoomAssistancePlugin, self).init()
        self.template_hook('event-actions', self._room_assistance_action)
        self.connect(signals.menu.items,
                     self._extend_services_menu,
                     sender='top-menu')
        self.connect(signals.plugin.get_event_request_definitions,
                     self._get_room_assistance_request)

    def get_blueprints(self):
        return blueprint

    def _room_assistance_action(self, event, **kwargs):
        has_room_assistance_request = event.requests.filter_by(
            type='room-assistance').has_rows()
        room_allows_assistance = event.room is not None and event.room in self.settings.get(
            'rooms_with_assistance')
        can_request_assistance = not event.has_ended and not has_room_assistance_request and room_allows_assistance
        return render_plugin_template(
            'room_assistance_action.html',
            event=event,
            can_request_assistance=can_request_assistance)

    def _extend_services_menu(self, reservation, **kwargs):
        if not session.user or not is_room_assistance_support(session.user):
            return

        return TopMenuItem('services-cern-room-assistance',
                           _('Room assistance'),
                           url_for_plugin('room_assistance.request_list'),
                           section='services')

    def _get_room_assistance_request(self, sender, **kwargs):
        return RoomAssistanceRequest
Ejemplo n.º 2
0
class RoomAssistancePlugin(IndicoPlugin):
    """Room assistance request

    This plugin lets users request assistance for meeting rooms.
    """

    configurable = True
    settings_form = RoomAssistanceForm
    settings_converters = {'rooms_with_assistance': ModelListConverter(Room)}
    acl_settings = {'room_assistance_support'}
    default_settings = {
        'room_assistance_recipients': [],
        'rooms_with_assistance': [],
    }

    def init(self):
        super(RoomAssistancePlugin, self).init()
        self.inject_bundle('main.css',
                           WPRequestsEventManagement,
                           subclasses=False,
                           condition=lambda: request.view_args.get('type') ==
                           RoomAssistanceRequest.name)
        self.template_hook('event-actions', self._room_assistance_action)
        self.connect(signals.menu.items,
                     self._extend_services_menu,
                     sender='top-menu')
        self.connect(signals.plugin.get_event_request_definitions,
                     self._get_room_assistance_request)
        self.connect(signals.event.updated, self._on_event_update)

    def get_blueprints(self):
        return blueprint

    def _room_assistance_action(self, event, **kwargs):
        return render_plugin_template(
            'room_assistance_action.html',
            event=event,
            can_request_assistance=can_request_assistance_for_event(event))

    def _extend_services_menu(self, reservation, **kwargs):
        if not session.user or not is_room_assistance_support(session.user):
            return

        return TopMenuItem('services-cern-room-assistance',
                           _('Room assistance'),
                           url_for_plugin('room_assistance.request_list'),
                           section='services')

    def _get_room_assistance_request(self, sender, **kwargs):
        return RoomAssistanceRequest

    def _on_event_update(self, event, **kwargs):
        changes = kwargs['changes']
        if not changes.viewkeys() & {'location_data', 'start_dt', 'end_dt'}:
            return

        request = Request.find_latest_for_event(event,
                                                RoomAssistanceRequest.name)
        if not request or request.state != RequestState.accepted:
            return

        if 'location_data' in changes and not event_has_room_with_support_attached(
                event):
            request.definition.reject(
                request, {
                    'comment':
                    render_plugin_template('auto_reject_no_supported_room.txt')
                }, User.get_system_user())
            request.data = dict(request.data, occurrences=[])
            flash(
                _("The new event location is not in the list of the rooms supported by the room assistance team. "
                  "Room assistance request has been rejected and support will not be provided."
                  ), 'warning')
        if changes.viewkeys() & {'start_dt', 'end_dt'}:
            tz = pytz.timezone(config.DEFAULT_TIMEZONE)
            occurrences = {
                dateutil.parser.parse(occ).astimezone(tz)
                for occ in request.data['occurrences']
            }
            req_dates = {occ.date() for occ in occurrences}
            event_dates = set(event.iter_days())
            old_dates = req_dates - event_dates
            has_overlapping_dates = req_dates & event_dates

            if not has_overlapping_dates:
                request.definition.reject(
                    request, {
                        'comment':
                        render_plugin_template(
                            'auto_reject_no_overlapping_dates.txt')
                    }, User.get_system_user())
                request.data = dict(request.data, occurrences=[])
                flash(
                    _("The new event dates don't overlap with the existing room assistance request for this event. "
                      "Room assistance request has been rejected and support will not be provided."
                      ), 'warning')
            elif old_dates and has_overlapping_dates:
                new_data = dict(request.data)
                new_data['occurrences'] = [
                    occ.astimezone(pytz.utc).isoformat() for occ in occurrences
                    if occ.date() in req_dates & event_dates
                ]
                request.data = new_data
                flash(
                    _("Room assistance had been requested for days that are not between the updated start/end "
                      "dates. Support will not be provided on these days anymore."
                      ), 'warning')
Ejemplo n.º 3
0
        'managers_edit_rooms': False,
        'excluded_categories': [],
        'notification_before_days': 2,
        'notification_before_days_weekly': 5,
        'notification_before_days_monthly': 7,
        'notifications_enabled': True,
        'end_notification_daily': 1,
        'end_notification_weekly': 3,
        'end_notification_monthly': 7,
        'end_notifications_enabled': True,
        'booking_limit': 365,
        'tileserver_url': None,
        'grace_period': None,
    },
    acls={'admin_principals', 'authorized_principals'},
    converters={'excluded_categories': ModelListConverter(Category)})


@signals.core.import_tasks.connect
def _import_tasks(sender, **kwargs):
    import indico.modules.rb.tasks  # noqa: F401


@signals.users.preferences.connect
def _get_extra_user_prefs(sender, **kwargs):
    from indico.modules.rb.user_prefs import RBUserPreferences
    if config.ENABLE_ROOMBOOKING:
        return RBUserPreferences


@signals.menu.items.connect_via('admin-sidemenu')
Ejemplo n.º 4
0
#
# Indico is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see the
# LICENSE file for more details.

from indico.core.settings.converters import EnumConverter, ModelListConverter
from indico.modules.users import UserSettingsProxy
from indico.util.i18n import _
from indico.util.struct.enum import RichIntEnum


class RoomEmailMode(RichIntEnum):
    __titles__ = (_('None'), _('Rooms I own'), _('Rooms I manage'),
                  _('Rooms I own or manage'))
    none = 0
    owned = 1
    managed = 2
    all = 3


rb_user_settings = UserSettingsProxy('roombooking', {
    'email_mode': RoomEmailMode.all,
    'email_blacklist': [],
},
                                     converters={
                                         'email_mode':
                                         EnumConverter(RoomEmailMode),
                                         'email_blacklist':
                                         ModelListConverter('Room'),
                                     })
Ejemplo n.º 5
0
# This file is part of Indico.
# Copyright (C) 2002 - 2020 CERN
#
# Indico is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see the
# LICENSE file for more details.

from __future__ import unicode_literals

from indico.core.settings.converters import EnumConverter, ModelListConverter
from indico.modules.users import UserSettingsProxy
from indico.util.i18n import _
from indico.util.struct.enum import RichIntEnum


class RoomEmailMode(RichIntEnum):
    __titles__ = (_('None'), _('Rooms I own'), _('Rooms I manage'), _('Rooms I own or manage'))
    none = 0
    owned = 1
    managed = 2
    all = 3


rb_user_settings = UserSettingsProxy('roombooking', {
    'email_mode': RoomEmailMode.all,
    'email_blacklist': [],
}, converters={
    'email_mode': EnumConverter(RoomEmailMode),
    'email_blacklist': ModelListConverter('Room'),
})