Beispiel #1
0
    def get_context_data(self, *args, **kwargs) -> dict:
        from pretix.base.plugins import get_all_plugins

        context = super().get_context_data(*args, **kwargs)
        context['plugins'] = [p for p in get_all_plugins() if not p.name.startswith('.')]
        context['plugins_active'] = self.object.get_plugins()
        return context
Beispiel #2
0
    def to_representation(self, obj):
        from pretix.base.plugins import get_all_plugins

        return sorted([
            p.module for p in get_all_plugins()
            if not p.name.startswith('.') and getattr(p, 'visible', True) and p.module in obj.get_plugins()
        ])
Beispiel #3
0
    def post(self, request, *args, **kwargs):
        from pretix.base.plugins import get_all_plugins

        self.object = self.get_object()

        plugins_active = self.object.get_plugins()
        plugins_available = {
            p.module: p for p in get_all_plugins()
            if not p.name.startswith('.') and getattr(p, 'visible', True)
        }

        with transaction.atomic():
            for key, value in request.POST.items():
                if key.startswith("plugin:"):
                    module = key.split(":")[1]
                    if value == "enable" and module in plugins_available:
                        self.request.event.log_action('pretix.event.plugins.enabled', user=self.request.user,
                                                      data={'plugin': module})
                        if module not in plugins_active:
                            plugins_active.append(module)
                    else:
                        self.request.event.log_action('pretix.event.plugins.disabled', user=self.request.user,
                                                      data={'plugin': module})
                        if module in plugins_active:
                            plugins_active.remove(module)
            self.object.plugins = ",".join(plugins_active)
            self.object.save()
        messages.success(self.request, _('Your changes have been saved.'))
        return redirect(self.get_success_url())
Beispiel #4
0
    def to_representation(self, obj):
        from pretix.base.plugins import get_all_plugins

        return {
            p.module for p in get_all_plugins()
            if not p.name.startswith('.') and getattr(p, 'visible', True) and p.module in obj.get_plugins()
        }
Beispiel #5
0
    def get_context_data(self, *args, **kwargs) -> dict:
        from pretix.base.plugins import get_all_plugins

        context = super().get_context_data(*args, **kwargs)
        context['plugins'] = [p for p in get_all_plugins() if not p.name.startswith('.')
                              and getattr(p, 'visible', True)]
        context['plugins_active'] = self.object.get_plugins()
        return context
Beispiel #6
0
    def validate_plugins(self, value):
        from pretix.base.plugins import get_all_plugins

        plugins_available = {
            p.module for p in get_all_plugins()
            if not p.name.startswith('.') and getattr(p, 'visible', True)
        }

        for plugin in value.get('plugins'):
            if plugin not in plugins_available:
                raise ValidationError(_('Unknown plugin: \'{name}\'.').format(name=plugin))

        return value
Beispiel #7
0
    def validate_plugins(self, value):
        from pretix.base.plugins import get_all_plugins

        plugins_available = {
            p.module for p in get_all_plugins(self.instance)
            if not p.name.startswith('.') and getattr(p, 'visible', True)
        }

        for plugin in value.get('plugins'):
            if plugin not in plugins_available:
                raise ValidationError(_('Unknown plugin: \'{name}\'.').format(name=plugin))

        return value
Beispiel #8
0
def update_check():
    gs = GlobalSettingsObject()

    if not gs.settings.update_check_id:
        gs.settings.set('update_check_id', uuid.uuid4().hex)

    if not gs.settings.update_check_perform:
        return

    if 'runserver' in sys.argv:
        gs.settings.set('update_check_last', now())
        gs.settings.set('update_check_result', {
            'error': 'development'
        })
        return

    check_payload = {
        'id': gs.settings.get('update_check_id'),
        'version': __version__,
        'events': {
            'total': Event.objects.count(),
            'live': Event.objects.filter(live=True).count(),
        },
        'plugins': [
            {
                'name': p.module,
                'version': p.version
            } for p in get_all_plugins()
        ]
    }
    try:
        r = requests.post('https://pretix.eu/.update_check/', json=check_payload)
        gs.settings.set('update_check_last', now())
        if r.status_code != 200:
            gs.settings.set('update_check_result', {
                'error': 'http_error'
            })
        else:
            rdata = r.json()
            update_available = rdata['version']['updatable'] or any(p['updatable'] for p in rdata['plugins'].values())
            gs.settings.set('update_check_result_warning', update_available)
            if update_available and rdata != gs.settings.update_check_result:
                send_update_notification_email()
            gs.settings.set('update_check_result', rdata)
    except requests.RequestException:
        gs.settings.set('update_check_last', now())
        gs.settings.set('update_check_result', {
            'error': 'unavailable'
        })
Beispiel #9
0
def update_check():
    gs = GlobalSettingsObject()

    if not gs.settings.update_check_id:
        gs.settings.set('update_check_id', uuid.uuid4().hex)

    if not gs.settings.update_check_perform:
        return

    if 'runserver' in sys.argv:
        gs.settings.set('update_check_last', now())
        gs.settings.set('update_check_result', {
            'error': 'development'
        })
        return

    check_payload = {
        'id': gs.settings.get('update_check_id'),
        'version': __version__,
        'events': {
            'total': Event.objects.count(),
            'live': Event.objects.filter(live=True).count(),
        },
        'plugins': [
            {
                'name': p.module,
                'version': p.version
            } for p in get_all_plugins()
        ]
    }
    try:
        r = requests.post('https://pretix.eu/.update_check/', json=check_payload)
        gs.settings.set('update_check_last', now())
        if r.status_code != 200:
            gs.settings.set('update_check_result', {
                'error': 'http_error'
            })
        else:
            rdata = r.json()
            update_available = rdata['version']['updatable'] or any(p['updatable'] for p in rdata['plugins'].values())
            gs.settings.set('update_check_result_warning', update_available)
            if update_available and rdata != gs.settings.update_check_result:
                send_update_notification_email()
            gs.settings.set('update_check_result', rdata)
    except requests.RequestException:
        gs.settings.set('update_check_last', now())
        gs.settings.set('update_check_result', {
            'error': 'unavailable'
        })
Beispiel #10
0
    def set_active_plugins(self, modules, allow_restricted=False):
        from pretix.base.plugins import get_all_plugins

        plugins_active = self.get_plugins()
        plugins_available = {
            p.module: p for p in get_all_plugins(self)
            if not p.name.startswith('.') and getattr(p, 'visible', True)
        }

        enable = [m for m in modules if m not in plugins_active and m in plugins_available]

        for module in enable:
            if getattr(plugins_available[module].app, 'restricted', False) and not allow_restricted:
                modules.remove(module)
            elif hasattr(plugins_available[module].app, 'installed'):
                getattr(plugins_available[module].app, 'installed')(self)

        self.plugins = ",".join(modules)
Beispiel #11
0
    def set_active_plugins(self, modules, allow_restricted=False):
        from pretix.base.plugins import get_all_plugins

        plugins_active = self.get_plugins()
        plugins_available = {
            p.module: p for p in get_all_plugins(self)
            if not p.name.startswith('.') and getattr(p, 'visible', True)
        }

        enable = [m for m in modules if m not in plugins_active and m in plugins_available]

        for module in enable:
            if getattr(plugins_available[module].app, 'restricted', False) and not allow_restricted:
                modules.remove(module)
            elif hasattr(plugins_available[module].app, 'installed'):
                getattr(plugins_available[module].app, 'installed')(self)

        self.plugins = ",".join(modules)
Beispiel #12
0
def check_result_table():
    gs = GlobalSettingsObject()
    res = gs.settings.update_check_result
    if not res:
        return {'error': 'no_result'}

    if 'error' in res:
        return res

    table = []
    table.append(('pretix', __version__, res['version']['latest'],
                  res['version']['updatable']))
    for p in get_all_plugins():
        if p.module in res['plugins']:
            pdata = res['plugins'][p.module]
            table.append((_('Plugin: %s') % p.name, p.version, pdata['latest'],
                          pdata['updatable']))
        else:
            table.append((_('Plugin: %s') % p.name, p.version, '?', False))

    return table
Beispiel #13
0
def check_result_table():
    gs = GlobalSettingsObject()
    res = gs.settings.update_check_result
    if not res:
        return {
            'error': 'no_result'
        }

    if 'error' in res:
        return res

    table = []
    table.append(('pretix', __version__, res['version']['latest'], res['version']['updatable']))
    for p in get_all_plugins():
        if p.module in res['plugins']:
            pdata = res['plugins'][p.module]
            table.append((_('Plugin: %s') % p.name, p.version, pdata['latest'], pdata['updatable']))
        else:
            table.append((_('Plugin: %s') % p.name, p.version, '?', False))

    return table
Beispiel #14
0
 def test_plugin_names(self):
     for mod in get_all_plugins():
         self.assertIn(mod.module, settings.INSTALLED_APPS)
Beispiel #15
0
 def test_metadata(self):
     for mod in get_all_plugins():
         self.assertTrue(hasattr(mod, 'name'))
         self.assertTrue(hasattr(mod, 'version'))
         self.assertTrue(hasattr(mod, 'type'))
Beispiel #16
0
 def test_plugin_names(self):
     for mod in get_all_plugins():
         self.assertIn(mod.module, settings.INSTALLED_APPS)
Beispiel #17
0
 def test_metadata(self):
     for mod in get_all_plugins():
         self.assertTrue(hasattr(mod, 'name'))
         self.assertTrue(hasattr(mod, 'version'))
         self.assertTrue(hasattr(mod, 'type'))
Beispiel #18
0
import pytest
from django.conf import settings
from django.test import TestCase
from django.utils.timezone import now

from pretix.base.models import Event, Organizer
from pretix.base.plugins import get_all_plugins
from pretix.base.signals import register_ticket_outputs

plugins = get_all_plugins()


@pytest.mark.django_db
@pytest.mark.parametrize("plugin", plugins)
def test_metadata(plugin):
    assert hasattr(plugin, 'name')
    assert hasattr(plugin, 'version')
    assert hasattr(plugin, 'type')


@pytest.mark.django_db
@pytest.mark.parametrize("plugin", plugins)
def test_plugin_installed(plugin):
    assert plugin.module in settings.INSTALLED_APPS


class PluginSignalTest(TestCase):
    """
    This test case tests the EventPluginSignal handler
    """
    @classmethod