From 9038e498d5248f6152732e7807bf0873c98d7237 Mon Sep 17 00:00:00 2001 From: Humberto Rocha Date: Thu, 22 Jun 2023 19:09:19 -0400 Subject: [PATCH] Fix identity metadata not properly propagating through AP (#589) --- api/views/accounts.py | 3 ++- tests/users/models/test_identity.py | 28 ++++++++++++++++++++++++++++ users/models/identity.py | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/api/views/accounts.py b/api/views/accounts.py index 14729c1..c6d83fe 100644 --- a/api/views/accounts.py +++ b/api/views/accounts.py @@ -11,7 +11,7 @@ from api import schemas from api.decorators import scope_required from api.pagination import MastodonPaginator, PaginatingApiResponse, PaginationResult from core.models import Config -from users.models import Identity +from users.models import Identity, IdentityStates from users.services import IdentityService from users.shortcuts import by_handle_or_404 @@ -70,6 +70,7 @@ def update_credentials( if header: service.set_image(header) identity.save() + identity.transition_perform(IdentityStates.edited) return schemas.Account.from_identity(identity, source=True) diff --git a/tests/users/models/test_identity.py b/tests/users/models/test_identity.py index 4bbea1a..fbda49f 100644 --- a/tests/users/models/test_identity.py +++ b/tests/users/models/test_identity.py @@ -240,3 +240,31 @@ async def test_fetch_webfinger_url(httpx_mock: HTTPXMock, config_system): await Identity.fetch_webfinger_url("example.com") == "https://example.com/.well-known/webfinger?resource={uri}" ) + + +@pytest.mark.django_db +def test_attachment_to_ap(identity: Identity, config_system): + """ + Tests identity attachment conversion to AP format. + """ + identity.metadata = [ + { + "type": "http://schema.org#PropertyValue", + "name": "Website", + "value": "http://example.com", + } + ] + + response = identity.to_ap() + + assert response["attachment"] + assert len(response["attachment"]) == 1 + + attachment = response["attachment"][0] + + assert attachment["type"] == "PropertyValue" + assert attachment["name"] == "Website" + assert attachment["value"] == ( + '' + 'example.com' + ) diff --git a/users/models/identity.py b/users/models/identity.py index 9f19305..69283c6 100644 --- a/users/models/identity.py +++ b/users/models/identity.py @@ -534,7 +534,7 @@ class Identity(StatorModel): if self.metadata: response["attachment"] = [ { - "type": "http://schema.org#PropertyValue", + "type": "PropertyValue", "name": FediverseHtmlParser(item["name"]).plain_text, "value": FediverseHtmlParser(item["value"]).html, }