Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Fix 404 on /profile when the display name is empty but not the avatar (
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Velten committed Jul 27, 2023
1 parent a461f1f commit a719b70
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/16012.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix 404 not found code returned on profile endpoint when the display name is empty but not the avatar URL.
2 changes: 1 addition & 1 deletion synapse/handlers/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async def get_profile(self, user_id: str, ignore_backoff: bool = True) -> JsonDi

if self.hs.is_mine(target_user):
profileinfo = await self.store.get_profileinfo(target_user)
if profileinfo.display_name is None:
if profileinfo.display_name is None and profileinfo.avatar_url is None:
raise SynapseError(404, "Profile was not found", Codes.NOT_FOUND)

return {
Expand Down
10 changes: 10 additions & 0 deletions tests/handlers/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ def test_get_my_avatar(self) -> None:

self.assertEqual("http://my.server/me.png", avatar_url)

def test_get_profile_empty_displayname(self) -> None:
self.get_success(self.store.set_profile_displayname(self.frank, None))
self.get_success(
self.store.set_profile_avatar_url(self.frank, "http://my.server/me.png")
)

profile = self.get_success(self.handler.get_profile(self.frank.to_string()))

self.assertEqual("http://my.server/me.png", profile["avatar_url"])

def test_set_my_avatar(self) -> None:
self.get_success(
self.handler.set_avatar_url(
Expand Down

0 comments on commit a719b70

Please sign in to comment.