From da0a15a3ebb99334705854306ece2a71737291f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20Kol=C3=A1=C5=99?= Date: Sun, 17 Dec 2023 15:35:57 +0100 Subject: [PATCH] feat(plugins): display experimental plugins only to flagged sections --- fiesta/apps/pickup_system/apps.py | 1 - fiesta/apps/plugins/utils.py | 8 ++++++-- fiesta/apps/sections/views/plugins.py | 9 ++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/fiesta/apps/pickup_system/apps.py b/fiesta/apps/pickup_system/apps.py index 5e6b3b92..14aa69a0 100644 --- a/fiesta/apps/pickup_system/apps.py +++ b/fiesta/apps/pickup_system/apps.py @@ -19,7 +19,6 @@ class PickupSystemConfig(BasePluginAppConfig): verbose_name = _("Pickup System") emoji = "🤼" description = _("Tools for managing pickup of your students.") - feature_state = BasePluginAppConfig.FeatureState.EXPERIMENTAL order = 30 configuration_model = "pickup_system.PickupSystemConfiguration" diff --git a/fiesta/apps/plugins/utils.py b/fiesta/apps/plugins/utils.py index 9c596ab6..2c8a572d 100644 --- a/fiesta/apps/plugins/utils.py +++ b/fiesta/apps/plugins/utils.py @@ -9,13 +9,17 @@ @lru_cache -def all_plugin_apps() -> tuple[BasePluginAppConfig, ...]: +def all_plugin_apps(filter_f: callable = None) -> tuple[BasePluginAppConfig, ...]: """Returns all django app configs considered as PluginApps -- inheriting from PluginAppConfig.""" from django.apps import apps return tuple( sorted( - filter(lambda a: isinstance(a, BasePluginAppConfig), apps.get_app_configs()), key=attrgetter("verbose_name") + filter( + filter_f, + filter(lambda a: isinstance(a, BasePluginAppConfig), apps.get_app_configs()), + ), + key=attrgetter("verbose_name"), ) ) diff --git a/fiesta/apps/sections/views/plugins.py b/fiesta/apps/sections/views/plugins.py index da0b599a..b374f4ea 100644 --- a/fiesta/apps/sections/views/plugins.py +++ b/fiesta/apps/sections/views/plugins.py @@ -7,6 +7,7 @@ from apps.fiestaforms.views.htmx import HtmxFormViewMixin from apps.plugins.models import BasePluginConfiguration, Plugin +from apps.plugins.plugin import BasePluginAppConfig from apps.plugins.utils import all_plugin_apps from apps.sections.forms.plugin_configuration import get_plugin_configuration_form from apps.sections.forms.plugin_state import ChangePluginStateForm, SetupPluginSettingsForm @@ -27,6 +28,12 @@ def get_context_data(self, **kwargs): def by_label(label: str) -> Plugin | None: return self.request.in_space_of_section.plugins.filter(app_label=label).first() + def filter_app(app: BasePluginAppConfig) -> bool: + return ( + self.request.in_space_of_section.allow_experimental_plugins + or app.feature_state != BasePluginAppConfig.FeatureState.EXPERIMENTAL + ) + ctx = super().get_context_data(**kwargs) ctx.update( plugins=[ @@ -52,7 +59,7 @@ def by_label(label: str) -> Plugin | None: ) ), ) - for app in all_plugin_apps() + for app in all_plugin_apps(filter_f=filter_app) if (plugin := by_label(app.label)) or True ], PluginState=Plugin.State,