From 0bfcea102b9e371d0cb5775e5679740a1b4fcdd6 Mon Sep 17 00:00:00 2001 From: Deimos Date: Tue, 11 Jul 2023 01:42:45 -0600 Subject: [PATCH] Fix groups with subgroups for logged-out viewers --- tildes/tildes/templates/topic_listing.jinja2 | 2 +- tildes/tildes/views/topic.py | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/tildes/tildes/templates/topic_listing.jinja2 b/tildes/tildes/templates/topic_listing.jinja2 index 8d17477..6e6461f 100644 --- a/tildes/tildes/templates/topic_listing.jinja2 +++ b/tildes/tildes/templates/topic_listing.jinja2 @@ -108,7 +108,7 @@ {% set is_single_group = False %} {% endif %} -{% if is_single_group and subgroups %} +{% if request.user and is_single_group and subgroups %}
{% if all_subgroups %} Includes topics from all subgroups. diff --git a/tildes/tildes/views/topic.py b/tildes/tildes/views/topic.py index 2b7233a..cba2c7f 100644 --- a/tildes/tildes/views/topic.py +++ b/tildes/tildes/views/topic.py @@ -178,14 +178,20 @@ def get_group_topics( # noqa group for group in request.query(Group).all() if group.path != "test" ] subgroups = None + include_subgroups = False else: # otherwise, just topics from the single group that we're looking at groups = [request.context] - groups.extend([ - sub.group for sub in request.user.subscriptions - if sub.group.is_subgroup_of(request.context) - ]) + if request.user: + groups.extend([ + sub.group for sub in request.user.subscriptions + if sub.group.is_subgroup_of(request.context) + ]) + + include_subgroups = all_subgroups + else: + include_subgroups = True subgroups = ( request.query(Group) @@ -214,9 +220,7 @@ def get_group_topics( # noqa query = ( request.query(Topic) .join_all_relationships() - .inside_groups( - groups, include_subgroups=not is_home_page and all_subgroups - ) + .inside_groups(groups, include_subgroups=include_subgroups) .exclude_ignored() .apply_sort_option(order) )