From 5b7f2007e8f30c080d25f378cd0062fe04e67114 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 17 Apr 2021 12:51:36 -0700 Subject: [PATCH] Broadcast user deletions --- bookwyrm/models/activitypub_mixin.py | 2 +- bookwyrm/models/user.py | 6 ++++++ bookwyrm/tests/views/inbox/test_inbox_delete.py | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/bookwyrm/models/activitypub_mixin.py b/bookwyrm/models/activitypub_mixin.py index c6ba249c..efdf9a47 100644 --- a/bookwyrm/models/activitypub_mixin.py +++ b/bookwyrm/models/activitypub_mixin.py @@ -241,7 +241,7 @@ class ObjectMixin(ActivitypubMixin): return # is this a deletion? - if hasattr(self, "deleted") and self.deleted: + if (hasattr(self, "deleted") and self.deleted) or hasattr(self, "is_active") and not self.is_active: activity = self.to_delete_activity(user) else: activity = self.to_update_activity(user) diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index 15ceb19b..d0a8a34f 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -283,6 +283,12 @@ class User(OrderedCollectionPageMixin, AbstractUser): editable=False, ).save(broadcast=False) + def delete(self, *args, **kwargs): + """ deactivate rather than delete a user """ + self.is_active = False + # skip the logic in this class's save() + super().save(*args, **kwargs) + @property def local_path(self): """ this model doesn't inherit bookwyrm model, so here we are """ diff --git a/bookwyrm/tests/views/inbox/test_inbox_delete.py b/bookwyrm/tests/views/inbox/test_inbox_delete.py index 51c59015..88ef288e 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_delete.py +++ b/bookwyrm/tests/views/inbox/test_inbox_delete.py @@ -116,7 +116,7 @@ class InboxActivities(TestCase): 'type': 'Delete', 'actor': 'https://example.com/users/test-user', 'to': ['https://www.w3.org/ns/activitystreams#Public'], - 'object': 'https://example.com/users/test-user', + 'object': self.remote_user.remote_id, } views.inbox.activity_task(activity)