Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promote account suspension to stable #17964

Merged
merged 4 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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/17964.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support stable account suspension from [MSC3823](https://github.com/matrix-org/matrix-spec-proposals/pull/3823).
5 changes: 3 additions & 2 deletions synapse/api/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,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.
Expand Down
4 changes: 0 additions & 4 deletions synapse/config/experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 1 addition & 2 deletions synapse/rest/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion tests/rest/admin/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
32 changes: 8 additions & 24 deletions tests/rest/client/test_rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"], "ORG.MATRIX.MSC3823.USER_ACCOUNT_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"], "ORG.MATRIX.MSC3823.USER_ACCOUNT_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
Expand All @@ -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"], "ORG.MATRIX.MSC3823.USER_ACCOUNT_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
Expand All @@ -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"], "ORG.MATRIX.MSC3823.USER_ACCOUNT_SUSPENDED"
)
self.assertEqual(channel.json_body["errcode"], "M_USER_SUSPENDED")


class RoomAppserviceTsParamTestCase(unittest.HomeserverTestCase):
Expand Down Expand Up @@ -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"], "ORG.MATRIX.MSC3823.USER_ACCOUNT_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
Expand All @@ -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"], "ORG.MATRIX.MSC3823.USER_ACCOUNT_SUSPENDED"
)
self.assertEqual(channel.json_body["errcode"], "M_USER_SUSPENDED")

channel2 = self.make_request(
"PUT",
Expand All @@ -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"], "ORG.MATRIX.MSC3823.USER_ACCOUNT_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
Expand Down Expand Up @@ -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"], "ORG.MATRIX.MSC3823.USER_ACCOUNT_SUSPENDED"
)
self.assertEqual(channel.json_body["errcode"], "M_USER_SUSPENDED")

# but can redact their own
channel = self.make_request(
Expand Down
Loading