implement AP Delete of actors when their accounts are deleted

fixes #63
thib
Ryan Barrett 2020-02-29 20:28:53 -08:00
rodzic df6b0b58ba
commit 9784686b1c
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 32 dodań i 0 usunięć

Wyświetl plik

@ -23,6 +23,7 @@ SUPPORTED_TYPES = (
'Article',
'Audio',
'Create',
'Delete',
'Follow',
'Image',
'Like',
@ -128,6 +129,15 @@ class InboxHandler(common.Handler):
if type == 'Undo' and obj.get('type') == 'Follow':
# skip actor fetch below; we don't need it to undo a follow
return self.undo_follow(self.redirect_unwrap(activity))
elif type == 'Delete':
id = obj.get('id')
if isinstance(id, str):
# assume this is an actor
# https://github.com/snarfed/bridgy-fed/issues/63
for key in Follower.query().iter(keys_only=True):
if key.id().split(' ')[-1] == id:
key.delete()
return
# fetch actor if necessary so we have name, profile photo, etc
for elem in obj, activity:

Wyświetl plik

@ -130,6 +130,15 @@ UNDO_FOLLOW_WRAPPED = {
'object': FOLLOW_WRAPPED,
}
DELETE = {
'@context': 'https://www.w3.org/ns/activitystreams',
'id': 'https://mastodon.social/users/swentel#delete',
'type': 'Delete',
'actor': 'https://mastodon.social/users/swentel',
'object': 'https://mastodon.social/users/swentel',
}
@patch('requests.post')
@patch('requests.get')
@patch('requests.head')
@ -397,3 +406,16 @@ class ActivityPubTest(testutil.TestCase):
'object': 'http://snarfed.org/',
}).encode())
self.assertEqual(501, got.status_int)
def test_inbox_delete_actor(self, mock_head, mock_get, mock_post):
follower = Follower.get_or_create('realize.be', DELETE['actor'])
Follower.get_or_create('snarfed.org', DELETE['actor'])
# other unrelated follower
other = Follower.get_or_create('realize.be', 'https://mas.to/users/other')
self.assertEqual(3, Follower.query().count())
got = application.get_response('/realize.be/inbox', method='POST',
body=json_dumps(DELETE).encode())
self.assertEqual(200, got.status_int)
self.assertEqual([other], Follower.query().fetch())