kopia lustrzana https://github.com/snarfed/bridgy-fed
rodzic
0dbbbe167c
commit
95cbfba31c
|
@ -127,6 +127,7 @@ class User(StringIdModel, metaclass=ProtocolUserMeta):
|
|||
"""Override Model.get_by_id to follow the use_instead property."""
|
||||
user = cls._get_by_id(id)
|
||||
if user and user.use_instead:
|
||||
logger.info(f'{user.key} use_instead => {user.use_instead}')
|
||||
return user.use_instead.get()
|
||||
|
||||
return user
|
||||
|
|
|
@ -1038,6 +1038,42 @@ class WebTest(TestCase):
|
|||
self.assertEqual(('https://mas.to/inbox',), args)
|
||||
self.assert_equals(REPOST_AS2, json_loads(kwargs['data']))
|
||||
|
||||
def test_create_no_author(self, mock_get, mock_post):
|
||||
"""No mf2 author. We should default to the user's homepage."""
|
||||
mock_get.side_effect = [
|
||||
requests_response("""\
|
||||
<html>
|
||||
<body class="h-entry">
|
||||
<a class="u-repost-of p-name" href="https://mas.to/toot/id">reposted!</a>
|
||||
<a href="http://localhost/"></a>
|
||||
</body>
|
||||
</html>
|
||||
""", url='https://user.com/repost', content_type=CONTENT_TYPE_HTML),
|
||||
NOT_FEDIVERSE,
|
||||
TOOT_AS2,
|
||||
ACTOR,
|
||||
]
|
||||
mock_post.return_value = requests_response('abc xyz')
|
||||
|
||||
got = self.client.post('/_ah/queue/webmention', data={
|
||||
'source': 'https://user.com/repost',
|
||||
'target': 'https://fed.brid.gy/',
|
||||
})
|
||||
self.assertEqual(200, got.status_code)
|
||||
|
||||
repost_mf2 = copy.deepcopy(REPOST_MF2)
|
||||
repost_mf2['properties']['author'] = ['https://user.com/']
|
||||
self.assert_object('https://user.com/repost',
|
||||
users=[g.user.key],
|
||||
source_protocol='web',
|
||||
mf2=repost_mf2, # includes author https://user.com/
|
||||
type='share',
|
||||
labels=['activity', 'user'],
|
||||
notify=[ndb.Key('ActivityPub', 'https://mas.to/author')],
|
||||
delivered=['https://mas.to/inbox'],
|
||||
status='complete',
|
||||
)
|
||||
|
||||
def test_create_post(self, mock_get, mock_post):
|
||||
mock_get.side_effect = [NOTE, ACTOR]
|
||||
mock_post.return_value = requests_response('abc xyz')
|
||||
|
|
13
web.py
13
web.py
|
@ -514,6 +514,7 @@ def webmention_task():
|
|||
logger.info(f'webmention from {domain}')
|
||||
|
||||
g.user = Web.get_by_id(domain)
|
||||
logger.info(f'User: {g.user.key}')
|
||||
if not g.user:
|
||||
error(f'No user found for domain {domain}', status=304)
|
||||
|
||||
|
@ -544,13 +545,15 @@ def webmention_task():
|
|||
|
||||
if not obj or (not obj.mf2 and obj.type != 'delete'):
|
||||
error(f"Couldn't load {source} as microformats2 HTML", status=304)
|
||||
elif obj.mf2:
|
||||
elif obj.mf2 and 'h-entry' in obj.mf2.get('type', []):
|
||||
# default actor to user
|
||||
props = obj.mf2['properties']
|
||||
author_urls = microformats2.get_string_urls(props.get('author', []))
|
||||
if author_urls and not g.user.is_web_url(author_urls[0]):
|
||||
logger.info(f'Overriding author {author_urls[0]} with {g.user.ap_actor()}')
|
||||
props['author'] = [g.user.ap_actor()]
|
||||
for url in microformats2.get_string_urls(props.get('author', [])):
|
||||
if g.user.is_web_url(url):
|
||||
break
|
||||
else:
|
||||
logger.info(f'Adding {g.user.web_url()} as author')
|
||||
props.setdefault('author', []).append(g.user.web_url())
|
||||
|
||||
# if source is home page, update Web user and send an actor Update to
|
||||
# followers' instances
|
||||
|
|
Ładowanie…
Reference in New Issue