From fa0dfb74918911ef85a2fa2d2efd9649281deb43 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 26 Nov 2024 13:18:03 -0700 Subject: [PATCH 1/3] Promote account suspension to stable --- synapse/api/errors.py | 5 +++-- synapse/config/experimental.py | 4 ---- synapse/rest/admin/__init__.py | 3 +-- tests/rest/admin/test_user.py | 1 - tests/rest/client/test_rooms.py | 16 ++++++++-------- 5 files changed, 12 insertions(+), 17 deletions(-) diff --git a/synapse/api/errors.py b/synapse/api/errors.py index e6efa7a4249..4b6521b1227 100644 --- a/synapse/api/errors.py +++ b/synapse/api/errors.py @@ -101,8 +101,9 @@ class Codes(str, Enum): # The account has been suspended on the server. # By opposition to `USER_DEACTIVATED`, this is a reversible measure # that can possibly be appealed and reverted. - # Part of MSC3823. - USER_ACCOUNT_SUSPENDED = "ORG.MATRIX.MSC3823.USER_ACCOUNT_SUSPENDED" + # Introduced by MSC3823 + # https://github.com/matrix-org/matrix-spec-proposals/pull/3823 + USER_ACCOUNT_SUSPENDED = "M_USER_SUSPENDED" BAD_ALIAS = "M_BAD_ALIAS" # For restricted join rules. diff --git a/synapse/config/experimental.py b/synapse/config/experimental.py index 3411179a2a3..223118df2a5 100644 --- a/synapse/config/experimental.py +++ b/synapse/config/experimental.py @@ -436,10 +436,6 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None: ("experimental", "msc4108_delegation_endpoint"), ) - self.msc3823_account_suspension = experimental.get( - "msc3823_account_suspension", False - ) - # MSC4151: Report room API (Client-Server API) self.msc4151_enabled: bool = experimental.get("msc4151_enabled", False) diff --git a/synapse/rest/admin/__init__.py b/synapse/rest/admin/__init__.py index 4db89756747..c01282a43ef 100644 --- a/synapse/rest/admin/__init__.py +++ b/synapse/rest/admin/__init__.py @@ -332,8 +332,7 @@ def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None: BackgroundUpdateRestServlet(hs).register(http_server) BackgroundUpdateStartJobRestServlet(hs).register(http_server) ExperimentalFeaturesRestServlet(hs).register(http_server) - if hs.config.experimental.msc3823_account_suspension: - SuspendAccountRestServlet(hs).register(http_server) + SuspendAccountRestServlet(hs).register(http_server) def register_servlets_for_client_rest_resource( diff --git a/tests/rest/admin/test_user.py b/tests/rest/admin/test_user.py index fdb8fafa0e8..9a0e90208da 100644 --- a/tests/rest/admin/test_user.py +++ b/tests/rest/admin/test_user.py @@ -5031,7 +5031,6 @@ def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None: self.store = hs.get_datastores().main - @override_config({"experimental_features": {"msc3823_account_suspension": True}}) def test_suspend_user(self) -> None: # test that suspending user works channel = self.make_request( diff --git a/tests/rest/client/test_rooms.py b/tests/rest/client/test_rooms.py index 07600418ed8..85326c5e7fb 100644 --- a/tests/rest/client/test_rooms.py +++ b/tests/rest/client/test_rooms.py @@ -1338,7 +1338,7 @@ def test_suspended_user_cannot_join_room(self) -> None: ) self.assertEqual(channel.code, 403) self.assertEqual( - channel.json_body["errcode"], "ORG.MATRIX.MSC3823.USER_ACCOUNT_SUSPENDED" + channel.json_body["errcode"], "M_USER_SUSPENDED" ) channel = self.make_request( @@ -1346,7 +1346,7 @@ def test_suspended_user_cannot_join_room(self) -> None: ) self.assertEqual(channel.code, 403) self.assertEqual( - channel.json_body["errcode"], "ORG.MATRIX.MSC3823.USER_ACCOUNT_SUSPENDED" + channel.json_body["errcode"], "M_USER_SUSPENDED" ) def test_suspended_user_cannot_knock_on_room(self) -> None: @@ -1362,7 +1362,7 @@ def test_suspended_user_cannot_knock_on_room(self) -> None: ) self.assertEqual(channel.code, 403) self.assertEqual( - channel.json_body["errcode"], "ORG.MATRIX.MSC3823.USER_ACCOUNT_SUSPENDED" + channel.json_body["errcode"], "M_USER_SUSPENDED" ) def test_suspended_user_cannot_invite_to_room(self) -> None: @@ -1377,7 +1377,7 @@ def test_suspended_user_cannot_invite_to_room(self) -> None: content={"user_id": self.user2}, ) self.assertEqual( - channel.json_body["errcode"], "ORG.MATRIX.MSC3823.USER_ACCOUNT_SUSPENDED" + channel.json_body["errcode"], "M_USER_SUSPENDED" ) @@ -4012,7 +4012,7 @@ def test_suspended_user_cannot_send_message_to_room(self) -> None: content={"body": "hello", "msgtype": "m.text"}, ) self.assertEqual( - channel.json_body["errcode"], "ORG.MATRIX.MSC3823.USER_ACCOUNT_SUSPENDED" + channel.json_body["errcode"], "M_USER_SUSPENDED" ) def test_suspended_user_cannot_change_profile_data(self) -> None: @@ -4027,7 +4027,7 @@ def test_suspended_user_cannot_change_profile_data(self) -> None: shorthand=False, ) self.assertEqual( - channel.json_body["errcode"], "ORG.MATRIX.MSC3823.USER_ACCOUNT_SUSPENDED" + channel.json_body["errcode"], "M_USER_SUSPENDED" ) channel2 = self.make_request( @@ -4038,7 +4038,7 @@ def test_suspended_user_cannot_change_profile_data(self) -> None: shorthand=False, ) self.assertEqual( - channel2.json_body["errcode"], "ORG.MATRIX.MSC3823.USER_ACCOUNT_SUSPENDED" + channel2.json_body["errcode"], "M_USER_SUSPENDED" ) def test_suspended_user_cannot_redact_messages_other_than_their_own(self) -> None: @@ -4074,7 +4074,7 @@ def test_suspended_user_cannot_redact_messages_other_than_their_own(self) -> Non shorthand=False, ) self.assertEqual( - channel.json_body["errcode"], "ORG.MATRIX.MSC3823.USER_ACCOUNT_SUSPENDED" + channel.json_body["errcode"], "M_USER_SUSPENDED" ) # but can redact their own From c4227f1b4d429795d78030fafa4c7a43c975b350 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 26 Nov 2024 13:20:22 -0700 Subject: [PATCH 2/3] changelog --- changelog.d/17964.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/17964.feature diff --git a/changelog.d/17964.feature b/changelog.d/17964.feature new file mode 100644 index 00000000000..e2ae566eb98 --- /dev/null +++ b/changelog.d/17964.feature @@ -0,0 +1 @@ +Support stable account suspension from [MSC3823](https://github.com/matrix-org/matrix-spec-proposals/pull/3823). \ No newline at end of file From e6913a656c149655701e22f3ff20fd1aabcbce48 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 26 Nov 2024 13:29:16 -0700 Subject: [PATCH 3/3] appease the linter? --- tests/rest/client/test_rooms.py | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/tests/rest/client/test_rooms.py b/tests/rest/client/test_rooms.py index 85326c5e7fb..4cf1a3dc519 100644 --- a/tests/rest/client/test_rooms.py +++ b/tests/rest/client/test_rooms.py @@ -1337,17 +1337,13 @@ def test_suspended_user_cannot_join_room(self) -> None: "POST", f"/join/{self.room1}", access_token=self.tok2 ) self.assertEqual(channel.code, 403) - self.assertEqual( - channel.json_body["errcode"], "M_USER_SUSPENDED" - ) + self.assertEqual(channel.json_body["errcode"], "M_USER_SUSPENDED") channel = self.make_request( "POST", f"/rooms/{self.room1}/join", access_token=self.tok2 ) self.assertEqual(channel.code, 403) - self.assertEqual( - channel.json_body["errcode"], "M_USER_SUSPENDED" - ) + self.assertEqual(channel.json_body["errcode"], "M_USER_SUSPENDED") def test_suspended_user_cannot_knock_on_room(self) -> None: # set the user as suspended @@ -1361,9 +1357,7 @@ def test_suspended_user_cannot_knock_on_room(self) -> None: shorthand=False, ) self.assertEqual(channel.code, 403) - self.assertEqual( - channel.json_body["errcode"], "M_USER_SUSPENDED" - ) + self.assertEqual(channel.json_body["errcode"], "M_USER_SUSPENDED") def test_suspended_user_cannot_invite_to_room(self) -> None: # set the user as suspended @@ -1376,9 +1370,7 @@ def test_suspended_user_cannot_invite_to_room(self) -> None: access_token=self.tok1, content={"user_id": self.user2}, ) - self.assertEqual( - channel.json_body["errcode"], "M_USER_SUSPENDED" - ) + self.assertEqual(channel.json_body["errcode"], "M_USER_SUSPENDED") class RoomAppserviceTsParamTestCase(unittest.HomeserverTestCase): @@ -4011,9 +4003,7 @@ def test_suspended_user_cannot_send_message_to_room(self) -> None: access_token=self.tok1, content={"body": "hello", "msgtype": "m.text"}, ) - self.assertEqual( - channel.json_body["errcode"], "M_USER_SUSPENDED" - ) + self.assertEqual(channel.json_body["errcode"], "M_USER_SUSPENDED") def test_suspended_user_cannot_change_profile_data(self) -> None: # set the user as suspended @@ -4026,9 +4016,7 @@ def test_suspended_user_cannot_change_profile_data(self) -> None: content={"avatar_url": "mxc://matrix.org/wefh34uihSDRGhw34"}, shorthand=False, ) - self.assertEqual( - channel.json_body["errcode"], "M_USER_SUSPENDED" - ) + self.assertEqual(channel.json_body["errcode"], "M_USER_SUSPENDED") channel2 = self.make_request( "PUT", @@ -4037,9 +4025,7 @@ def test_suspended_user_cannot_change_profile_data(self) -> None: content={"displayname": "something offensive"}, shorthand=False, ) - self.assertEqual( - channel2.json_body["errcode"], "M_USER_SUSPENDED" - ) + self.assertEqual(channel2.json_body["errcode"], "M_USER_SUSPENDED") def test_suspended_user_cannot_redact_messages_other_than_their_own(self) -> None: # first user sends message @@ -4073,9 +4059,7 @@ def test_suspended_user_cannot_redact_messages_other_than_their_own(self) -> Non content={"reason": "bogus"}, shorthand=False, ) - self.assertEqual( - channel.json_body["errcode"], "M_USER_SUSPENDED" - ) + self.assertEqual(channel.json_body["errcode"], "M_USER_SUSPENDED") # but can redact their own channel = self.make_request(