kopia lustrzana https://gitlab.com/jaywink/federation
Fix Diaspora `Profile` mapping regarding `last_name` property
Previously only `first_name` was used when creating the `Profile.name` value. Now both `first_name` and `last_name` are used. When creating outgoing payloads, the `Profile.name` will still be placed in `first_name` to avoid trying to artificially split it.merge-requests/130/head
rodzic
690e8872d8
commit
bfb4792f16
|
@ -53,6 +53,12 @@
|
|||
* Allow port in Diaspora handles as per the protocol specification
|
||||
|
||||
Previously handles were validated like emails.
|
||||
|
||||
* Fix Diaspora `Profile` mapping regarding `last_name` property
|
||||
|
||||
Previously only `first_name` was used when creating the `Profile.name` value. Now both `first_name` and `last_name` are used.
|
||||
|
||||
When creating outgoing payloads, the `Profile.name` will still be placed in `first_name` to avoid trying to artificially split it.
|
||||
|
||||
## [0.15.0] - 2018-02-12
|
||||
|
||||
|
|
|
@ -221,7 +221,7 @@ class DiasporaProfile(DiasporaEntityMixin, Profile):
|
|||
struct_to_xml(element, [
|
||||
{"author": self.handle},
|
||||
{"first_name": self.name},
|
||||
{"last_name": ""}, # Not used in Diaspora modern profiles
|
||||
{"last_name": ""}, # We only have one field - splitting it would be artificial
|
||||
{"image_url": self.image_urls["large"]},
|
||||
{"image_url_small": self.image_urls["small"]},
|
||||
{"image_url_medium": self.image_urls["medium"]},
|
||||
|
|
|
@ -178,8 +178,10 @@ def transform_attributes(attrs, cls):
|
|||
transformed["target_handle"] = value
|
||||
elif key in ["parent_guid", "post_guid", "root_guid"]:
|
||||
transformed["target_guid"] = value
|
||||
elif key == "first_name":
|
||||
transformed["name"] = value
|
||||
elif key in ("first_name", "last_name"):
|
||||
values = [attrs.get('first_name'), attrs.get('last_name')]
|
||||
values = [v for v in values if v]
|
||||
transformed["name"] = " ".join(values)
|
||||
elif key == "image_url":
|
||||
if "image_urls" not in transformed:
|
||||
transformed["image_urls"] = {}
|
||||
|
|
|
@ -17,7 +17,8 @@ from federation.tests.fixtures.payloads import (
|
|||
DIASPORA_REQUEST, DIASPORA_PROFILE, DIASPORA_POST_INVALID, DIASPORA_RETRACTION,
|
||||
DIASPORA_POST_WITH_PHOTOS, DIASPORA_POST_LEGACY_TIMESTAMP, DIASPORA_POST_LEGACY, DIASPORA_CONTACT,
|
||||
DIASPORA_LEGACY_REQUEST_RETRACTION, DIASPORA_POST_WITH_PHOTOS_2, DIASPORA_PROFILE_EMPTY_TAGS, DIASPORA_RESHARE,
|
||||
DIASPORA_RESHARE_WITH_EXTRA_PROPERTIES, DIASPORA_RESHARE_LEGACY, DIASPORA_POST_SIMPLE_WITH_MENTION)
|
||||
DIASPORA_RESHARE_WITH_EXTRA_PROPERTIES, DIASPORA_RESHARE_LEGACY, DIASPORA_POST_SIMPLE_WITH_MENTION,
|
||||
DIASPORA_PROFILE_FIRST_NAME_ONLY)
|
||||
|
||||
|
||||
def mock_fill(attributes):
|
||||
|
@ -162,6 +163,13 @@ class TestDiasporaEntityMappersReceive:
|
|||
assert profile.nsfw == False
|
||||
assert profile.tag_list == ["socialfederation", "federation"]
|
||||
|
||||
@patch("federation.entities.diaspora.entities.DiasporaProfile.fill_extra_attributes", new=mock_fill)
|
||||
def test_message_to_objects_profile__first_name_only(self):
|
||||
entities = message_to_objects(DIASPORA_PROFILE_FIRST_NAME_ONLY, "bob@example.com")
|
||||
assert len(entities) == 1
|
||||
profile = entities[0]
|
||||
assert profile.name == "Bob"
|
||||
|
||||
@patch("federation.entities.diaspora.entities.DiasporaProfile.fill_extra_attributes", new=mock_fill)
|
||||
def test_message_to_objects_profile_survives_empty_tag_string(self):
|
||||
entities = message_to_objects(DIASPORA_PROFILE_EMPTY_TAGS, "bob@example.com")
|
||||
|
|
|
@ -188,7 +188,24 @@ DIASPORA_REQUEST = """
|
|||
DIASPORA_PROFILE = """
|
||||
<profile>
|
||||
<author>bob@example.com</author>
|
||||
<first_name>Bob Bobertson</first_name>
|
||||
<first_name>Bob</first_name>
|
||||
<last_name>Bobertson</last_name>
|
||||
<image_url>https://example.com/uploads/images/thumb_large_c833747578b5.jpg</image_url>
|
||||
<image_url_small>https://example.com/uploads/images/thumb_small_c8b147578b5.jpg</image_url_small>
|
||||
<image_url_medium>https://example.com/uploads/images/thumb_medium_c8b1aab04f3.jpg</image_url_medium>
|
||||
<gender></gender>
|
||||
<bio>A cool bio</bio>
|
||||
<location>Helsinki</location>
|
||||
<searchable>true</searchable>
|
||||
<nsfw>false</nsfw>
|
||||
<tag_string>#socialfederation #federation</tag_string>
|
||||
</profile>
|
||||
"""
|
||||
|
||||
DIASPORA_PROFILE_FIRST_NAME_ONLY = """
|
||||
<profile>
|
||||
<author>bob@example.com</author>
|
||||
<first_name>Bob</first_name>
|
||||
<last_name></last_name>
|
||||
<image_url>https://example.com/uploads/images/thumb_large_c833747578b5.jpg</image_url>
|
||||
<image_url_small>https://example.com/uploads/images/thumb_small_c8b147578b5.jpg</image_url_small>
|
||||
|
@ -205,8 +222,8 @@ DIASPORA_PROFILE = """
|
|||
DIASPORA_PROFILE_EMPTY_TAGS = """
|
||||
<profile>
|
||||
<author>bob@example.com</author>
|
||||
<first_name>Bob Bobertson</first_name>
|
||||
<last_name></last_name>
|
||||
<first_name>Bob</first_name>
|
||||
<last_name>Bobertson</last_name>
|
||||
<image_url>https://example.com/uploads/images/thumb_large_c833747578b5.jpg</image_url>
|
||||
<image_url_small>https://example.com/uploads/images/thumb_small_c8b147578b5.jpg</image_url_small>
|
||||
<image_url_medium>https://example.com/uploads/images/thumb_medium_c8b1aab04f3.jpg</image_url_medium>
|
||||
|
|
Ładowanie…
Reference in New Issue