Handle incoming follow request cancellations

This commit is contained in:
Mouse Reeve 2021-03-13 15:32:56 -08:00
parent e2d394d894
commit 6490a55274
2 changed files with 38 additions and 1 deletions

View file

@ -69,7 +69,13 @@ class Undo(Verb):
model = None
if self.object.type == "Follow":
model = apps.get_model("bookwyrm.UserFollows")
obj = self.object.to_model(model=model, save=False, allow_create=False)
obj = self.object.to_model(model=model, save=False, allow_create=False)
if not obj:
# this could be a folloq request not a follow proper
model = apps.get_model("bookwyrm.UserFollowRequest")
obj = self.object.to_model(model=model, save=False, allow_create=False)
else:
obj = self.object.to_model(model=model, save=False, allow_create=False)
if not obj:
# if we don't have the object, we can't undo it. happens a lot with boosts
return

View file

@ -275,6 +275,37 @@ class Inbox(TestCase):
follow = models.UserFollows.objects.all()
self.assertEqual(list(follow), [])
def test_handle_undo_follow_request(self):
""" the requester cancels a follow request """
self.local_user.manually_approves_followers = True
self.local_user.save(broadcast=False)
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
request = models.UserFollowRequest.objects.create(
user_subject=self.remote_user,
user_object=self.local_user
)
self.assertTrue(self.local_user.follower_requests.exists())
activity = {
"type": "Undo",
"id": "bleh",
"to": ["https://www.w3.org/ns/activitystreams#Public"],
"cc": ["https://example.com/user/mouse/followers"],
"actor": self.remote_user.remote_id,
"@context": "https://www.w3.org/ns/activitystreams",
"object": {
"@context": "https://www.w3.org/ns/activitystreams",
"id": request.remote_id,
"type": "Follow",
"actor": "https://example.com/users/rat",
"object": "https://example.com/user/mouse",
}
}
views.inbox.activity_task(activity)
self.assertFalse(self.local_user.follower_requests.exists())
def test_handle_unfollow(self):
""" remove a relationship """
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):