forked from mirrors/bookwyrm
commit
d72d4eddfd
3 changed files with 59 additions and 3 deletions
|
@ -331,8 +331,15 @@ def remove_statuses_on_block(sender, instance, *args, **kwargs):
|
|||
@receiver(signals.post_delete, sender=models.UserBlocks)
|
||||
# pylint: disable=unused-argument
|
||||
def add_statuses_on_unblock(sender, instance, *args, **kwargs):
|
||||
"""remove statuses from all feeds on block"""
|
||||
public_streams = [v for (k, v) in streams.items() if k != "home"]
|
||||
"""add statuses back to all feeds on unblock"""
|
||||
# make sure there isn't a block in the other direction
|
||||
if models.UserBlocks.objects.filter(
|
||||
user_subject=instance.user_object,
|
||||
user_object=instance.user_subject,
|
||||
).exists():
|
||||
return
|
||||
|
||||
public_streams = [k for (k, v) in streams.items() if k != "home"]
|
||||
|
||||
# add statuses back to streams with statuses from anyone
|
||||
if instance.user_subject.local:
|
||||
|
|
|
@ -16,6 +16,9 @@ class ActivitystreamsSignals(TestCase):
|
|||
self.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
||||
)
|
||||
self.another_user = models.User.objects.create_user(
|
||||
"fish", "fish@fish.fish", "password", local=True, localname="fish"
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
|
@ -66,3 +69,49 @@ class ActivitystreamsSignals(TestCase):
|
|||
args = mock.call_args[0]
|
||||
self.assertEqual(args[0], "books")
|
||||
self.assertEqual(args[1], self.local_user.id)
|
||||
|
||||
def test_remove_statuses_on_block(self, _):
|
||||
"""don't show statuses from blocked users"""
|
||||
with patch("bookwyrm.activitystreams.remove_user_statuses_task.delay") as mock:
|
||||
models.UserBlocks.objects.create(
|
||||
user_subject=self.local_user,
|
||||
user_object=self.remote_user,
|
||||
)
|
||||
|
||||
args = mock.call_args[0]
|
||||
self.assertEqual(args[0], self.local_user.id)
|
||||
self.assertEqual(args[1], self.remote_user.id)
|
||||
|
||||
def test_add_statuses_on_unblock(self, _):
|
||||
"""re-add statuses on unblock"""
|
||||
with patch("bookwyrm.activitystreams.remove_user_statuses_task.delay"):
|
||||
block = models.UserBlocks.objects.create(
|
||||
user_subject=self.local_user,
|
||||
user_object=self.remote_user,
|
||||
)
|
||||
|
||||
with patch("bookwyrm.activitystreams.add_user_statuses_task.delay") as mock:
|
||||
block.delete()
|
||||
|
||||
args = mock.call_args[0]
|
||||
kwargs = mock.call_args.kwargs
|
||||
self.assertEqual(args[0], self.local_user.id)
|
||||
self.assertEqual(args[1], self.remote_user.id)
|
||||
self.assertEqual(kwargs["stream_list"], ["local", "books"])
|
||||
|
||||
def test_add_statuses_on_unblock_reciprocal_block(self, _):
|
||||
"""re-add statuses on unblock"""
|
||||
with patch("bookwyrm.activitystreams.remove_user_statuses_task.delay"):
|
||||
block = models.UserBlocks.objects.create(
|
||||
user_subject=self.local_user,
|
||||
user_object=self.remote_user,
|
||||
)
|
||||
block = models.UserBlocks.objects.create(
|
||||
user_subject=self.remote_user,
|
||||
user_object=self.local_user,
|
||||
)
|
||||
|
||||
with patch("bookwyrm.activitystreams.add_user_statuses_task.delay") as mock:
|
||||
block.delete()
|
||||
|
||||
self.assertEqual(mock.call_count, 0)
|
||||
|
|
|
@ -14,7 +14,7 @@ class Block(View):
|
|||
"""blocking users"""
|
||||
|
||||
def get(self, request):
|
||||
"""list of blocked users?"""
|
||||
"""list of blocked users"""
|
||||
return TemplateResponse(request, "preferences/blocks.html")
|
||||
|
||||
def post(self, request, user_id):
|
||||
|
|
Loading…
Reference in a new issue