Skip to content

Commit

Permalink
Merge branch 'develop' into issue-160
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoeejoee authored Aug 21, 2023
2 parents 317b64f + 39409d4 commit 9afbbef
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 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
19 changes: 7 additions & 12 deletions fiesta/apps/utils/templatetags/navigation.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 import Plugin
from apps.plugins.plugin import PluginAppConfig
from apps.sections.models import Section, SectionMembership

register = template.Library()
Expand All @@ -28,24 +29,18 @@ def get_navigation_items(context):
membership: SectionMembership | None = request.membership
section: Section | None = request.in_space_of_section

items = []

if not membership:
return items
return []

plugins: list[Plugin] = (
section.enabled_plugins_for_privileged if membership.is_privileged else section.enabled_plugins
)

items.extend(
[
nav_item
for plugin in plugins # type: Plugin
if (apps := plugin.app_config) and (nav_item := apps.as_navigation_item(request)) # type: PluginAppConfig
]
)

return items
for plugin in plugins:
apps: PluginAppConfig = plugin.app_config
item = apps.as_navigation_item(request=request, bound_plugin=plugin)
if item:
yield item


@register.simple_tag(takes_context=True)
Expand Down

0 comments on commit 9afbbef

Please sign in to comment.