AP users: switch ActivityPub.ap_address() to use as2.address()

for #512
circle-datastore-transactions
Ryan Barrett 2023-06-01 20:58:42 -07:00
rodzic 958f81ddd1
commit 17ed24b6f5
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
4 zmienionych plików z 20 dodań i 12 usunięć

Wyświetl plik

@ -60,10 +60,7 @@ class ActivityPub(User, Protocol):
def ap_address(self):
"""Returns this user's ActivityPub address, eg '@foo.com@foo.com'."""
if self.direct:
return f'@{self.username()}@{self.key.id()}'
else:
return f'@{self.key.id()}@{request.host}'
return as2.address(self.actor_as2) or as2.address(self.key.id())
def ap_actor(self, rest=None):
"""Returns this user's ActivityPub/AS2 actor id URL.

Wyświetl plik

@ -98,8 +98,8 @@ def followers_or_following(protocol, domain, collection):
for f in followers:
f.url = f.src if collection == 'followers' else f.dest
f.handle = re.sub(r'^https?://(.+)/(users/|@)(.+)$', r'@\3@\1', f.url)
person = f.to_as1()
f.handle = as2.address(as2.from_as1(person) or f.url) or f.url
if person and isinstance(person, dict):
f.name = person.get('name') or ''
f.picture = util.get_url(person, 'icon') or util.get_url(person, 'image')

Wyświetl plik

@ -1544,8 +1544,14 @@ class ActivityPubUtilsTest(TestCase):
ignore=['to'])
def test_ap_actor(self):
user = self.make_user('http://foo/actor', cls=ActivityPub)
self.assertEqual('http://foo/actor', user.ap_actor())
user = ActivityPub(actor_as2={**ACTOR, 'preferredUsername': 'me'})
self.assertEqual('@me@mas.to', user.ap_address())
user = ActivityPub(actor_as2=ACTOR)
self.assertEqual('@swentel@mas.to', user.ap_address())
user = ActivityPub(id='https://mas.to/users/alice')
self.assertEqual('@alice@mas.to', user.ap_address())
def test_ap_address(self):
user = self.make_user('http://foo/actor', cls=ActivityPub)

Wyświetl plik

@ -114,15 +114,20 @@ class PagesTest(TestCase):
def test_followers(self):
self.make_user('bar.com')
Follower.get_or_create('bar.com', 'https://no/stored/follow')
Follower.get_or_create('bar.com', 'https://masto/user',
last_follow=FOLLOW_WITH_ACTOR)
Follower.get_or_create('bar.com', 'https://no.stored/users/follow')
Follower.get_or_create('bar.com', 'https://masto/user', last_follow={
**FOLLOW_WITH_ACTOR,
'actor': {
**ACTOR,
'preferredUsername': 'me',
},
})
got = self.client.get('/web/bar.com/followers')
self.assert_equals(200, got.status_code)
body = got.get_data(as_text=True)
self.assertIn('no/stored/follow', body)
self.assertIn('masto/user', body)
self.assertIn('@follow@no.stored', body)
self.assertIn('@me@plus.google.com', body)
def test_followers_fake(self):
self.make_user('foo.com', cls=Fake)