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

Commit

Permalink
Move MSC2432 stuff onto unstable prefix (#6948)
Browse files Browse the repository at this point in the history
it's not in the spec yet, so needs to be unstable. Also add a feature flag for it. Also add a test for admin users.
  • Loading branch information
richvdh authored Feb 19, 2020
1 parent abf1e5c commit 880aaac
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/6948.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implement `GET /_matrix/client/r0/rooms/{roomId}/aliases` endpoint as per [MSC2432](https://github.com/matrix-org/matrix-doc/pull/2432).
8 changes: 7 additions & 1 deletion synapse/rest/client/v1/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

""" This module contains REST servlets to do with rooms: /rooms/<paths> """
import logging
import re
from typing import List, Optional

from six.moves.urllib import parse as urlparse
Expand Down Expand Up @@ -848,7 +849,12 @@ async def on_PUT(self, request, room_id, user_id):


class RoomAliasListServlet(RestServlet):
PATTERNS = client_patterns("/rooms/(?P<room_id>[^/]*)/aliases", unstable=False)
PATTERNS = [
re.compile(
r"^/_matrix/client/unstable/org\.matrix\.msc2432"
r"/rooms/(?P<room_id>[^/]*)/aliases"
),
]

def __init__(self, hs: "synapse.server.HomeServer"):
super().__init__()
Expand Down
2 changes: 2 additions & 0 deletions synapse/rest/client/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def on_GET(self, request):
"org.matrix.label_based_filtering": True,
# Implements support for cross signing as described in MSC1756
"org.matrix.e2e_cross_signing": True,
# Implements additional endpoints as described in MSC2432
"org.matrix.msc2432": True,
},
},
)
Expand Down
16 changes: 13 additions & 3 deletions tests/rest/client/v1/test_rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1729,8 +1729,7 @@ def test_erased_sender(self):
self.assertEqual(events_after[1].get("content"), {}, events_after[1])


class DirectoryTestCase(unittest.HomeserverTestCase):

class RoomAliasListTestCase(unittest.HomeserverTestCase):
servlets = [
synapse.rest.admin.register_servlets_for_client_rest_resource,
directory.register_servlets,
Expand All @@ -1756,6 +1755,16 @@ def test_not_in_room(self):
res = self._get_aliases(user_tok, expected_code=403)
self.assertEqual(res["errcode"], "M_FORBIDDEN")

def test_admin_user(self):
alias1 = self._random_alias()
self._set_alias_via_directory(alias1)

self.register_user("user", "test", admin=True)
user_tok = self.login("user", "test")

res = self._get_aliases(user_tok)
self.assertEqual(res["aliases"], [alias1])

def test_with_aliases(self):
alias1 = self._random_alias()
alias2 = self._random_alias()
Expand All @@ -1770,7 +1779,8 @@ def _get_aliases(self, access_token: str, expected_code: int = 200) -> JsonDict:
"""Calls the endpoint under test. returns the json response object."""
request, channel = self.make_request(
"GET",
"/_matrix/client/r0/rooms/%s/aliases" % (self.room_id,),
"/_matrix/client/unstable/org.matrix.msc2432/rooms/%s/aliases"
% (self.room_id,),
access_token=access_token,
)
self.render(request)
Expand Down

0 comments on commit 880aaac

Please sign in to comment.