From 7c7972872e1c2bd2311dc6ba0c4e9fe22583a4f2 Mon Sep 17 00:00:00 2001 From: Jonathan de Jong Date: Fri, 18 Feb 2022 18:18:10 +0100 Subject: [PATCH 1/4] rename shared_rooms to mutual_rooms --- synapse/rest/__init__.py | 4 +-- .../{shared_rooms.py => mutual_rooms.py} | 11 +++---- .../storage/databases/main/user_directory.py | 6 ++-- ...t_shared_rooms.py => test_mutual_rooms.py} | 30 +++++++++---------- 4 files changed, 26 insertions(+), 25 deletions(-) rename synapse/rest/client/{shared_rooms.py => mutual_rooms.py} (88%) rename tests/rest/client/{test_shared_rooms.py => test_mutual_rooms.py} (87%) diff --git a/synapse/rest/__init__.py b/synapse/rest/__init__.py index 762808a5717b..9ff5ded68773 100644 --- a/synapse/rest/__init__.py +++ b/synapse/rest/__init__.py @@ -49,7 +49,7 @@ room_keys, room_upgrade_rest_servlet, sendtodevice, - shared_rooms, + mutual_rooms, sync, tags, thirdparty, @@ -132,4 +132,4 @@ def register_servlets(client_resource: HttpServer, hs: "HomeServer") -> None: admin.register_servlets_for_client_rest_resource(hs, client_resource) # unstable - shared_rooms.register_servlets(hs, client_resource) + mutual_rooms.register_servlets(hs, client_resource) diff --git a/synapse/rest/client/shared_rooms.py b/synapse/rest/client/mutual_rooms.py similarity index 88% rename from synapse/rest/client/shared_rooms.py rename to synapse/rest/client/mutual_rooms.py index e669fa78902d..d3872a76c85c 100644 --- a/synapse/rest/client/shared_rooms.py +++ b/synapse/rest/client/mutual_rooms.py @@ -28,13 +28,13 @@ logger = logging.getLogger(__name__) -class UserSharedRoomsServlet(RestServlet): +class UserMutualRoomsServlet(RestServlet): """ - GET /uk.half-shot.msc2666/user/shared_rooms/{user_id} HTTP/1.1 + GET /uk.half-shot.msc2666/user/mutual_rooms/{user_id} HTTP/1.1 """ PATTERNS = client_patterns( - "/uk.half-shot.msc2666/user/shared_rooms/(?P[^/]*)", + "/uk.half-shot.msc2666/user/mutual_rooms/(?P[^/]*)", releases=(), # This is an unstable feature ) @@ -64,7 +64,8 @@ async def on_GET( msg="You cannot request a list of shared rooms with yourself", errcode=Codes.FORBIDDEN, ) - rooms = await self.store.get_shared_rooms_for_users( + + rooms = await self.store.get_mutual_rooms_for_users( requester.user.to_string(), user_id ) @@ -72,4 +73,4 @@ async def on_GET( def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None: - UserSharedRoomsServlet(hs).register(http_server) + UserMutualRoomsServlet(hs).register(http_server) diff --git a/synapse/storage/databases/main/user_directory.py b/synapse/storage/databases/main/user_directory.py index e7fddd24262a..38071f6d782d 100644 --- a/synapse/storage/databases/main/user_directory.py +++ b/synapse/storage/databases/main/user_directory.py @@ -718,7 +718,7 @@ async def get_user_dir_rooms_user_is_in(self, user_id: str) -> List[str]: users.update(rows) return list(users) - async def get_shared_rooms_for_users( + async def get_mutual_rooms_for_users( self, user_id: str, other_user_id: str ) -> Set[str]: """ @@ -732,7 +732,7 @@ async def get_shared_rooms_for_users( A set of room ID's that the users share. """ - def _get_shared_rooms_for_users_txn( + def _get_mutual_rooms_for_users_txn( txn: LoggingTransaction, ) -> List[Dict[str, str]]: txn.execute( @@ -756,7 +756,7 @@ def _get_shared_rooms_for_users_txn( return rows rows = await self.db_pool.runInteraction( - "get_shared_rooms_for_users", _get_shared_rooms_for_users_txn + "get_mutual_rooms_for_users", _get_mutual_rooms_for_users_txn ) return {row["room_id"] for row in rows} diff --git a/tests/rest/client/test_shared_rooms.py b/tests/rest/client/test_mutual_rooms.py similarity index 87% rename from tests/rest/client/test_shared_rooms.py rename to tests/rest/client/test_mutual_rooms.py index 3818b7b14bf3..f7166380ae66 100644 --- a/tests/rest/client/test_shared_rooms.py +++ b/tests/rest/client/test_mutual_rooms.py @@ -14,7 +14,7 @@ from twisted.test.proto_helpers import MemoryReactor import synapse.rest.admin -from synapse.rest.client import login, room, shared_rooms +from synapse.rest.client import login, room, mutual_rooms from synapse.server import HomeServer from synapse.util import Clock @@ -22,16 +22,16 @@ from tests.server import FakeChannel -class UserSharedRoomsTest(unittest.HomeserverTestCase): +class UserMutualRoomsTest(unittest.HomeserverTestCase): """ - Tests the UserSharedRoomsServlet. + Tests the UserMutualRoomsServlet. """ servlets = [ login.register_servlets, synapse.rest.admin.register_servlets_for_client_rest_resource, room.register_servlets, - shared_rooms.register_servlets, + mutual_rooms.register_servlets, ] def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer: @@ -43,10 +43,10 @@ def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None: self.store = hs.get_datastores().main self.handler = hs.get_user_directory_handler() - def _get_shared_rooms(self, token: str, other_user: str) -> FakeChannel: + def _get_mutual_rooms(self, token: str, other_user: str) -> FakeChannel: return self.make_request( "GET", - "/_matrix/client/unstable/uk.half-shot.msc2666/user/shared_rooms/%s" + "/_matrix/client/unstable/uk.half-shot.msc2666/user/mutual_rooms/%s" % other_user, access_token=token, ) @@ -56,14 +56,14 @@ def test_shared_room_list_public(self) -> None: A room should show up in the shared list of rooms between two users if it is public. """ - self._check_shared_rooms_with(room_one_is_public=True, room_two_is_public=True) + self._check_mutual_rooms_with(room_one_is_public=True, room_two_is_public=True) def test_shared_room_list_private(self) -> None: """ A room should show up in the shared list of rooms between two users if it is private. """ - self._check_shared_rooms_with( + self._check_mutual_rooms_with( room_one_is_public=False, room_two_is_public=False ) @@ -72,9 +72,9 @@ def test_shared_room_list_mixed(self) -> None: The shared room list between two users should contain both public and private rooms. """ - self._check_shared_rooms_with(room_one_is_public=True, room_two_is_public=False) + self._check_mutual_rooms_with(room_one_is_public=True, room_two_is_public=False) - def _check_shared_rooms_with( + def _check_mutual_rooms_with( self, room_one_is_public: bool, room_two_is_public: bool ) -> None: """Checks that shared public or private rooms between two users appear in @@ -94,7 +94,7 @@ def _check_shared_rooms_with( # Check shared rooms from user1's perspective. # We should see the one room in common - channel = self._get_shared_rooms(u1_token, u2) + channel = self._get_mutual_rooms(u1_token, u2) self.assertEqual(200, channel.code, channel.result) self.assertEqual(len(channel.json_body["joined"]), 1) self.assertEqual(channel.json_body["joined"][0], room_id_one) @@ -107,7 +107,7 @@ def _check_shared_rooms_with( self.helper.join(room_id_two, user=u2, tok=u2_token) # Check shared rooms again. We should now see both rooms. - channel = self._get_shared_rooms(u1_token, u2) + channel = self._get_mutual_rooms(u1_token, u2) self.assertEqual(200, channel.code, channel.result) self.assertEqual(len(channel.json_body["joined"]), 2) for room_id_id in channel.json_body["joined"]: @@ -128,7 +128,7 @@ def test_shared_room_list_after_leave(self) -> None: self.helper.join(room, user=u2, tok=u2_token) # Assert user directory is not empty - channel = self._get_shared_rooms(u1_token, u2) + channel = self._get_mutual_rooms(u1_token, u2) self.assertEqual(200, channel.code, channel.result) self.assertEqual(len(channel.json_body["joined"]), 1) self.assertEqual(channel.json_body["joined"][0], room) @@ -136,11 +136,11 @@ def test_shared_room_list_after_leave(self) -> None: self.helper.leave(room, user=u1, tok=u1_token) # Check user1's view of shared rooms with user2 - channel = self._get_shared_rooms(u1_token, u2) + channel = self._get_mutual_rooms(u1_token, u2) self.assertEqual(200, channel.code, channel.result) self.assertEqual(len(channel.json_body["joined"]), 0) # Check user2's view of shared rooms with user1 - channel = self._get_shared_rooms(u2_token, u1) + channel = self._get_mutual_rooms(u2_token, u1) self.assertEqual(200, channel.code, channel.result) self.assertEqual(len(channel.json_body["joined"]), 0) From b60637998d2662fb8cc85d0c2bc1dd022617adbc Mon Sep 17 00:00:00 2001 From: Jonathan de Jong Date: Fri, 18 Feb 2022 18:19:53 +0100 Subject: [PATCH 2/4] lint --- synapse/rest/__init__.py | 2 +- tests/rest/client/test_mutual_rooms.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/synapse/rest/__init__.py b/synapse/rest/__init__.py index 9ff5ded68773..57c4773edce6 100644 --- a/synapse/rest/__init__.py +++ b/synapse/rest/__init__.py @@ -32,6 +32,7 @@ knock, login as v1_login, logout, + mutual_rooms, notifications, openid, password_policy, @@ -49,7 +50,6 @@ room_keys, room_upgrade_rest_servlet, sendtodevice, - mutual_rooms, sync, tags, thirdparty, diff --git a/tests/rest/client/test_mutual_rooms.py b/tests/rest/client/test_mutual_rooms.py index f7166380ae66..7b7d283bb628 100644 --- a/tests/rest/client/test_mutual_rooms.py +++ b/tests/rest/client/test_mutual_rooms.py @@ -14,7 +14,7 @@ from twisted.test.proto_helpers import MemoryReactor import synapse.rest.admin -from synapse.rest.client import login, room, mutual_rooms +from synapse.rest.client import login, mutual_rooms, room from synapse.server import HomeServer from synapse.util import Clock From c668bd6a1d714b8eeef7edb4681c60156785e5d6 Mon Sep 17 00:00:00 2001 From: Jonathan de Jong Date: Fri, 18 Feb 2022 18:20:53 +0100 Subject: [PATCH 3/4] add news --- changelog.d/12036.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/12036.misc diff --git a/changelog.d/12036.misc b/changelog.d/12036.misc new file mode 100644 index 000000000000..159e3a64c046 --- /dev/null +++ b/changelog.d/12036.misc @@ -0,0 +1 @@ +Refactor `shared_rooms` to `mutual_rooms` (MSC2666), as per proposal changes. \ No newline at end of file From 3c8d0daa7a49e84b5c254311c8ffbce05112e4f2 Mon Sep 17 00:00:00 2001 From: Jonathan de Jong Date: Sun, 13 Mar 2022 22:19:58 +0100 Subject: [PATCH 4/4] Update changelog.d/12036.misc Co-authored-by: reivilibre --- changelog.d/12036.misc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/12036.misc b/changelog.d/12036.misc index 159e3a64c046..d2996730cc2c 100644 --- a/changelog.d/12036.misc +++ b/changelog.d/12036.misc @@ -1 +1 @@ -Refactor `shared_rooms` to `mutual_rooms` (MSC2666), as per proposal changes. \ No newline at end of file +Rename `shared_rooms` to `mutual_rooms` (MSC2666), as per proposal changes. \ No newline at end of file