Handle incoming follow request cancellations
This commit is contained in:
parent
e2d394d894
commit
6490a55274
|
@ -69,7 +69,13 @@ class Undo(Verb):
|
||||||
model = None
|
model = None
|
||||||
if self.object.type == "Follow":
|
if self.object.type == "Follow":
|
||||||
model = apps.get_model("bookwyrm.UserFollows")
|
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 not obj:
|
||||||
# if we don't have the object, we can't undo it. happens a lot with boosts
|
# if we don't have the object, we can't undo it. happens a lot with boosts
|
||||||
return
|
return
|
||||||
|
|
|
@ -275,6 +275,37 @@ class Inbox(TestCase):
|
||||||
follow = models.UserFollows.objects.all()
|
follow = models.UserFollows.objects.all()
|
||||||
self.assertEqual(list(follow), [])
|
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):
|
def test_handle_unfollow(self):
|
||||||
""" remove a relationship """
|
""" remove a relationship """
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
|
|
Loading…
Reference in New Issue