kopia lustrzana https://github.com/snarfed/bridgy-fed
Protocol.receive: send accepts for bot user follows
rodzic
1981c8eba8
commit
70da21a7f3
|
@ -829,10 +829,9 @@ class Protocol:
|
||||||
if obj.type == 'follow':
|
if obj.type == 'follow':
|
||||||
proto = Protocol.for_bridgy_subdomain(inner_obj_id)
|
proto = Protocol.for_bridgy_subdomain(inner_obj_id)
|
||||||
if proto:
|
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)
|
from_user.enable_protocol(proto)
|
||||||
# TODO: accept
|
|
||||||
return 'OK', 200
|
|
||||||
|
|
||||||
from_cls.handle_follow(obj)
|
from_cls.handle_follow(obj)
|
||||||
|
|
||||||
|
@ -927,7 +926,7 @@ class Protocol:
|
||||||
|
|
||||||
# send accept. note that this is one accept for the whole
|
# send accept. note that this is one accept for the whole
|
||||||
# follow, even if it has multiple followees!
|
# 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={
|
accept = Object.get_or_create(id, our_as1={
|
||||||
'id': id,
|
'id': id,
|
||||||
'objectType': 'activity',
|
'objectType': 'activity',
|
||||||
|
|
|
@ -230,7 +230,7 @@ ACCEPT_FOLLOW['object'] = 'http://localhost/user.com'
|
||||||
ACCEPT = {
|
ACCEPT = {
|
||||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||||
'type': 'Accept',
|
'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',
|
'actor': 'http://localhost/user.com',
|
||||||
'object': {
|
'object': {
|
||||||
'type': 'Follow',
|
'type': 'Follow',
|
||||||
|
@ -1096,7 +1096,7 @@ class ActivityPubTest(TestCase):
|
||||||
self.assert_equals(('http://mas.to/inbox',), args)
|
self.assert_equals(('http://mas.to/inbox',), args)
|
||||||
self.assert_equals({
|
self.assert_equals({
|
||||||
'type': 'Accept',
|
'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',
|
'actor': 'https://web.brid.gy/user.com',
|
||||||
'object': {
|
'object': {
|
||||||
'type': 'Follow',
|
'type': 'Follow',
|
||||||
|
|
|
@ -1375,7 +1375,7 @@ class ProtocolReceiveTest(TestCase):
|
||||||
delivered=['fake:user:target'],
|
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 = {
|
accept_as1 = {
|
||||||
'id': accept_id,
|
'id': accept_id,
|
||||||
'objectType': 'activity',
|
'objectType': 'activity',
|
||||||
|
@ -1597,9 +1597,8 @@ class ProtocolReceiveTest(TestCase):
|
||||||
self.assertEqual(('OK', 202), OtherFake.receive_as1(follow_as1))
|
self.assertEqual(('OK', 202), OtherFake.receive_as1(follow_as1))
|
||||||
|
|
||||||
self.assertEqual(1, len(OtherFake.sent))
|
self.assertEqual(1, len(OtherFake.sent))
|
||||||
self.assertEqual(
|
self.assertEqual('fake:alice/followers#accept-other:follow',
|
||||||
'https://fa.brid.gy/ap/fake:alice/followers#accept-other:follow',
|
OtherFake.sent[0][0])
|
||||||
OtherFake.sent[0][0])
|
|
||||||
|
|
||||||
self.assertEqual(1, len(Fake.sent))
|
self.assertEqual(1, len(Fake.sent))
|
||||||
self.assertEqual('other:follow', Fake.sent[0][0])
|
self.assertEqual('other:follow', Fake.sent[0][0])
|
||||||
|
@ -1778,7 +1777,7 @@ class ProtocolReceiveTest(TestCase):
|
||||||
}],
|
}],
|
||||||
}, obj.key.get().our_as1)
|
}, 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 = {
|
follow = {
|
||||||
'objectType': 'activity',
|
'objectType': 'activity',
|
||||||
'verb': 'follow',
|
'verb': 'follow',
|
||||||
|
@ -1803,14 +1802,20 @@ class ProtocolReceiveTest(TestCase):
|
||||||
self.assertEqual([], user.enabled_protocols)
|
self.assertEqual([], user.enabled_protocols)
|
||||||
|
|
||||||
# follow should add to 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()
|
user = user.key.get()
|
||||||
self.assertEqual(['fake'], user.enabled_protocols)
|
self.assertEqual(['fake'], user.enabled_protocols)
|
||||||
self.assertTrue(ExplicitEnableFake.is_enabled_to(Fake, user))
|
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
|
# another follow should be a noop
|
||||||
follow['id'] += '2'
|
follow['id'] += '2'
|
||||||
self.assertEqual(('OK', 200), ExplicitEnableFake.receive_as1(follow))
|
with self.assertRaises(NoContent):
|
||||||
|
ExplicitEnableFake.receive_as1(follow)
|
||||||
user = user.key.get()
|
user = user.key.get()
|
||||||
self.assertEqual(['fake'], user.enabled_protocols)
|
self.assertEqual(['fake'], user.enabled_protocols)
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue