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

Add dedicated admin API for blocking a room #11324

Merged
merged 6 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 4 additions & 3 deletions docs/admin_api/rooms.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ A response body like the following is returned:
```

# Block Room API
The Block Room admin API allows server admins to block and unblock rooms, and query to see if a given room is blocked.
The Block Room admin API allows server admins to block and unblock rooms,
and query to see if a given room is blocked.
This API can be used to pre-emptively block a room, even if it's unknown to this
homeserver. Users will be prevented from joining a blocked room.

Expand Down Expand Up @@ -460,8 +461,8 @@ The following parameters should be set in the URL:
The following fields are possible in the JSON response body:

- `block` - A boolean. `true` if the room is blocked, otherwise `false`
- `user_id` - Optional. If the room is blocked (`block` is `true`) shows the user who has
add the room to blocking list. Otherwise it is not displayed.
- `user_id` - A optional string. If the room is blocked (`block` is `true`) shows
dklimpel marked this conversation as resolved.
Show resolved Hide resolved
the user who has add the room to blocking list. Otherwise it is not displayed.

# Delete Room API

Expand Down
4 changes: 3 additions & 1 deletion synapse/rest/admin/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,9 @@ async def on_GET(
)

blocked_by = await self._store.room_is_blocked_by(room_id)
if blocked_by:
# Test `not None` if `user_id` is an empty string
# if someone add manually an entry in database
if blocked_by is not None:
response = {"block": True, "user_id": blocked_by}
else:
response = {"block": False}
Expand Down
6 changes: 5 additions & 1 deletion synapse/storage/databases/main/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,11 @@ async def is_room_blocked(self, room_id: str) -> Optional[bool]:
)

async def room_is_blocked_by(self, room_id: str) -> Optional[str]:
"""Function to retrieve user who has blocked the room"""
"""
Function to retrieve user who has blocked the room.
user_id is non-nullable
It returns None if the room is not blocked.
"""
return await self.db_pool.simple_select_one_onecol(
table="blocked_rooms",
keyvalues={"room_id": room_id},
Expand Down