add User.profile_id, implement in ATProto

pull/646/head
Ryan Barrett 2023-09-22 15:40:22 -07:00
rodzic e257d43f21
commit 452e49134d
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
3 zmienionych plików z 23 dodań i 0 usunięć

Wyświetl plik

@ -109,6 +109,9 @@ class ATProto(User, Protocol):
return did.resolve_handle(handle, get_fn=util.requests_get)
def profile_id(self):
return f'at://{self.key.id()}/app.bsky.actor.profile/self'
@classmethod
def target_for(cls, obj, shared=False):
"""Returns the PDS URL for the given object, or None.

Wyświetl plik

@ -398,6 +398,22 @@ class User(StringIdModel, metaclass=ProtocolUserMeta):
"""
raise NotImplementedError()
def profile_id(self):
"""Returns the id of this user's profile object in its native protocol.
Examples:
* Web: home page URL, eg ``https://me.com/``
* ActivityPub: actor URL, eg ``https://instance.com/users/me``
* ATProto: profile AT URI, eg ``at://did:plc:123/app.bsky.actor.profile/self``
Defaults to this user's key id.
Returns:
str
"""
return self.key.id()
def user_page_path(self, rest=None):
"""Returns the user's Bridgy Fed user page path."""
path = f'/{self.ABBREV}/{self.readable_or_key_id()}'

Wyświetl plik

@ -238,6 +238,10 @@ class ATProtoTest(TestCase):
self.store_object(id='did:plc:foo', raw=DID_DOC)
self.assertEqual('@han.dull@atproto.brid.gy', user.ap_address())
def test_profile_id(self):
self.assertEqual('at://did:plc:foo/app.bsky.actor.profile/self',
self.make_user('did:plc:foo', cls=ATProto).profile_id())
@patch.object(tasks_client, 'create_task', return_value=Task(name='my task'))
@patch('requests.post',
return_value=requests_response('OK')) # create DID on PLC