forked from mirrors/bookwyrm
Broadcast deletions
This commit is contained in:
parent
5b7f2007e8
commit
ebdbdc8790
4 changed files with 40 additions and 20 deletions
|
@ -241,7 +241,11 @@ class ObjectMixin(ActivitypubMixin):
|
||||||
return
|
return
|
||||||
|
|
||||||
# is this a deletion?
|
# is this a deletion?
|
||||||
if (hasattr(self, "deleted") and self.deleted) or hasattr(self, "is_active") and not self.is_active:
|
if (
|
||||||
|
(hasattr(self, "deleted") and self.deleted)
|
||||||
|
or hasattr(self, "is_active")
|
||||||
|
and not self.is_active
|
||||||
|
):
|
||||||
activity = self.to_delete_activity(user)
|
activity = self.to_delete_activity(user)
|
||||||
else:
|
else:
|
||||||
activity = self.to_update_activity(user)
|
activity = self.to_update_activity(user)
|
||||||
|
|
|
@ -289,6 +289,12 @@ class User(OrderedCollectionPageMixin, AbstractUser):
|
||||||
# skip the logic in this class's save()
|
# skip the logic in this class's save()
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
|
def to_activity(self, *args, **kwargs):
|
||||||
|
""" return a remote_id only if the user is inactive """
|
||||||
|
if not self.is_active:
|
||||||
|
return self.remote_id
|
||||||
|
return super().to_activity_dataclass(*args, **kwargs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def local_path(self):
|
def local_path(self):
|
||||||
""" this model doesn't inherit bookwyrm model, so here we are """
|
""" this model doesn't inherit bookwyrm model, so here we are """
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
""" testing models """
|
""" testing models """
|
||||||
|
import json
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
import responses
|
import responses
|
||||||
|
@ -152,3 +153,17 @@ class User(TestCase):
|
||||||
self.assertEqual(server.server_name, DOMAIN)
|
self.assertEqual(server.server_name, DOMAIN)
|
||||||
self.assertIsNone(server.application_type)
|
self.assertIsNone(server.application_type)
|
||||||
self.assertIsNone(server.application_version)
|
self.assertIsNone(server.application_version)
|
||||||
|
|
||||||
|
def test_delete_user(self):
|
||||||
|
""" deactivate a user """
|
||||||
|
self.assertTrue(self.user.is_active)
|
||||||
|
with patch(
|
||||||
|
"bookwyrm.models.activitypub_mixin.broadcast_task.delay"
|
||||||
|
) as broadcast_mock:
|
||||||
|
self.user.delete()
|
||||||
|
|
||||||
|
self.assertEqual(broadcast_mock.call_count, 1)
|
||||||
|
activity = json.loads(broadcast_mock.call_args[0][1])
|
||||||
|
self.assertEqual(activity["type"], "Delete")
|
||||||
|
self.assertEqual(activity["object"], self.user.remote_id)
|
||||||
|
self.assertFalse(self.user.is_active)
|
||||||
|
|
|
@ -107,34 +107,29 @@ class InboxActivities(TestCase):
|
||||||
|
|
||||||
def test_delete_user(self):
|
def test_delete_user(self):
|
||||||
""" delete a user """
|
""" delete a user """
|
||||||
self.assertTrue(
|
self.assertTrue(models.User.objects.get(username="rat@example.com").is_active)
|
||||||
models.User.objects.get(username="rat@example.com").is_active
|
|
||||||
)
|
|
||||||
activity = {
|
activity = {
|
||||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
"@context": "https://www.w3.org/ns/activitystreams",
|
||||||
'id': 'https://example.com/users/test-user#delete',
|
"id": "https://example.com/users/test-user#delete",
|
||||||
'type': 'Delete',
|
"type": "Delete",
|
||||||
'actor': 'https://example.com/users/test-user',
|
"actor": "https://example.com/users/test-user",
|
||||||
'to': ['https://www.w3.org/ns/activitystreams#Public'],
|
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
'object': self.remote_user.remote_id,
|
"object": self.remote_user.remote_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
views.inbox.activity_task(activity)
|
views.inbox.activity_task(activity)
|
||||||
self.assertFalse(
|
self.assertFalse(models.User.objects.get(username="rat@example.com").is_active)
|
||||||
models.User.objects.get(username="rat@example.com").is_active
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_delete_user_unknown(self):
|
def test_delete_user_unknown(self):
|
||||||
""" don't worry about it if we don't know the user """
|
""" don't worry about it if we don't know the user """
|
||||||
self.assertEqual(models.User.objects.filter(is_active=True).count(), 2)
|
self.assertEqual(models.User.objects.filter(is_active=True).count(), 2)
|
||||||
activity = {
|
activity = {
|
||||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
"@context": "https://www.w3.org/ns/activitystreams",
|
||||||
'id': 'https://example.com/users/test-user#delete',
|
"id": "https://example.com/users/test-user#delete",
|
||||||
'type': 'Delete',
|
"type": "Delete",
|
||||||
'actor': 'https://example.com/users/test-user',
|
"actor": "https://example.com/users/test-user",
|
||||||
'to': ['https://www.w3.org/ns/activitystreams#Public'],
|
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
'object': 'https://example.com/users/test-user',
|
"object": "https://example.com/users/test-user",
|
||||||
}
|
}
|
||||||
|
|
||||||
# nothing happens.
|
# nothing happens.
|
||||||
|
|
Loading…
Reference in a new issue