User override in child class instead of if/else for privacy_filter

This commit is contained in:
Mouse Reeve 2021-10-06 11:08:54 -07:00
parent 97cc129478
commit 68b6b1fbae
2 changed files with 8 additions and 6 deletions

View file

@ -167,12 +167,7 @@ class BookWyrmModel(models.Model):
@classmethod
def direct_filter(cls, queryset, viewer):
"""Override-able filter for "direct" privacy level"""
try:
return queryset.exclude(
~Q(Q(user=viewer) | Q(mention_users=viewer)), privacy="direct"
)
except FieldError:
return queryset.exclude(~Q(user=viewer), privacy="direct")
return queryset.exclude(~Q(user=viewer), privacy="direct")
@receiver(models.signals.post_save)

View file

@ -207,6 +207,13 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
if isinstance(self, (GeneratedNote, ReviewRating)):
raise PermissionDenied()
@classmethod
def direct_filter(cls, queryset, viewer):
"""Override-able filter for "direct" privacy level"""
return queryset.exclude(
~Q(Q(user=viewer) | Q(mention_users=viewer)), privacy="direct"
)
class GeneratedNote(Status):
"""these are app-generated messages about user activity"""