Fix identity metadata not properly propagating through AP (#589)

This commit is contained in:
Humberto Rocha 2023-06-22 19:09:19 -04:00 committed by GitHub
parent bb8f589da7
commit 9038e498d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 2 deletions

View file

@ -11,7 +11,7 @@ from api import schemas
from api.decorators import scope_required from api.decorators import scope_required
from api.pagination import MastodonPaginator, PaginatingApiResponse, PaginationResult from api.pagination import MastodonPaginator, PaginatingApiResponse, PaginationResult
from core.models import Config from core.models import Config
from users.models import Identity from users.models import Identity, IdentityStates
from users.services import IdentityService from users.services import IdentityService
from users.shortcuts import by_handle_or_404 from users.shortcuts import by_handle_or_404
@ -70,6 +70,7 @@ def update_credentials(
if header: if header:
service.set_image(header) service.set_image(header)
identity.save() identity.save()
identity.transition_perform(IdentityStates.edited)
return schemas.Account.from_identity(identity, source=True) return schemas.Account.from_identity(identity, source=True)

View file

@ -240,3 +240,31 @@ async def test_fetch_webfinger_url(httpx_mock: HTTPXMock, config_system):
await Identity.fetch_webfinger_url("example.com") await Identity.fetch_webfinger_url("example.com")
== "https://example.com/.well-known/webfinger?resource={uri}" == "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"] == (
'<a href="http://example.com" rel="nofollow">'
'<span class="invisible">http://</span>example.com</a>'
)

View file

@ -534,7 +534,7 @@ class Identity(StatorModel):
if self.metadata: if self.metadata:
response["attachment"] = [ response["attachment"] = [
{ {
"type": "http://schema.org#PropertyValue", "type": "PropertyValue",
"name": FediverseHtmlParser(item["name"]).plain_text, "name": FediverseHtmlParser(item["name"]).plain_text,
"value": FediverseHtmlParser(item["value"]).html, "value": FediverseHtmlParser(item["value"]).html,
} }