From fecc5ec3074c50f52f9b8294df90231908fe7026 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Sun, 22 Jan 2017 18:15:31 +0100 Subject: [PATCH] Add support for restricted plugins --- doc/development/api/plugins.rst | 9 +++++++++ .../control/templates/pretixcontrol/event/plugins.html | 7 +++++++ src/pretix/control/views/event.py | 3 +++ 3 files changed, 19 insertions(+) diff --git a/doc/development/api/plugins.rst b/doc/development/api/plugins.rst index f64973e2bd..2bfb5b2b31 100644 --- a/doc/development/api/plugins.rst +++ b/doc/development/api/plugins.rst @@ -42,6 +42,13 @@ configuration class. The metadata class must define the following attributes: ``description`` (``str``): A more verbose description of what your plugin does. +``visible`` (``bool``): + ``True`` by default, can hide a plugin so it cannot be normally activated. + +``restricted`` (``bool``): + ``False`` by default, restricts a plugin such that it can only be enabled for an event + by system administrators / superusers. + A working example would be:: # file: pretix/plugins/timerestriction/__init__.py @@ -57,6 +64,8 @@ A working example would be:: name = _("PayPal") author = _("the pretix team") version = '1.0.0' + visible = True + restricted = False description = _("This plugin allows you to receive payments via PayPal") diff --git a/src/pretix/control/templates/pretixcontrol/event/plugins.html b/src/pretix/control/templates/pretixcontrol/event/plugins.html index 417381921f..7c175715de 100644 --- a/src/pretix/control/templates/pretixcontrol/event/plugins.html +++ b/src/pretix/control/templates/pretixcontrol/event/plugins.html @@ -23,6 +23,8 @@
{% if plugin.app.compatibility_errors %} + {% elif plugin.restricted and not request.user.is_superuser %} + {% elif plugin.module in plugins_active %} {% else %} @@ -42,6 +44,11 @@ {% endblocktrans %}

{% endif %}

{{ plugin.description }}

+ {% if plugin.restricted and not request.user.is_superuser %} +
+ {% trans "This plugin needs to be enabled by a system administrator for your event." %} +
+ {% endif %} {% if plugin.app.compatibility_errors %}
{% trans "This plugin cannot be enabled for the following reasons:" %} diff --git a/src/pretix/control/views/event.py b/src/pretix/control/views/event.py index cf3967f303..b30ae480a1 100644 --- a/src/pretix/control/views/event.py +++ b/src/pretix/control/views/event.py @@ -132,6 +132,9 @@ class EventPlugins(EventPermissionRequiredMixin, TemplateView, SingleObjectMixin if key.startswith("plugin:"): module = key.split(":")[1] if value == "enable" and module in plugins_available: + if getattr(plugins_available[module], 'restricted', False): + if not request.user.is_superuser: + continue self.request.event.log_action('pretix.event.plugins.enabled', user=self.request.user, data={'plugin': module}) if module not in plugins_active: