diff --git a/src/open_inwoner/cms/products/cms_plugins.py b/src/open_inwoner/cms/products/cms_plugins.py index 9b423f0aa1..a5d8686ee0 100644 --- a/src/open_inwoner/cms/products/cms_plugins.py +++ b/src/open_inwoner/cms/products/cms_plugins.py @@ -29,7 +29,10 @@ def render(self, context, instance, placeholder): # Highlighted categories highlighted_categories = ( - Category.objects.published().filter(highlighted=True).order_by("path") + Category.objects.published() + .visible_for_user(request.user) + .filter(highlighted=True) + .order_by("path") ) if request.user.is_authenticated and request.user.selected_categories.exists(): categories = request.user.selected_categories.order_by("name")[: self.limit] diff --git a/src/open_inwoner/pdc/managers.py b/src/open_inwoner/pdc/managers.py index 461225c257..d29937a5c7 100644 --- a/src/open_inwoner/pdc/managers.py +++ b/src/open_inwoner/pdc/managers.py @@ -3,6 +3,8 @@ from ordered_model.models import OrderedModelQuerySet from treebeard.mp_tree import MP_NodeQuerySet +from open_inwoner.accounts.models import User + class ProductQueryset(models.QuerySet): def published(self): @@ -22,6 +24,11 @@ def published(self): def draft(self): return self.filter(published=False) + def visible_for_user(self, user: User): + if user.is_authenticated: + return self.filter(visible_for_authenticated=True) + return self.filter(visible_for_anonymous=True) + class QuestionQueryset(OrderedModelQuerySet): def general(self): diff --git a/src/open_inwoner/pdc/views.py b/src/open_inwoner/pdc/views.py index a3992f6519..ef49cedae2 100644 --- a/src/open_inwoner/pdc/views.py +++ b/src/open_inwoner/pdc/views.py @@ -122,7 +122,7 @@ class CategoryListView( model = Category def get_queryset(self): - return Category.get_root_nodes().published() + return Category.get_root_nodes().published().visible_for_user(self.request.user) @cached_property def crumbs(self): diff --git a/src/open_inwoner/utils/context_processors.py b/src/open_inwoner/utils/context_processors.py index ffb0b8e4dd..fbafdf6d95 100644 --- a/src/open_inwoner/utils/context_processors.py +++ b/src/open_inwoner/utils/context_processors.py @@ -78,7 +78,9 @@ def settings(request): "cookie_link_text": config.cookie_link_text, "cookie_link_url": config.cookie_link_url, "extra_css": config.extra_css, - "menu_categories": Category.get_root_nodes().published(), + "menu_categories": ( + Category.get_root_nodes().published().visible_for_user(request.user) + ), # default SearchForm, might be overwritten by actual SearchView "search_form": SearchForm(auto_id=False), "search_filter_categories": config.search_filter_categories,