kopia lustrzana https://github.com/snarfed/bridgy-fed
User.handle_as: handle web users with custom usernames
bug fix for b255962
, fixes https://console.cloud.google.com/errors/detail/CPiAj72alvDYNQ;time=P30D?project=bridgy-federated
as2-actor-ids
rodzic
f6af56f1c4
commit
48f89cebc0
|
@ -322,8 +322,11 @@ class User(StringIdModel, metaclass=ProtocolUserMeta):
|
|||
if isinstance(to_proto, str):
|
||||
to_proto = PROTOCOLS[to_proto]
|
||||
|
||||
return ids.translate_handle(handle=self.handle, from_proto=self.__class__,
|
||||
to_proto=to_proto)
|
||||
# override web users to always use domain instead of custom username
|
||||
handle = self.key.id() if self.LABEL == 'web' else self.handle
|
||||
|
||||
return ids.translate_handle(handle=handle, from_proto=self.__class__,
|
||||
to_proto=to_proto)
|
||||
|
||||
def id_as(self, to_proto):
|
||||
"""Returns this user's id in a different protocol.
|
||||
|
|
|
@ -158,6 +158,14 @@ class UserTest(TestCase):
|
|||
self.assertEqual('fake:handle:user', user.handle_as('fake'))
|
||||
self.assertEqual('@fake:handle:user@fa.brid.gy', user.handle_as('ap'))
|
||||
|
||||
def test_handle_as_web_custom_username(self, *_):
|
||||
self.user.obj.our_as1 = {
|
||||
'objectType': 'person',
|
||||
'url': 'acct:alice@y.z',
|
||||
}
|
||||
self.assertEqual('alice', self.user.username())
|
||||
self.assertEqual('@y.z@web.brid.gy', self.user.handle_as('ap'))
|
||||
|
||||
@patch('requests.get', return_value=requests_response(DID_DOC))
|
||||
def test_ap_actor(self, mock_get):
|
||||
user = self.make_user('did:plc:abc', cls=ATProto)
|
||||
|
|
Ładowanie…
Reference in New Issue