Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Allow admins to proactively block rooms #11228

Merged
merged 15 commits into from
Nov 9, 2021
5 changes: 3 additions & 2 deletions docs/admin_api/rooms.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ This API will remove all trace of the old room from your database after removing
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.

The local server will only have the power to move local user and room aliases to
Expand Down Expand Up @@ -478,7 +478,8 @@ The following fields are returned in the JSON response body:
* `failed_to_kick_users` - An array of users (`user_id`) that that were not kicked.
* `local_aliases` - An array of strings representing the local aliases that were migrated from
the old room to the new.
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
* `new_room_id` - A string representing the room ID of the new room.
* `new_room_id` - A string representing the room ID of the new room, or `null` if
no such room was created.


## Undoing room deletions
Expand Down
18 changes: 14 additions & 4 deletions synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Contains functions for performing events on rooms."""

"""Contains functions for performing actions on rooms."""
import itertools
import logging
import math
Expand All @@ -31,6 +30,8 @@
Tuple,
)

from typing_extensions import TypedDict

from synapse.api.constants import (
EventContentFields,
EventTypes,
Expand Down Expand Up @@ -1275,6 +1276,13 @@ def get_current_key_for_room(self, room_id: str) -> Awaitable[str]:
return self.store.get_room_events_max_id(room_id)


class ShutdownRoomResponse(TypedDict):
kicked_users: List[str]
failed_to_kick_users: List[str]
local_aliases: List[str]
new_room_id: Optional[str]


class RoomShutdownHandler:

DEFAULT_MESSAGE = (
Expand All @@ -1300,7 +1308,7 @@ async def shutdown_room(
new_room_name: Optional[str] = None,
message: Optional[str] = None,
block: bool = False,
) -> dict:
) -> ShutdownRoomResponse:
"""
Shuts down a room. Moves all local users and room aliases automatically
to a new room if `new_room_user_id` is set. Otherwise local users only
Expand Down Expand Up @@ -1344,7 +1352,9 @@ async def shutdown_room(
local_aliases:
An array of strings representing the local aliases that were
migrated from the old room to the new.
new_room_id: A string representing the room ID of the new room.
new_room_id:
A string representing the room ID of the new room, or None if
no such room was created.
"""

if not new_room_name:
Expand Down
6 changes: 4 additions & 2 deletions synapse/rest/admin/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
import logging
from http import HTTPStatus
from typing import TYPE_CHECKING, List, Optional, Tuple
from typing import TYPE_CHECKING, List, Optional, Tuple, cast
from urllib import parse as urlparse

from synapse.api.constants import EventTypes, JoinRules, Membership
Expand Down Expand Up @@ -241,7 +241,9 @@ async def _delete_room(
if purge:
await pagination_handler.purge_room(room_id, force=force_purge)

return 200, ret
# Cast safety: I'm casting away the knowledge that this is a TypedDict.
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
# `ret` is an opaque dictionary blob as far as the rest of the app cares.
return 200, cast(JsonDict, ret)


class RoomMembersRestServlet(RestServlet):
Expand Down