This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add dedicated admin API for blocking a room #11324
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
44c10fb
Add dedicated admin API for blocking a room
dklimpel 3011cf4
newsfile
dklimpel 5008f58
Apply suggestions from code review
dklimpel 8bad9ed
chnage response to `HTTPStatus.OK`
dklimpel 03cdf59
some docs
dklimpel 82af5cf
Apply suggestions from code review
dklimpel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add dedicated admin API for blocking a room. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| - [Room Details API](#room-details-api) | ||
| - [Room Members API](#room-members-api) | ||
| - [Room State API](#room-state-api) | ||
| - [Block Room API](#block-room-api) | ||
| - [Delete Room API](#delete-room-api) | ||
| * [Version 1 (old version)](#version-1-old-version) | ||
| * [Version 2 (new version)](#version-2-new-version) | ||
|
|
@@ -386,6 +387,82 @@ A response body like the following is returned: | |
| } | ||
| ``` | ||
|
|
||
| # Block Room API | ||
| The Block Room admin API allows server admins to block rooms and get the status. | ||
| 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. | ||
|
|
||
| ## Block or unblock a room | ||
|
|
||
| The API is: | ||
|
|
||
| ``` | ||
| PUT /_synapse/admin/v1/rooms/<room_id>/block | ||
| ``` | ||
|
|
||
| with a body of: | ||
|
|
||
| ```json | ||
| { | ||
| "block": true | ||
| } | ||
| ``` | ||
|
|
||
| A response body like the following is returned: | ||
|
|
||
| ```json | ||
| { | ||
| "block": true | ||
| } | ||
| ``` | ||
|
|
||
| **Parameters** | ||
|
|
||
| The following parameters should be set in the URL: | ||
|
|
||
| - `room_id` - The ID of the room. | ||
|
|
||
| The following JSON body parameters are available: | ||
|
|
||
| - `block` - If `true` the room will be blocked and if `false` the room will be unblocked. | ||
|
|
||
| **Response** | ||
|
|
||
| The following fields are possible in the JSON response body: | ||
|
|
||
| - `block` - A boolean if the room is blocked or not. | ||
dklimpel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Get block status | ||
|
|
||
| The API is: | ||
|
|
||
| ``` | ||
| GET /_synapse/admin/v1/rooms/<room_id>/block | ||
| ``` | ||
|
|
||
| A response body like the following is returned: | ||
|
|
||
| ```json | ||
| { | ||
| "block": true, | ||
| "user_id": "<user_id>" | ||
| } | ||
| ``` | ||
|
|
||
| **Parameters** | ||
|
|
||
| The following parameters should be set in the URL: | ||
|
|
||
| - `room_id` - The ID of the room. | ||
|
|
||
| **Response** | ||
|
|
||
| The following fields are possible in the JSON response body: | ||
|
|
||
| - `block` - A boolean if the room is blocked or not. | ||
dklimpel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - `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. | ||
|
|
||
| # Delete Room API | ||
|
|
||
| The Delete Room admin API allows server admins to remove rooms from the server | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -397,6 +397,16 @@ async def is_room_blocked(self, room_id: str) -> Optional[bool]: | |
| desc="is_room_blocked", | ||
| ) | ||
|
|
||
| async def room_is_blocked_by(self, room_id: str) -> Optional[str]: | ||
| """Function to retrieve user who has blocked the room""" | ||
| return await self.db_pool.simple_select_one_onecol( | ||
| table="blocked_rooms", | ||
| keyvalues={"room_id": room_id}, | ||
| retcol="user_id", | ||
| allow_none=True, | ||
| desc="room_is_blocked_by", | ||
| ) | ||
|
Comment on lines
+400
to
+412
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For completeness, |
||
|
|
||
| async def get_rooms_paginate( | ||
| self, | ||
| start: int, | ||
|
|
@@ -1775,3 +1785,21 @@ async def block_room(self, room_id: str, user_id: str) -> None: | |
| self.is_room_blocked, | ||
| (room_id,), | ||
| ) | ||
|
|
||
| async def unblock_room(self, room_id: str) -> None: | ||
| """Remove the room from blocking list. | ||
|
|
||
| Args: | ||
| room_id: Room to unblock | ||
| """ | ||
| await self.db_pool.simple_delete( | ||
| table="blocked_rooms", | ||
| keyvalues={"room_id": room_id}, | ||
| desc="unblock_room", | ||
| ) | ||
| await self.db_pool.runInteraction( | ||
| "block_room_invalidation", | ||
| self._invalidate_cache_and_stream, | ||
| self.is_room_blocked, | ||
| (room_id,), | ||
| ) | ||
DMRobertson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.