Ejemplo n.º 1
0
    def send(cls, req, data):
        room = req.event.room
        if room is None or room not in cls.plugin.settings.get(
                'rooms_with_assistance'):
            raise Forbidden

        data['start_dt'] = data['start_dt'].isoformat()
        is_new = req.id is None
        req.state = RequestState.accepted
        old_data = {} if is_new else req.data

        super(RoomAssistanceRequest, cls).send(req, data)
        with plugin_context(cls.plugin):
            if is_new:
                notify_about_new_request(req)
            else:
                changes = {}
                if data['reason'] != old_data['reason']:
                    changes['reason'] = {
                        'old': old_data['reason'],
                        'new': data['reason']
                    }
                if data['start_dt'] != old_data['start_dt']:
                    changes['start_dt'] = {
                        'old': dateutil.parser.parse(old_data['start_dt']),
                        'new': dateutil.parser.parse(data['start_dt'])
                    }
                if changes:
                    notify_about_request_modification(req, changes)
Ejemplo n.º 2
0
    def send(cls, req, data):
        room = req.event.room
        if room is None or room not in cls.plugin.settings.get(
                'rooms_with_assistance'):
            raise Forbidden

        is_new = req.id is None
        req.state = RequestState.accepted
        old_data = {} if is_new else req.data
        data['occurrences'] = [
            occ.astimezone(pytz.utc).isoformat() for occ in data['occurrences']
        ]

        super().send(req, data)
        with plugin_context(cls.plugin):
            if is_new:
                notify_about_new_request(req)
            else:
                changes = {}
                if data['reason'] != old_data['reason']:
                    changes['reason'] = {
                        'old': old_data['reason'],
                        'new': data['reason']
                    }
                if data['occurrences'] != old_data['occurrences']:
                    changes['occurrences'] = [
                        dateutil.parser.parse(occ)
                        for occ in data['occurrences']
                    ]
                if changes:
                    notify_about_request_modification(req, changes)
Ejemplo n.º 3
0
def _get_notification_reply_email(req):
    """
    Get the e-mail address that should be the `Reply-To:` of
    user notifications.
    """
    with plugin_context(req.definition.plugin):
        return req.definition.get_notification_reply_email()
Ejemplo n.º 4
0
 def create_form(cls, event, existing_request=None):
     form_data = {'occurrences': None}
     if existing_request:
         tz = pytz.timezone(config.DEFAULT_TIMEZONE)
         form_data = dict(existing_request.data)
         form_data['occurrences'] = [dateutil.parser.parse(occ).astimezone(tz) for occ in form_data['occurrences']]
     with plugin_context(cls.plugin):
         return cls.form(prefix='request-', obj=FormDefaults(form_data), event=event, request=existing_request)
Ejemplo n.º 5
0
    def create_manager_form(cls, req):
        """Creates the request management form

        :param req: the :class:`Request` of the request
        :return: an instance of an :class:`IndicoForm` subclass
        """
        defaults = FormDefaults(req, **req.data)
        with plugin_context(cls.plugin):
            return cls.manager_form(prefix='request-manage-', obj=defaults)
Ejemplo n.º 6
0
    def create_manager_form(cls, req):
        """Creates the request management form

        :param req: the :class:`Request` of the request
        :return: an instance of an :class:`IndicoForm` subclass
        """
        defaults = FormDefaults(req, **req.data)
        with plugin_context(cls.plugin):
            return cls.manager_form(prefix='request-manage-', obj=defaults)
Ejemplo n.º 7
0
    def create_form(cls, event, existing_request=None):
        """Creates the request form

        :param event: the event the request is for
        :param existing_request: the :class:`Request` if there's an existing request of this type
        :return: an instance of an :class:`IndicoForm` subclass
        """
        defaults = FormDefaults(existing_request.data if existing_request else cls.form_defaults)
        with plugin_context(cls.plugin):
            return cls.form(prefix='request-', obj=defaults, event=event, request=existing_request)
Ejemplo n.º 8
0
    def create_form(cls, event, existing_request=None):
        """Create the request form.

        :param event: the event the request is for
        :param existing_request: the :class:`Request` if there's an existing request of this type
        :return: an instance of an :class:`IndicoForm` subclass
        """
        defaults = FormDefaults(existing_request.data if existing_request else cls.form_defaults)
        with plugin_context(cls.plugin):
            return cls.form(prefix='request-', obj=defaults, event=event, request=existing_request)
Ejemplo n.º 9
0
 def create_form(cls, event, existing_request=None):
     default_data = cls.form_defaults
     if existing_request:
         default_data = dict(existing_request.data)
         if default_data['start_dt_override']:
             default_data['start_dt_override'] = dateutil.parser.parse(default_data['start_dt_override'])
         if default_data['end_dt_override']:
             default_data['end_dt_override'] = dateutil.parser.parse(default_data['end_dt_override'])
     with plugin_context(cls.plugin):
         return cls.form(prefix='request-', obj=FormDefaults(default_data), event=event, request=existing_request)
Ejemplo n.º 10
0
def test_template_plugin_contexts_super(flask_app_ctx, loaded_engine, in_plugin_ctx):
    """
    Check that the plugin context is handled properly when using `super()`
    """
    plugin = loaded_engine.get_plugin('espresso')
    with plugin_context(plugin if in_plugin_ctx else None):
        assert _parse_template_data(render_template('base.txt')) == {
            'block': 'core',
        }
        assert _parse_template_data(render_template('espresso:super.txt')) == {
            'block': 'core/espresso',
        }
Ejemplo n.º 11
0
 def create_form(cls, event, existing_request=None):
     form_data = {'start_dt': event.start_dt_local - timedelta(minutes=30)}
     if existing_request:
         form_data = dict(existing_request.data)
         if form_data['start_dt']:
             form_data['start_dt'] = dateutil.parser.parse(
                 form_data['start_dt'])
     with plugin_context(cls.plugin):
         return cls.form(prefix='request-',
                         obj=FormDefaults(form_data),
                         event=event,
                         request=existing_request)
Ejemplo n.º 12
0
def test_template_plugin_contexts_super(flask_app_ctx, loaded_engine, in_plugin_ctx):
    """
    Check that the plugin context is handled properly when using `super()`
    """
    plugin = loaded_engine.get_plugin('espresso')
    with plugin_context(plugin if in_plugin_ctx else None):
        assert _parse_template_data(render_template('base.txt')) == {
            'block': 'core',
        }
        assert _parse_template_data(render_template('espresso:super.txt')) == {
            'block': 'core/espresso',
        }
Ejemplo n.º 13
0
def test_template_plugin_contexts_macros_nested_calls(flask_app_ctx, loaded_engine, in_plugin_ctx):
    """
    Check that the plugin context is handled properly when using nested call blocks
    """
    plugin = loaded_engine.get_plugin('espresso')
    with plugin_context(plugin if in_plugin_ctx else None):
        assert _parse_template_data(render_template('nested_calls.txt')) == {
            'outer': 'core-outer-macro/core/core',
            'inner': 'core-inner-macro/core/core',
        }
        assert _parse_template_data(render_template('espresso:nested_calls.txt')) == {
            'outer': 'core-outer-macro/core/espresso',
            'inner': 'core-inner-macro/core/espresso',
        }
Ejemplo n.º 14
0
def test_template_plugin_contexts_macros(flask_app_ctx, loaded_engine, in_plugin_ctx):
    """
    Check that the plugin context is handled properly in macros
    """
    plugin = loaded_engine.get_plugin('espresso')
    with plugin_context(plugin if in_plugin_ctx else None):
        assert _parse_template_data(render_template('simple_macro.txt')) == {
            'macro': 'core-imp-macro/core/undef',
            'macro_call': 'core-imp-macro/core/core'
        }
        assert _parse_template_data(render_template('espresso:simple_macro.txt')) == {
            'macro': 'core-imp-macro/core/undef',
            'macro_call': 'core-imp-macro/core/espresso'
        }
Ejemplo n.º 15
0
def test_template_plugin_contexts_macros_extends_base(flask_app_ctx, loaded_engine, in_plugin_ctx):
    """
    Check that the plugin context is handled properly in macros defined/called in the base tpl
    """
    plugin = loaded_engine.get_plugin('espresso')
    with plugin_context(plugin if in_plugin_ctx else None):
        assert _parse_template_data(render_template('simple_macro_extends_base.txt')) == {
            'core_macro': 'core-macro/core/undef',
            'core_macro_call': 'core-macro/core/core',
        }
        assert _parse_template_data(render_template('espresso:simple_macro_extends_base.txt')) == {
            'core_macro': 'core-macro/core/undef',
            'core_macro_call': 'core-macro/core/core',
        }
Ejemplo n.º 16
0
def test_template_plugin_contexts_macros(flask_app_ctx, loaded_engine, in_plugin_ctx):
    """
    Check that the plugin context is handled properly in macros
    """
    plugin = loaded_engine.get_plugin('espresso')
    with plugin_context(plugin if in_plugin_ctx else None):
        assert _parse_template_data(render_template('simple_macro.txt')) == {
            'macro': 'core-imp-macro/core/undef',
            'macro_call': 'core-imp-macro/core/core'
        }
        assert _parse_template_data(render_template('espresso:simple_macro.txt')) == {
            'macro': 'core-imp-macro/core/undef',
            'macro_call': 'core-imp-macro/core/espresso'
        }
Ejemplo n.º 17
0
def test_template_plugin_contexts_macros_extends_base(flask_app_ctx, loaded_engine, in_plugin_ctx):
    """
    Check that the plugin context is handled properly in macros defined/called in the base tpl
    """
    plugin = loaded_engine.get_plugin('espresso')
    with plugin_context(plugin if in_plugin_ctx else None):
        assert _parse_template_data(render_template('simple_macro_extends_base.txt')) == {
            'core_macro': 'core-macro/core/undef',
            'core_macro_call': 'core-macro/core/core',
        }
        assert _parse_template_data(render_template('espresso:simple_macro_extends_base.txt')) == {
            'core_macro': 'core-macro/core/undef',
            'core_macro_call': 'core-macro/core/core',
        }
Ejemplo n.º 18
0
def test_template_plugin_contexts_macros_nested_calls(flask_app_ctx, loaded_engine, in_plugin_ctx):
    """
    Check that the plugin context is handled properly when using nested call blocks
    """
    plugin = loaded_engine.get_plugin('espresso')
    with plugin_context(plugin if in_plugin_ctx else None):
        assert _parse_template_data(render_template('nested_calls.txt')) == {
            'outer': 'core-outer-macro/core/core',
            'inner': 'core-inner-macro/core/core',
        }
        assert _parse_template_data(render_template('espresso:nested_calls.txt')) == {
            'outer': 'core-outer-macro/core/espresso',
            'inner': 'core-inner-macro/core/espresso',
        }
Ejemplo n.º 19
0
 def __call__(s, *args, **kwargs):
     stack = ExitStack()
     stack.enter_context(self.flask_app.app_context())
     stack.enter_context(DBMgr.getInstance().global_connection())
     if getattr(s, 'request_context', False):
         stack.enter_context(self.flask_app.test_request_context())
     args = _CelerySAWrapper.unwrap_args(args)
     kwargs = _CelerySAWrapper.unwrap_kwargs(kwargs)
     plugin = getattr(s, 'plugin', kwargs.pop('__current_plugin__', None))
     if isinstance(plugin, basestring):
         plugin_name = plugin
         plugin = plugin_engine.get_plugin(plugin)
         if plugin is None:
             stack.close()
             raise ValueError('Plugin not active: ' + plugin_name)
     stack.enter_context(plugin_context(plugin))
     with stack:
         return super(IndicoTask, s).__call__(*args, **kwargs)
Ejemplo n.º 20
0
 def __call__(s, *args, **kwargs):
     stack = ExitStack()
     stack.enter_context(self.flask_app.app_context())
     if getattr(s, 'request_context', False):
         stack.enter_context(self.flask_app.test_request_context(base_url=config.BASE_URL))
     args = _CelerySAWrapper.unwrap_args(args)
     kwargs = _CelerySAWrapper.unwrap_kwargs(kwargs)
     plugin = getattr(s, 'plugin', s.request.get('indico_plugin'))
     if isinstance(plugin, basestring):
         plugin_name = plugin
         plugin = plugin_engine.get_plugin(plugin)
         if plugin is None:
             stack.close()
             raise ValueError('Plugin not active: ' + plugin_name)
     stack.enter_context(plugin_context(plugin))
     clearCache()
     with stack:
         request_stats_request_started()
         return super(IndicoTask, s).__call__(*args, **kwargs)
Ejemplo n.º 21
0
 def __call__(s, *args, **kwargs):
     stack = ExitStack()
     stack.enter_context(self.flask_app.app_context())
     if getattr(s, 'request_context', False):
         stack.enter_context(
             self.flask_app.test_request_context(
                 base_url=config.BASE_URL))
     args = _CelerySAWrapper.unwrap_args(args)
     kwargs = _CelerySAWrapper.unwrap_kwargs(kwargs)
     plugin = getattr(s, 'plugin', s.request.get('indico_plugin'))
     if isinstance(plugin, basestring):
         plugin_name = plugin
         plugin = plugin_engine.get_plugin(plugin)
         if plugin is None:
             stack.close()
             raise ValueError('Plugin not active: ' + plugin_name)
     stack.enter_context(plugin_context(plugin))
     clearCache()
     with stack:
         request_stats_request_started()
         return super(IndicoTask, s).__call__(*args, **kwargs)
Ejemplo n.º 22
0
 def __call__(s, *args, **kwargs):
     stack = ExitStack()
     stack.enter_context(self.flask_app.app_context())
     stack.enter_context(DBMgr.getInstance().global_connection())
     if getattr(s, 'request_context', False):
         stack.enter_context(
             self.flask_app.test_request_context(
                 base_url=Config.getInstance().getBaseURL()))
     args = _CelerySAWrapper.unwrap_args(args)
     kwargs = _CelerySAWrapper.unwrap_kwargs(kwargs)
     plugin = getattr(s, 'plugin',
                      kwargs.pop('__current_plugin__', None))
     if isinstance(plugin, basestring):
         plugin_name = plugin
         plugin = plugin_engine.get_plugin(plugin)
         if plugin is None:
             stack.close()
             raise ValueError('Plugin not active: ' + plugin_name)
     stack.enter_context(plugin_context(plugin))
     clearCache()
     with stack:
         return super(IndicoTask, s).__call__(*args, **kwargs)
Ejemplo n.º 23
0
def test_template_plugin_contexts(flask_app_ctx, loaded_engine, in_plugin_ctx):
    """
    Check that the plugin contexts are correct in all cases
    """
    plugin = loaded_engine.get_plugin('espresso')
    with plugin_context(plugin if in_plugin_ctx else None):
        assert _parse_template_data(render_template('context.txt')) == {
            'core_main': 'core',
            'core_block_a': 'core-a/core',
            'core_block_b': 'core-b/core',
            'core_macro': 'core-macro/core/undef',
            'core_macro_call': 'core-macro/core/core',
            'core_macro_imp': 'core-imp-macro/core/undef',
            'core_macro_imp_call': 'core-imp-macro/core/core',
            'core_macro_plugin_imp': 'plugin-imp-macro/espresso/undef',
            'core_macro_plugin_imp_call': 'plugin-imp-macro/espresso/core',
            'core_inc_core': 'core test',
            'core_inc_plugin': 'plugin test',
        }
        assert _parse_template_data(
            render_template('espresso:context.txt')) == {
                'core_main': 'core',
                'core_block_a': 'plugin-a/espresso',
                'core_block_b': 'core-b/core',
                'core_macro': 'core-macro/core/undef',
                'core_macro_call': 'core-macro/core/core',
                'core_macro_in_plugin': 'core-macro/core/undef',
                'core_macro_in_plugin_call': 'core-macro/core/espresso',
                'core_macro_imp': 'core-imp-macro/core/undef',
                'core_macro_imp_call': 'core-imp-macro/core/core',
                'core_macro_plugin_imp': 'plugin-imp-macro/espresso/undef',
                'core_macro_plugin_imp_call': 'plugin-imp-macro/espresso/core',
                'plugin_macro': 'plugin-macro/espresso/undef',
                'plugin_macro_call': 'plugin-macro/espresso/espresso',
                'core_inc_core': 'core test',
                'core_inc_plugin': 'plugin test',
                'plugin_inc_core': 'core test',
                'plugin_inc_plugin': 'plugin test',
            }
Ejemplo n.º 24
0
def test_template_plugin_contexts(flask_app_ctx, loaded_engine, in_plugin_ctx):
    """
    Check that the plugin contexts are correct in all cases
    """
    plugin = loaded_engine.get_plugin('espresso')
    with plugin_context(plugin if in_plugin_ctx else None):
        assert _parse_template_data(render_template('context.txt')) == {
            'core_main': 'core',
            'core_block_a': 'core-a/core',
            'core_block_b': 'core-b/core',
            'core_macro': 'core-macro/core/undef',
            'core_macro_call': 'core-macro/core/core',
            'core_macro_imp': 'core-imp-macro/core/undef',
            'core_macro_imp_call': 'core-imp-macro/core/core',
            'core_macro_plugin_imp': 'plugin-imp-macro/espresso/undef',
            'core_macro_plugin_imp_call': 'plugin-imp-macro/espresso/core',
            'core_inc_core': 'core test',
            'core_inc_plugin': 'plugin test',
        }
        assert _parse_template_data(render_template('espresso:context.txt')) == {
            'core_main': 'core',
            'core_block_a': 'plugin-a/espresso',
            'core_block_b': 'core-b/core',
            'core_macro': 'core-macro/core/undef',
            'core_macro_call': 'core-macro/core/core',
            'core_macro_in_plugin': 'core-macro/core/undef',
            'core_macro_in_plugin_call': 'core-macro/core/espresso',
            'core_macro_imp': 'core-imp-macro/core/undef',
            'core_macro_imp_call': 'core-imp-macro/core/core',
            'core_macro_plugin_imp': 'plugin-imp-macro/espresso/undef',
            'core_macro_plugin_imp_call': 'plugin-imp-macro/espresso/core',
            'plugin_macro': 'plugin-macro/espresso/undef',
            'plugin_macro_call': 'plugin-macro/espresso/espresso',
            'core_inc_core': 'core test',
            'core_inc_plugin': 'plugin test',
            'plugin_inc_core': 'core test',
            'plugin_inc_plugin': 'plugin test',
        }
Ejemplo n.º 25
0
def _get_request_manager_emails(req):
    """Get set of request manager emails"""
    with plugin_context(req.definition.plugin):
        return req.definition.get_manager_notification_emails()
Ejemplo n.º 26
0
 def withdraw(cls, req, notify_event_managers=True):
     super().withdraw(req, notify_event_managers)
     with plugin_context(cls.plugin):
         notify_about_withdrawn_request(req)