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

Bugfix in joined_rooms admin API if user has no memberships #8643

Merged
merged 4 commits into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/8643.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug in joined_rooms admin API if user has no memberships.
dklimpel marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 4 additions & 3 deletions synapse/rest/admin/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,10 @@ async def on_GET(self, request, user_id):
if not self.is_mine(UserID.from_string(user_id)):
raise SynapseError(400, "Can only lookup local users")

room_ids = await self.store.get_rooms_for_user(user_id)
if not room_ids:
raise NotFoundError("User not found")
u = await self.store.get_user_by_id(user_id)
if u is None:
dklimpel marked this conversation as resolved.
Show resolved Hide resolved
raise NotFoundError("Unknown user")

room_ids = await self.store.get_rooms_for_user(user_id)
ret = {"joined_rooms": list(room_ids), "total": len(room_ids)}
return 200, ret
16 changes: 15 additions & 1 deletion tests/rest/admin/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,6 @@ class UserMembershipRestTestCase(unittest.HomeserverTestCase):
servlets = [
synapse.rest.admin.register_servlets,
login.register_servlets,
sync.register_servlets,
room.register_servlets,
]

Expand Down Expand Up @@ -1082,6 +1081,21 @@ def test_user_is_not_local(self):
self.assertEqual(400, channel.code, msg=channel.json_body)
self.assertEqual("Can only lookup local users", channel.json_body["error"])

def test_no_memberships(self):
"""
Tests that a normal lookup for rooms is successfully
if user has no memberships
"""
# Get rooms
request, channel = self.make_request(
"GET", self.url, access_token=self.admin_user_tok,
)
self.render(request)

self.assertEqual(200, channel.code, msg=channel.json_body)
self.assertEqual(0, channel.json_body["total"])
self.assertEqual(0, len(channel.json_body["joined_rooms"]))

def test_get_rooms(self):
"""
Tests that a normal lookup for rooms is successfully
Expand Down