forked from mirrors/bookwyrm
Removes get activity feed function
This commit is contained in:
parent
0caea7e9ff
commit
7eb494b4ab
8 changed files with 27 additions and 174 deletions
|
@ -66,8 +66,8 @@ class ActivityStream(ABC):
|
|||
|
||||
def stream_users(self, status): # pylint: disable=no-self-use
|
||||
""" given a status, what users should see it """
|
||||
# direct messages don't appeard in feeds.
|
||||
if status.privacy == "direct":
|
||||
# direct messages don't appeard in feeds, direct comments/reviews/etc do
|
||||
if status.privacy == "direct" and status.status_type == 'Note':
|
||||
return None
|
||||
|
||||
# everybody who could plausibly see this status
|
||||
|
|
|
@ -5,8 +5,6 @@ import re
|
|||
from django.apps import apps
|
||||
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||
from django.db import models
|
||||
from django.db.models import Q
|
||||
from django.dispatch import receiver
|
||||
from django.template.loader import get_template
|
||||
from django.utils import timezone
|
||||
from model_utils.managers import InheritanceManager
|
||||
|
|
|
@ -80,113 +80,6 @@ class ViewsHelpers(TestCase):
|
|||
request.headers = {"Accept": "Praise"}
|
||||
self.assertFalse(views.helpers.is_api_request(request))
|
||||
|
||||
def test_get_activity_feed(self):
|
||||
""" loads statuses """
|
||||
rat = models.User.objects.create_user(
|
||||
"rat", "rat@rat.rat", "password", local=True
|
||||
)
|
||||
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
public_status = models.Comment.objects.create(
|
||||
content="public status", book=self.book, user=self.local_user
|
||||
)
|
||||
direct_status = models.Status.objects.create(
|
||||
content="direct", user=self.local_user, privacy="direct"
|
||||
)
|
||||
|
||||
rat_public = models.Status.objects.create(content="blah blah", user=rat)
|
||||
rat_unlisted = models.Status.objects.create(
|
||||
content="blah blah", user=rat, privacy="unlisted"
|
||||
)
|
||||
remote_status = models.Status.objects.create(
|
||||
content="blah blah", user=self.remote_user
|
||||
)
|
||||
followers_status = models.Status.objects.create(
|
||||
content="blah", user=rat, privacy="followers"
|
||||
)
|
||||
rat_mention = models.Status.objects.create(
|
||||
content="blah blah blah", user=rat, privacy="followers"
|
||||
)
|
||||
rat_mention.mention_users.set([self.local_user])
|
||||
|
||||
statuses = views.helpers.get_activity_feed(
|
||||
self.local_user,
|
||||
privacy=["public", "unlisted", "followers"],
|
||||
following_only=True,
|
||||
queryset=models.Comment.objects,
|
||||
)
|
||||
self.assertEqual(len(statuses), 1)
|
||||
self.assertEqual(statuses[0], public_status)
|
||||
|
||||
statuses = views.helpers.get_activity_feed(
|
||||
self.local_user, privacy=["public", "followers"], local_only=True
|
||||
)
|
||||
self.assertEqual(len(statuses), 2)
|
||||
self.assertEqual(statuses[1], public_status)
|
||||
self.assertEqual(statuses[0], rat_public)
|
||||
|
||||
statuses = views.helpers.get_activity_feed(self.local_user, privacy=["direct"])
|
||||
self.assertEqual(len(statuses), 1)
|
||||
self.assertEqual(statuses[0], direct_status)
|
||||
|
||||
statuses = views.helpers.get_activity_feed(
|
||||
self.local_user,
|
||||
privacy=["public", "followers"],
|
||||
)
|
||||
self.assertEqual(len(statuses), 3)
|
||||
self.assertEqual(statuses[2], public_status)
|
||||
self.assertEqual(statuses[1], rat_public)
|
||||
self.assertEqual(statuses[0], remote_status)
|
||||
|
||||
statuses = views.helpers.get_activity_feed(
|
||||
self.local_user,
|
||||
privacy=["public", "unlisted", "followers"],
|
||||
following_only=True,
|
||||
)
|
||||
self.assertEqual(len(statuses), 2)
|
||||
self.assertEqual(statuses[1], public_status)
|
||||
self.assertEqual(statuses[0], rat_mention)
|
||||
|
||||
rat.followers.add(self.local_user)
|
||||
statuses = views.helpers.get_activity_feed(
|
||||
self.local_user,
|
||||
privacy=["public", "unlisted", "followers"],
|
||||
following_only=True,
|
||||
)
|
||||
self.assertEqual(len(statuses), 5)
|
||||
self.assertEqual(statuses[4], public_status)
|
||||
self.assertEqual(statuses[3], rat_public)
|
||||
self.assertEqual(statuses[2], rat_unlisted)
|
||||
self.assertEqual(statuses[1], followers_status)
|
||||
self.assertEqual(statuses[0], rat_mention)
|
||||
|
||||
def test_get_activity_feed_blocks(self):
|
||||
""" feed generation with blocked users """
|
||||
rat = models.User.objects.create_user(
|
||||
"rat", "rat@rat.rat", "password", local=True
|
||||
)
|
||||
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
public_status = models.Comment.objects.create(
|
||||
content="public status", book=self.book, user=self.local_user
|
||||
)
|
||||
rat_public = models.Status.objects.create(content="blah blah", user=rat)
|
||||
|
||||
statuses = views.helpers.get_activity_feed(
|
||||
self.local_user, privacy=["public"]
|
||||
)
|
||||
self.assertEqual(len(statuses), 2)
|
||||
|
||||
# block relationship
|
||||
rat.blocks.add(self.local_user)
|
||||
statuses = views.helpers.get_activity_feed(self.local_user, privacy=["public"])
|
||||
self.assertEqual(len(statuses), 1)
|
||||
self.assertEqual(statuses[0], public_status)
|
||||
|
||||
statuses = views.helpers.get_activity_feed(rat, privacy=["public"])
|
||||
self.assertEqual(len(statuses), 1)
|
||||
self.assertEqual(statuses[0], rat_public)
|
||||
|
||||
def test_is_bookwyrm_request(self):
|
||||
""" checks if a request came from a bookwyrm instance """
|
||||
request = self.factory.get("", {"q": "Test Book"})
|
||||
|
|
|
@ -19,8 +19,7 @@ from bookwyrm.activitypub import ActivitypubResponse
|
|||
from bookwyrm.connectors import connector_manager
|
||||
from bookwyrm.connectors.abstract_connector import get_image
|
||||
from bookwyrm.settings import PAGE_LENGTH
|
||||
from .helpers import is_api_request, get_activity_feed, get_edition
|
||||
from .helpers import privacy_filter
|
||||
from .helpers import is_api_request, get_edition, privacy_filter
|
||||
|
||||
|
||||
# pylint: disable= no-self-use
|
||||
|
@ -53,7 +52,7 @@ class Book(View):
|
|||
|
||||
# all reviews for the book
|
||||
reviews = models.Review.objects.filter(book__in=work.editions.all())
|
||||
reviews = get_activity_feed(request.user, queryset=reviews)
|
||||
reviews = privacy_filter(request.user, reviews)
|
||||
|
||||
# the reviews to show
|
||||
paginated = Paginator(
|
||||
|
|
|
@ -11,7 +11,7 @@ from django.views import View
|
|||
from bookwyrm import activitystreams, forms, models
|
||||
from bookwyrm.activitypub import ActivitypubResponse
|
||||
from bookwyrm.settings import PAGE_LENGTH, STREAMS
|
||||
from .helpers import get_activity_feed, get_user_from_username
|
||||
from .helpers import get_user_from_username, privacy_filter
|
||||
from .helpers import is_api_request, is_bookwyrm_request, object_visible_to_user
|
||||
|
||||
|
||||
|
@ -58,7 +58,13 @@ class DirectMessage(View):
|
|||
except ValueError:
|
||||
page = 1
|
||||
|
||||
queryset = models.Status.objects
|
||||
# remove fancy subclasses of status, keep just good ol' notes
|
||||
queryset = models.Status.objects.filter(
|
||||
review__isnull=True,
|
||||
comment__isnull=True,
|
||||
quotation__isnull=True,
|
||||
generatednote__isnull=True,
|
||||
)
|
||||
|
||||
user = None
|
||||
if username:
|
||||
|
@ -69,8 +75,8 @@ class DirectMessage(View):
|
|||
if user:
|
||||
queryset = queryset.filter(Q(user=user) | Q(mention_users=user))
|
||||
|
||||
activities = get_activity_feed(
|
||||
request.user, privacy=["direct"], queryset=queryset
|
||||
activities = privacy_filter(
|
||||
request.user, queryset, privacy_levels=["direct"]
|
||||
)
|
||||
|
||||
paginated = Paginator(activities, PAGE_LENGTH)
|
||||
|
|
|
@ -59,6 +59,11 @@ def object_visible_to_user(viewer, obj):
|
|||
def privacy_filter(viewer, queryset, privacy_levels=None, following_only=False):
|
||||
""" filter objects that have "user" and "privacy" fields """
|
||||
privacy_levels = privacy_levels or ["public", "unlisted", "followers", "direct"]
|
||||
# if there'd a deleted field, exclude deleted items
|
||||
try:
|
||||
queryset = queryset.filter(deleted=False)
|
||||
except FieldError:
|
||||
pass
|
||||
|
||||
# exclude blocks from both directions
|
||||
if not viewer.is_anonymous:
|
||||
|
@ -102,54 +107,6 @@ def privacy_filter(viewer, queryset, privacy_levels=None, following_only=False):
|
|||
return queryset
|
||||
|
||||
|
||||
def get_activity_feed(
|
||||
user, privacy=None, local_only=False, following_only=False, queryset=None
|
||||
):
|
||||
""" get a filtered queryset of statuses """
|
||||
if queryset is None:
|
||||
queryset = models.Status.objects.select_subclasses()
|
||||
|
||||
# exclude deleted
|
||||
queryset = queryset.exclude(deleted=True).order_by("-published_date")
|
||||
|
||||
# apply privacy filters
|
||||
queryset = privacy_filter(user, queryset, privacy, following_only=following_only)
|
||||
|
||||
# only show dms if we only want dms
|
||||
if privacy == ["direct"]:
|
||||
# dms are direct statuses not related to books
|
||||
queryset = queryset.filter(
|
||||
review__isnull=True,
|
||||
comment__isnull=True,
|
||||
quotation__isnull=True,
|
||||
generatednote__isnull=True,
|
||||
)
|
||||
else:
|
||||
try:
|
||||
queryset = queryset.exclude(
|
||||
review__isnull=True,
|
||||
comment__isnull=True,
|
||||
quotation__isnull=True,
|
||||
generatednote__isnull=True,
|
||||
privacy="direct",
|
||||
)
|
||||
except FieldError:
|
||||
# if we're looking at a subtype of Status (like Review)
|
||||
pass
|
||||
|
||||
# filter for only local status
|
||||
if local_only:
|
||||
queryset = queryset.filter(user__local=True)
|
||||
|
||||
# remove statuses that have boosts in the same queryset
|
||||
try:
|
||||
queryset = queryset.filter(~Q(boosters__in=queryset))
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
return queryset
|
||||
|
||||
|
||||
def handle_remote_webfinger(query):
|
||||
""" webfingerin' other servers """
|
||||
user = None
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
""" serialize user's posts in rss feed """
|
||||
|
||||
from django.contrib.syndication.views import Feed
|
||||
from .helpers import get_activity_feed, get_user_from_username
|
||||
from .helpers import get_user_from_username, privacy_filter
|
||||
|
||||
# pylint: disable=no-self-use, unused-argument
|
||||
class RssFeed(Feed):
|
||||
|
@ -24,10 +24,10 @@ class RssFeed(Feed):
|
|||
|
||||
def items(self, obj):
|
||||
""" the user's activity feed """
|
||||
return get_activity_feed(
|
||||
return privacy_filter(
|
||||
obj,
|
||||
privacy=["public", "unlisted"],
|
||||
queryset=obj.status_set.select_subclasses(),
|
||||
obj.status_set.select_subclasses(),
|
||||
privacy_levels=["public", "unlisted"],
|
||||
)
|
||||
|
||||
def item_link(self, item):
|
||||
|
|
|
@ -16,8 +16,8 @@ from django.views import View
|
|||
from bookwyrm import forms, models
|
||||
from bookwyrm.activitypub import ActivitypubResponse
|
||||
from bookwyrm.settings import PAGE_LENGTH
|
||||
from .helpers import get_activity_feed, get_user_from_username, is_api_request
|
||||
from .helpers import is_blocked, object_visible_to_user
|
||||
from .helpers import get_user_from_username, is_api_request
|
||||
from .helpers import is_blocked, privacy_filter, object_visible_to_user
|
||||
|
||||
|
||||
# pylint: disable= no-self-use
|
||||
|
@ -72,9 +72,9 @@ class User(View):
|
|||
break
|
||||
|
||||
# user's posts
|
||||
activities = get_activity_feed(
|
||||
activities = privacy_filter(
|
||||
request.user,
|
||||
queryset=user.status_set.select_subclasses(),
|
||||
user.status_set.select_subclasses(),
|
||||
)
|
||||
paginated = Paginator(activities, PAGE_LENGTH)
|
||||
goal = models.AnnualGoal.objects.filter(
|
||||
|
|
Loading…
Reference in a new issue