diff --git a/bookwyrm/models/group.py b/bookwyrm/models/group.py index f1005d4c..89fb3a0e 100644 --- a/bookwyrm/models/group.py +++ b/bookwyrm/models/group.py @@ -19,6 +19,22 @@ class Group(BookWyrmModel): """don't want the user to be in there in this case""" return f"https://{DOMAIN}/group/{self.id}" + @classmethod + def followers_filter(cls, queryset, viewer): + """Override filter for "followers" privacy level to allow non-following group members to see the existence of groups and group lists""" + + return queryset.exclude( + ~Q( # user isn't following and it isn't their own status and they are not a group member + Q(user__followers=viewer) | Q(user=viewer) | Q(memberships__user=viewer) + ), + privacy="followers", # and the status of the group is followers only + ) + + @classmethod + def direct_filter(cls, queryset, viewer): + """Override filter for "direct" privacy level to allow group members to see the existence of groups and group lists""" + + return queryset.exclude(~Q(memberships__user=viewer), privacy="direct") class GroupMember(models.Model): """Users who are members of a group""" diff --git a/bookwyrm/models/list.py b/bookwyrm/models/list.py index 8a083b69..b0222cef 100644 --- a/bookwyrm/models/list.py +++ b/bookwyrm/models/list.py @@ -1,6 +1,7 @@ """ make a list of books!! """ from django.apps import apps from django.db import models +from django.db.models import Q from django.utils import timezone from bookwyrm import activitypub @@ -71,6 +72,22 @@ class List(OrderedCollectionMixin, BookWyrmModel): return super().raise_not_editable(viewer) + @classmethod + def followers_filter(cls, queryset, viewer): + """Override filter for "followers" privacy level to allow non-following group members to see the existence of group lists""" + + return queryset.exclude( + ~Q( # user isn't following and it isn't their own status and they are not a group member + Q(user__followers=viewer) | Q(user=viewer) | Q(group__memberships__user=viewer) + ), + privacy="followers", # and the status (of the list) is followers only + ) + + @classmethod + def direct_filter(cls, queryset, viewer): + """Override filter for "direct" privacy level to allow group members to see the existence of group lists""" + + return queryset.exclude(~Q(group__memberships__user=viewer), privacy="direct") class ListItem(CollectionItemMixin, BookWyrmModel): """ok""" diff --git a/bookwyrm/templates/groups/user_groups.html b/bookwyrm/templates/groups/user_groups.html index f68994dc..cc27ce42 100644 --- a/bookwyrm/templates/groups/user_groups.html +++ b/bookwyrm/templates/groups/user_groups.html @@ -3,8 +3,7 @@ {% load interaction %}