Make room alias lists peekable
As per https://github.com/matrix-org/matrix-doc/pull/2432#pullrequestreview-360566830, make room alias lists accessible to users outside world_readable rooms.
This commit is contained in:
parent
a0a1fd0bec
commit
709e81f518
|
@ -463,7 +463,9 @@ class DirectoryHandler(BaseHandler):
|
||||||
# allow access to server admins and current members of the room
|
# allow access to server admins and current members of the room
|
||||||
is_admin = await self.auth.is_server_admin(requester.user)
|
is_admin = await self.auth.is_server_admin(requester.user)
|
||||||
if not is_admin:
|
if not is_admin:
|
||||||
await self.auth.check_joined_room(room_id, requester.user.to_string())
|
await self.auth.check_user_in_room_or_world_readable(
|
||||||
|
room_id, requester.user.to_string()
|
||||||
|
)
|
||||||
|
|
||||||
aliases = await self.store.get_aliases_for_room(room_id)
|
aliases = await self.store.get_aliases_for_room(room_id)
|
||||||
return aliases
|
return aliases
|
||||||
|
|
|
@ -1766,6 +1766,23 @@ class DirectoryTestCase(unittest.HomeserverTestCase):
|
||||||
res = self._get_aliases(self.room_owner_tok)
|
res = self._get_aliases(self.room_owner_tok)
|
||||||
self.assertEqual(set(res["aliases"]), {alias1, alias2})
|
self.assertEqual(set(res["aliases"]), {alias1, alias2})
|
||||||
|
|
||||||
|
def test_peekable_room(self):
|
||||||
|
alias1 = self._random_alias()
|
||||||
|
self._set_alias_via_directory(alias1)
|
||||||
|
|
||||||
|
self.helper.send_state(
|
||||||
|
self.room_id,
|
||||||
|
EventTypes.RoomHistoryVisibility,
|
||||||
|
body={"history_visibility": "world_readable"},
|
||||||
|
tok=self.room_owner_tok,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.register_user("user", "test")
|
||||||
|
user_tok = self.login("user", "test")
|
||||||
|
|
||||||
|
res = self._get_aliases(user_tok)
|
||||||
|
self.assertEqual(res["aliases"], [alias1])
|
||||||
|
|
||||||
def _get_aliases(self, access_token: str, expected_code: int = 200) -> JsonDict:
|
def _get_aliases(self, access_token: str, expected_code: int = 200) -> JsonDict:
|
||||||
"""Calls the endpoint under test. returns the json response object."""
|
"""Calls the endpoint under test. returns the json response object."""
|
||||||
request, channel = self.make_request(
|
request, channel = self.make_request(
|
||||||
|
|
Loading…
Reference in New Issue