mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-15 01:23:51 +01:00
Add an option to disable purge in delete room admin API (#7964)
Add option ```purge``` to ```POST /_synapse/admin/v1/rooms/<room_id>/delete``` Fixes: #3761 Signed-off-by: Dirk Klimpel dirk@klimpel.org
This commit is contained in:
parent
8a25332d94
commit
e866e3b896
4 changed files with 75 additions and 7 deletions
1
changelog.d/7964.feature
Normal file
1
changelog.d/7964.feature
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Add an option to purge room or not with delete room admin endpoint (`POST /_synapse/admin/v1/rooms/<room_id>/delete`). Contributed by @dklimpel.
|
|
@ -369,7 +369,9 @@ to the new room will have power level `-10` by default, and thus be unable to sp
|
||||||
If `block` is `True` it prevents new joins to the old room.
|
If `block` is `True` it prevents new joins to the old room.
|
||||||
|
|
||||||
This API will remove all trace of the old room from your database after removing
|
This API will remove all trace of the old room from your database after removing
|
||||||
all local users.
|
all local users. If `purge` is `true` (the default), all traces of the old room will
|
||||||
|
be removed from your database after removing all local users. If you do not want
|
||||||
|
this to happen, set `purge` to `false`.
|
||||||
Depending on the amount of history being purged a call to the API may take
|
Depending on the amount of history being purged a call to the API may take
|
||||||
several minutes or longer.
|
several minutes or longer.
|
||||||
|
|
||||||
|
@ -388,7 +390,8 @@ with a body of:
|
||||||
"new_room_user_id": "@someuser:example.com",
|
"new_room_user_id": "@someuser:example.com",
|
||||||
"room_name": "Content Violation Notification",
|
"room_name": "Content Violation Notification",
|
||||||
"message": "Bad Room has been shutdown due to content violations on this server. Please review our Terms of Service.",
|
"message": "Bad Room has been shutdown due to content violations on this server. Please review our Terms of Service.",
|
||||||
"block": true
|
"block": true,
|
||||||
|
"purge": true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -430,8 +433,10 @@ The following JSON body parameters are available:
|
||||||
`new_room_user_id` in the new room. Ideally this will clearly convey why the
|
`new_room_user_id` in the new room. Ideally this will clearly convey why the
|
||||||
original room was shut down. Defaults to `Sharing illegal content on this server
|
original room was shut down. Defaults to `Sharing illegal content on this server
|
||||||
is not permitted and rooms in violation will be blocked.`
|
is not permitted and rooms in violation will be blocked.`
|
||||||
* `block` - Optional. If set to `true`, this room will be added to a blocking list, preventing future attempts to
|
* `block` - Optional. If set to `true`, this room will be added to a blocking list, preventing
|
||||||
join the room. Defaults to `false`.
|
future attempts to join the room. Defaults to `false`.
|
||||||
|
* `purge` - Optional. If set to `true`, it will remove all traces of the room from your database.
|
||||||
|
Defaults to `true`.
|
||||||
|
|
||||||
The JSON body must not be empty. The body must be at least `{}`.
|
The JSON body must not be empty. The body must be at least `{}`.
|
||||||
|
|
||||||
|
|
|
@ -103,6 +103,14 @@ class DeleteRoomRestServlet(RestServlet):
|
||||||
Codes.BAD_JSON,
|
Codes.BAD_JSON,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
purge = content.get("purge", True)
|
||||||
|
if not isinstance(purge, bool):
|
||||||
|
raise SynapseError(
|
||||||
|
HTTPStatus.BAD_REQUEST,
|
||||||
|
"Param 'purge' must be a boolean, if given",
|
||||||
|
Codes.BAD_JSON,
|
||||||
|
)
|
||||||
|
|
||||||
ret = await self.room_shutdown_handler.shutdown_room(
|
ret = await self.room_shutdown_handler.shutdown_room(
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
new_room_user_id=content.get("new_room_user_id"),
|
new_room_user_id=content.get("new_room_user_id"),
|
||||||
|
@ -113,6 +121,7 @@ class DeleteRoomRestServlet(RestServlet):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Purge room
|
# Purge room
|
||||||
|
if purge:
|
||||||
await self.pagination_handler.purge_room(room_id)
|
await self.pagination_handler.purge_room(room_id)
|
||||||
|
|
||||||
return (200, ret)
|
return (200, ret)
|
||||||
|
|
|
@ -283,6 +283,23 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.BAD_JSON, channel.json_body["errcode"])
|
self.assertEqual(Codes.BAD_JSON, channel.json_body["errcode"])
|
||||||
|
|
||||||
|
def test_purge_is_not_bool(self):
|
||||||
|
"""
|
||||||
|
If parameter `purge` is not boolean, return an error
|
||||||
|
"""
|
||||||
|
body = json.dumps({"purge": "NotBool"})
|
||||||
|
|
||||||
|
request, channel = self.make_request(
|
||||||
|
"POST",
|
||||||
|
self.url,
|
||||||
|
content=body.encode(encoding="utf_8"),
|
||||||
|
access_token=self.admin_user_tok,
|
||||||
|
)
|
||||||
|
self.render(request)
|
||||||
|
|
||||||
|
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
self.assertEqual(Codes.BAD_JSON, channel.json_body["errcode"])
|
||||||
|
|
||||||
def test_purge_room_and_block(self):
|
def test_purge_room_and_block(self):
|
||||||
"""Test to purge a room and block it.
|
"""Test to purge a room and block it.
|
||||||
Members will not be moved to a new room and will not receive a message.
|
Members will not be moved to a new room and will not receive a message.
|
||||||
|
@ -297,7 +314,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
||||||
# Assert one user in room
|
# Assert one user in room
|
||||||
self._is_member(room_id=self.room_id, user_id=self.other_user)
|
self._is_member(room_id=self.room_id, user_id=self.other_user)
|
||||||
|
|
||||||
body = json.dumps({"block": True})
|
body = json.dumps({"block": True, "purge": True})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
request, channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
|
@ -331,7 +348,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
||||||
# Assert one user in room
|
# Assert one user in room
|
||||||
self._is_member(room_id=self.room_id, user_id=self.other_user)
|
self._is_member(room_id=self.room_id, user_id=self.other_user)
|
||||||
|
|
||||||
body = json.dumps({"block": False})
|
body = json.dumps({"block": False, "purge": True})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
request, channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
|
@ -351,6 +368,42 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
||||||
self._is_blocked(self.room_id, expect=False)
|
self._is_blocked(self.room_id, expect=False)
|
||||||
self._has_no_members(self.room_id)
|
self._has_no_members(self.room_id)
|
||||||
|
|
||||||
|
def test_block_room_and_not_purge(self):
|
||||||
|
"""Test to block a room without purging it.
|
||||||
|
Members will not be moved to a new room and will not receive a message.
|
||||||
|
The room will not be purged.
|
||||||
|
"""
|
||||||
|
# Test that room is not purged
|
||||||
|
with self.assertRaises(AssertionError):
|
||||||
|
self._is_purged(self.room_id)
|
||||||
|
|
||||||
|
# Test that room is not blocked
|
||||||
|
self._is_blocked(self.room_id, expect=False)
|
||||||
|
|
||||||
|
# Assert one user in room
|
||||||
|
self._is_member(room_id=self.room_id, user_id=self.other_user)
|
||||||
|
|
||||||
|
body = json.dumps({"block": False, "purge": False})
|
||||||
|
|
||||||
|
request, channel = self.make_request(
|
||||||
|
"POST",
|
||||||
|
self.url.encode("ascii"),
|
||||||
|
content=body.encode(encoding="utf_8"),
|
||||||
|
access_token=self.admin_user_tok,
|
||||||
|
)
|
||||||
|
self.render(request)
|
||||||
|
|
||||||
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
self.assertEqual(None, channel.json_body["new_room_id"])
|
||||||
|
self.assertEqual(self.other_user, channel.json_body["kicked_users"][0])
|
||||||
|
self.assertIn("failed_to_kick_users", channel.json_body)
|
||||||
|
self.assertIn("local_aliases", channel.json_body)
|
||||||
|
|
||||||
|
with self.assertRaises(AssertionError):
|
||||||
|
self._is_purged(self.room_id)
|
||||||
|
self._is_blocked(self.room_id, expect=False)
|
||||||
|
self._has_no_members(self.room_id)
|
||||||
|
|
||||||
def test_shutdown_room_consent(self):
|
def test_shutdown_room_consent(self):
|
||||||
"""Test that we can shutdown rooms with local users who have not
|
"""Test that we can shutdown rooms with local users who have not
|
||||||
yet accepted the privacy policy. This used to fail when we tried to
|
yet accepted the privacy policy. This used to fail when we tried to
|
||||||
|
|
Loading…
Reference in a new issue