Skip to content

Commit

Permalink
feat(plugins): display experimental plugins only to flagged sections
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoeejoee committed Dec 17, 2023
1 parent d2aea13 commit da0a15a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 0 additions & 1 deletion fiesta/apps/pickup_system/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 6 additions & 2 deletions fiesta/apps/plugins/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)
)

Expand Down
9 changes: 8 additions & 1 deletion fiesta/apps/sections/views/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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=[
Expand All @@ -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,
Expand Down

0 comments on commit da0a15a

Please sign in to comment.