diff --git a/bookwyrm/models/activitypub_mixin.py b/bookwyrm/models/activitypub_mixin.py index f287b752..3e9e1940 100644 --- a/bookwyrm/models/activitypub_mixin.py +++ b/bookwyrm/models/activitypub_mixin.py @@ -369,6 +369,16 @@ class OrderedCollectionMixin(OrderedCollectionPageMixin): if self.user.local and broadcast: self.broadcast(activity, self.user) + def to_delete_activity(self, user): + """notice of deletion""" + return activitypub.Delete( + id=self.remote_id + "/activity", + actor=user.remote_id, + to=["%s/followers" % user.remote_id], + cc=["https://www.w3.org/ns/activitystreams#Public"], + object=self.remote_id, + ).serialize() + class CollectionItemMixin(ActivitypubMixin): """for items that are part of an (Ordered)Collection""" diff --git a/bookwyrm/tests/views/inbox/test_inbox_delete.py b/bookwyrm/tests/views/inbox/test_inbox_delete.py index 1566c05a..fef5ce51 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_delete.py +++ b/bookwyrm/tests/views/inbox/test_inbox_delete.py @@ -40,14 +40,6 @@ class InboxActivities(TestCase): remote_id="https://example.com/status/1", ) - self.create_json = { - "id": "hi", - "type": "Create", - "actor": "hi", - "to": ["https://www.w3.org/ns/activitystreams#public"], - "cc": ["https://example.com/user/mouse/followers"], - "object": {}, - } models.SiteSettings.objects.create() def test_delete_status(self): @@ -137,3 +129,20 @@ class InboxActivities(TestCase): # nothing happens. views.inbox.activity_task(activity) self.assertEqual(models.User.objects.filter(is_active=True).count(), 2) + + def test_delete_list(self): + """delete a list""" + book_list = models.List.objects.create( + name="test list", + user=self.remote_user, + ) + activity = { + "@context": "https://www.w3.org/ns/activitystreams", + "id": "https://example.com/users/test-user#delete", + "type": "Delete", + "actor": "https://example.com/users/test-user", + "to": ["https://www.w3.org/ns/activitystreams#Public"], + "object": book_list.remote_id, + } + views.inbox.activity_task(activity) + self.assertFalse(models.List.objects.exists()) diff --git a/bookwyrm/tests/views/test_list_actions.py b/bookwyrm/tests/views/test_list_actions.py index 710d83de..e268905d 100644 --- a/bookwyrm/tests/views/test_list_actions.py +++ b/bookwyrm/tests/views/test_list_actions.py @@ -87,6 +87,11 @@ class ListActionViews(TestCase): request.user = self.local_user with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: views.delete_list(request, self.list.id) + activity = json.loads(mock.call_args[0][1]) + self.assertEqual(activity["type"], "Delete") + self.assertEqual(activity["actor"], self.local_user.remote_id) + self.assertEqual(activity["object"], self.list.remote_id) + self.assertEqual(mock.call_count, 1) self.assertFalse(models.List.objects.exists()) self.assertFalse(models.ListItem.objects.exists())