Protocol.receive: send accepts for bot user follows

pull/968/head
Ryan Barrett 2024-04-19 13:16:48 -07:00
rodzic 1981c8eba8
commit 70da21a7f3
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
3 zmienionych plików z 17 dodań i 13 usunięć

Wyświetl plik

@ -829,10 +829,9 @@ class Protocol:
if obj.type == 'follow':
proto = Protocol.for_bridgy_subdomain(inner_obj_id)
if proto:
# follow of one of our protocol users; enable that protocol
# follow of one of our protocol users; enable that protocol.
# foll through so that we send an accept.
from_user.enable_protocol(proto)
# TODO: accept
return 'OK', 200
from_cls.handle_follow(obj)
@ -927,7 +926,7 @@ class Protocol:
# send accept. note that this is one accept for the whole
# follow, even if it has multiple followees!
id = followee.id_as('activitypub') + f'/followers#accept-{follow.key.id()}'
id = f'{followee.key.id()}/followers#accept-{follow.key.id()}'
accept = Object.get_or_create(id, our_as1={
'id': id,
'objectType': 'activity',

Wyświetl plik

@ -230,7 +230,7 @@ ACCEPT_FOLLOW['object'] = 'http://localhost/user.com'
ACCEPT = {
'@context': 'https://www.w3.org/ns/activitystreams',
'type': 'Accept',
'id': 'http://localhost/user.com/followers#accept-https://mas.to/6d1a',
'id': 'http://localhost/r/user.com/followers#accept-https://mas.to/6d1a',
'actor': 'http://localhost/user.com',
'object': {
'type': 'Follow',
@ -1096,7 +1096,7 @@ class ActivityPubTest(TestCase):
self.assert_equals(('http://mas.to/inbox',), args)
self.assert_equals({
'type': 'Accept',
'id': 'https://web.brid.gy/user.com/followers#accept-https://mas.to/6d1a',
'id': 'https://web.brid.gy/r/user.com/followers#accept-https://mas.to/6d1a',
'actor': 'https://web.brid.gy/user.com',
'object': {
'type': 'Follow',

Wyświetl plik

@ -1375,7 +1375,7 @@ class ProtocolReceiveTest(TestCase):
delivered=['fake:user:target'],
)
accept_id = 'https://fa.brid.gy/ap/fake:user/followers#accept-fake:follow'
accept_id = 'fake:user/followers#accept-fake:follow'
accept_as1 = {
'id': accept_id,
'objectType': 'activity',
@ -1597,9 +1597,8 @@ class ProtocolReceiveTest(TestCase):
self.assertEqual(('OK', 202), OtherFake.receive_as1(follow_as1))
self.assertEqual(1, len(OtherFake.sent))
self.assertEqual(
'https://fa.brid.gy/ap/fake:alice/followers#accept-other:follow',
OtherFake.sent[0][0])
self.assertEqual('fake:alice/followers#accept-other:follow',
OtherFake.sent[0][0])
self.assertEqual(1, len(Fake.sent))
self.assertEqual('other:follow', Fake.sent[0][0])
@ -1778,7 +1777,7 @@ class ProtocolReceiveTest(TestCase):
}],
}, obj.key.get().our_as1)
def test_follow_and_block_protocol_user_adds_and_removes_enabled_protocols(self):
def test_follow_and_block_protocol_user_sets_enabled_protocols(self):
follow = {
'objectType': 'activity',
'verb': 'follow',
@ -1803,14 +1802,20 @@ class ProtocolReceiveTest(TestCase):
self.assertEqual([], user.enabled_protocols)
# follow should add to enabled_protocols
self.assertEqual(('OK', 200), ExplicitEnableFake.receive_as1(follow))
with self.assertRaises(NoContent):
ExplicitEnableFake.receive_as1(follow)
user = user.key.get()
self.assertEqual(['fake'], user.enabled_protocols)
self.assertTrue(ExplicitEnableFake.is_enabled_to(Fake, user))
self.assertEqual([
('https://fa.brid.gy//followers#accept-eefake:follow',
'eefake:user:target'),
], ExplicitEnableFake.sent)
# another follow should be a noop
follow['id'] += '2'
self.assertEqual(('OK', 200), ExplicitEnableFake.receive_as1(follow))
with self.assertRaises(NoContent):
ExplicitEnableFake.receive_as1(follow)
user = user.key.get()
self.assertEqual(['fake'], user.enabled_protocols)