overide filters for groups and group lists
- use more sensible query for displaying groups on user page - privacy_filter now allows group members to see followers_only and private lists and groups they would otherwise not see
This commit is contained in:
@ -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"""
|
||||
|
@ -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"""
|
||||
|
Reference in New Issue
Block a user