Skip to content

Commit

Permalink
feat(plugins): pass bound plugin to as_navigation_spec()
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoeejoee committed Aug 17, 2023
1 parent de17871 commit caeeb38
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
5 changes: 3 additions & 2 deletions fiesta/apps/buddy_system/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

if typing.TYPE_CHECKING:
from apps.plugins.middleware.plugin import HttpRequest
from apps.plugins.models import Plugin


class BuddySystemConfig(PluginAppConfig):
Expand All @@ -26,8 +27,8 @@ class BuddySystemConfig(PluginAppConfig):

membership_not_required_urls = ("new-request",)

def as_navigation_item(self, request: HttpRequest) -> NavigationItemSpec | None:
base = super().as_navigation_item(request)
def as_navigation_item(self, request: HttpRequest, bound_plugin: Plugin) -> NavigationItemSpec | None:
base = super().as_navigation_item(request, bound_plugin)
if not request.membership.is_privileged:
return base

Expand Down
3 changes: 2 additions & 1 deletion fiesta/apps/dashboard/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

if typing.TYPE_CHECKING:
from apps.plugins.middleware.plugin import HttpRequest
from apps.plugins.models.plugin import Plugin


class DashboardConfig(PluginAppConfig):
Expand All @@ -18,7 +19,7 @@ class DashboardConfig(PluginAppConfig):

configuration_model = "dashboard.DashboardConfiguration"

def as_navigation_item(self, request: HttpRequest) -> NavigationItemSpec | None:
def as_navigation_item(self, request: HttpRequest, bound_plugin: Plugin) -> NavigationItemSpec | None:
# do not display in menu, since it's the home button link if the plugin is enabled
return None

Expand Down
5 changes: 3 additions & 2 deletions fiesta/apps/esncards/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

if typing.TYPE_CHECKING:
from apps.plugins.middleware.plugin import HttpRequest
from apps.plugins.models import Plugin


class ESNcardsConfig(PluginAppConfig):
Expand All @@ -20,8 +21,8 @@ class ESNcardsConfig(PluginAppConfig):

verbose_name = _("ESNcard")

def as_navigation_item(self, request: HttpRequest) -> NavigationItemSpec | None:
base = super().as_navigation_item(request)
def as_navigation_item(self, request: HttpRequest, bound_plugin: Plugin) -> NavigationItemSpec | None:
base = super().as_navigation_item(request, bound_plugin)
if not request.membership.is_privileged:
return base

Expand Down
3 changes: 2 additions & 1 deletion fiesta/apps/pages/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

if typing.TYPE_CHECKING:
from apps.plugins.middleware.plugin import HttpRequest
from apps.plugins.models.plugin import Plugin
from apps.utils.templatetags.navigation import NavigationItemSpec


Expand All @@ -25,7 +26,7 @@ class PagesConfig(PluginAppConfig):
def url_prefix(self) -> str:
return "_/"

def as_navigation_item(self, request: HttpRequest) -> NavigationItemSpec | None:
def as_navigation_item(self, request: HttpRequest, bound_plugin: Plugin) -> NavigationItemSpec | None:
return None


Expand Down
3 changes: 2 additions & 1 deletion fiesta/apps/plugins/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

if typing.TYPE_CHECKING:
from apps.plugins.middleware.plugin import HttpRequest
from apps.plugins.models.plugin import Plugin


class PluginAppConfig(AppConfig, metaclass=ABCMeta):
Expand Down Expand Up @@ -65,7 +66,7 @@ def url_prefix(self) -> str:
"""Defines prefix, under which are all urls included."""
return self.label.replace("_", "-") + "/"

def as_navigation_item(self, request: HttpRequest) -> NavigationItemSpec | None:
def as_navigation_item(self, request: HttpRequest, bound_plugin: Plugin) -> NavigationItemSpec | None:
return NavigationItemSpec(
self.verbose_name,
f"/{self.url_prefix}",
Expand Down
5 changes: 3 additions & 2 deletions fiesta/apps/sections/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

if typing.TYPE_CHECKING:
from apps.plugins.middleware.plugin import HttpRequest
from apps.plugins.models import Plugin


class SectionsConfig(PluginAppConfig):
Expand All @@ -24,11 +25,11 @@ class SectionsConfig(PluginAppConfig):
"choose-space",
]

def as_navigation_item(self, request: HttpRequest) -> NavigationItemSpec | None:
def as_navigation_item(self, request: HttpRequest, bound_plugin: Plugin) -> NavigationItemSpec | None:
if request.membership.is_privileged:
return (
super()
.as_navigation_item(request)
.as_navigation_item(request, bound_plugin)
._replace(
url="",
children=[
Expand Down

0 comments on commit caeeb38

Please sign in to comment.