Object.actor_link bug fix: handle actor/author objects with only id field

for #442
pull/671/head
Ryan Barrett 2023-10-11 11:51:46 -07:00
rodzic b1b2478b66
commit bd19cab870
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
3 zmienionych plików z 15 dodań i 8 usunięć

Wyświetl plik

@ -840,13 +840,15 @@ class Object(StringIdModel):
# outbound; show a nice link to the user # outbound; show a nice link to the user
return g.user.user_link() return g.user.user_link()
actor = {} actor = None
if self.as1: if self.as1:
actor = (util.get_first(self.as1, 'actor') actor = (as1.get_object(self.as1, 'actor')
or util.get_first(self.as1, 'author') or as1.get_object(self.as1, 'author'))
or {})
if isinstance(actor, str): if not actor:
return common.pretty_link(actor, attrs=attrs) return ''
elif set(actor.keys()) == {'id'}:
return common.pretty_link(actor['id'], attrs=attrs)
url = util.get_first(actor, 'url') or '' url = util.get_first(actor, 'url') or ''
name = actor.get('displayName') or actor.get('username') or '' name = actor.get('displayName') or actor.get('username') or ''

Wyświetl plik

@ -4,7 +4,7 @@
{% block subtabs %} {% block subtabs %}
<div class="row"> <div class="row">
Subscribe: Subscribe:
<a href="{{ g.user.user_page_path('feed') }}">HTML</a> <a href="{{ g.user.user_page_path('feed?format=html') }}">HTML</a>
&middot; <a href="{{ g.user.user_page_path('feed?format=atom') }}">Atom</a> &middot; <a href="{{ g.user.user_page_path('feed?format=atom') }}">Atom</a>
&middot; <a href="{{ g.user.user_page_path('feed?format=rss') }}">RSS</a> &middot; <a href="{{ g.user.user_page_path('feed?format=rss') }}">RSS</a>
</div> </div>

Wyświetl plik

@ -385,8 +385,9 @@ class ObjectTest(TestCase):
def test_actor_link(self): def test_actor_link(self):
for expected, as2 in ( for expected, as2 in (
('href="">', {}), ('', {}),
('href="http://foo">foo', {'actor': 'http://foo'}), ('href="http://foo">foo', {'actor': 'http://foo'}),
('href="http://foo">foo', {'actor': {'id': 'http://foo'}}),
('href="">Alice', {'actor': {'name': 'Alice'}}), ('href="">Alice', {'actor': {'name': 'Alice'}}),
('href="http://foo/">Alice', {'actor': { ('href="http://foo/">Alice', {'actor': {
'name': 'Alice', 'name': 'Alice',
@ -404,6 +405,10 @@ class ObjectTest(TestCase):
obj = Object(id='x', as2=as2) obj = Object(id='x', as2=as2)
self.assert_multiline_in(expected, obj.actor_link()) self.assert_multiline_in(expected, obj.actor_link())
self.assertEqual(
'<a class="h-card u-author" href="http://foo">foo</a>',
Object(id='x', our_as1={'actor': {'id': 'http://foo'}}).actor_link())
def test_actor_link_user(self): def test_actor_link_user(self):
g.user = Fake(id='fake:user', obj=Object(id='a', as2={"name": "Alice"})) g.user = Fake(id='fake:user', obj=Object(id='a', as2={"name": "Alice"}))
obj = Object(id='x', source_protocol='ui', users=[g.user.key]) obj = Object(id='x', source_protocol='ui', users=[g.user.key])