kopia lustrzana https://github.com/snarfed/bridgy-fed
ids.translate_user_id: follow use_instead
rodzic
6410d0ef1a
commit
cada99e407
7
ids.py
7
ids.py
|
@ -36,8 +36,13 @@ def translate_user_id(*, id, from_proto, to_proto):
|
|||
if from_proto == to_proto:
|
||||
return id
|
||||
|
||||
# follow use_instead
|
||||
user = from_proto.get_by_id(id)
|
||||
if user:
|
||||
id = user.key.id()
|
||||
|
||||
def copy_or_original():
|
||||
if user := from_proto.get_by_id(id):
|
||||
if user:
|
||||
if copy := user.get_copy(to_proto):
|
||||
return copy
|
||||
if orig := models.get_original(id):
|
||||
|
|
|
@ -58,6 +58,22 @@ class IdsTest(TestCase):
|
|||
self.assertIsNone(translate_user_id(
|
||||
id='did:plc:123', from_proto=ATProto, to_proto=proto))
|
||||
|
||||
def test_translate_user_id_use_instead(self):
|
||||
did = Target(uri='did:plc:123', protocol='atproto')
|
||||
user = self.make_user('user.com', cls=Web, copies=[did])
|
||||
self.make_user('www.user.com', cls=Web, use_instead=user.key)
|
||||
|
||||
for proto, expected in [
|
||||
(ATProto, 'did:plc:123'),
|
||||
(ActivityPub, 'http://localhost/user.com'),
|
||||
(Fake, 'fake:u:user.com'),
|
||||
]:
|
||||
with self.subTest(proto=proto.LABEL):
|
||||
self.assertEqual(expected, translate_user_id(
|
||||
id='www.user.com', from_proto=Web, to_proto=proto))
|
||||
self.assertEqual(expected, translate_user_id(
|
||||
id='https://www.user.com/', from_proto=Web, to_proto=proto))
|
||||
|
||||
def test_translate_handle(self):
|
||||
for from_, handle, to, expected in [
|
||||
# basic
|
||||
|
|
Ładowanie…
Reference in New Issue