Add force_purge option to delete-room admin api. (#8843)

This commit is contained in:
Richard van der Hoff 2020-11-30 16:48:12 +00:00 committed by GitHub
parent 856eab606b
commit a090b86209
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 12 deletions

1
changelog.d/8843.feature Normal file
View File

@ -0,0 +1 @@
Add `force_purge` option to delete-room admin api.

View File

@ -382,7 +382,7 @@ the new room. Users on other servers will be unaffected.
The API is: The API is:
```json ```
POST /_synapse/admin/v1/rooms/<room_id>/delete POST /_synapse/admin/v1/rooms/<room_id>/delete
``` ```
@ -439,6 +439,10 @@ The following JSON body parameters are available:
future attempts to 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. * `purge` - Optional. If set to `true`, it will remove all traces of the room from your database.
Defaults to `true`. Defaults to `true`.
* `force_purge` - Optional, and ignored unless `purge` is `true`. If set to `true`, it
will force a purge to go ahead even if there are local users still in the room. Do not
use this unless a regular `purge` operation fails, as it could leave those users'
clients in a confused state.
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 `{}`.

View File

@ -299,17 +299,22 @@ class PaginationHandler:
""" """
return self._purges_by_id.get(purge_id) return self._purges_by_id.get(purge_id)
async def purge_room(self, room_id: str) -> None: async def purge_room(self, room_id: str, force: bool = False) -> None:
"""Purge the given room from the database""" """Purge the given room from the database.
Args:
room_id: room to be purged
force: set true to skip checking for joined users.
"""
with await self.pagination_lock.write(room_id): with await self.pagination_lock.write(room_id):
# check we know about the room # check we know about the room
await self.store.get_room_version_id(room_id) await self.store.get_room_version_id(room_id)
# first check that we have no users in this room # first check that we have no users in this room
joined = await self.store.is_host_joined(room_id, self._server_name) if not force:
joined = await self.store.is_host_joined(room_id, self._server_name)
if joined: if joined:
raise SynapseError(400, "Users are still joined to this room") raise SynapseError(400, "Users are still joined to this room")
await self.storage.purge_events.purge_room(room_id) await self.storage.purge_events.purge_room(room_id)

View File

@ -70,14 +70,18 @@ class ShutdownRoomRestServlet(RestServlet):
class DeleteRoomRestServlet(RestServlet): class DeleteRoomRestServlet(RestServlet):
"""Delete a room from server. It is a combination and improvement of """Delete a room from server.
shut down and purge room.
It is a combination and improvement of shutdown and purge room.
Shuts down a room by removing all local users from the room. Shuts down a room by removing all local users from the room.
Blocking all future invites and joins to the room is optional. Blocking all future invites and joins to the room is optional.
If desired any local aliases will be repointed to a new room If desired any local aliases will be repointed to a new room
created by `new_room_user_id` and kicked users will be auto created by `new_room_user_id` and kicked users will be auto-
joined to the new room. joined to the new room.
It will remove all trace of a room from the database.
If 'purge' is true, it will remove all traces of a room from the database.
""" """
PATTERNS = admin_patterns("/rooms/(?P<room_id>[^/]+)/delete$") PATTERNS = admin_patterns("/rooms/(?P<room_id>[^/]+)/delete$")
@ -110,6 +114,14 @@ class DeleteRoomRestServlet(RestServlet):
Codes.BAD_JSON, Codes.BAD_JSON,
) )
force_purge = content.get("force_purge", False)
if not isinstance(force_purge, bool):
raise SynapseError(
HTTPStatus.BAD_REQUEST,
"Param 'force_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"),
@ -121,7 +133,7 @@ class DeleteRoomRestServlet(RestServlet):
# Purge room # Purge room
if purge: if purge:
await self.pagination_handler.purge_room(room_id) await self.pagination_handler.purge_room(room_id, force=force_purge)
return (200, ret) return (200, ret)