-
Notifications
You must be signed in to change notification settings - Fork 404
Add an admin API to search for children of a room #19021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
H-Shay
wants to merge
19
commits into
element-hq:develop
Choose a base branch
from
H-Shay:shay/admin_spaces
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+472
−21
Open
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
f963b82
add admin api to search for parent space of room and other rooms in s…
H-Shay e664088
docs + tests
H-Shay 58c6a79
newsfragment
H-Shay fcb54a3
rewrite to model after cs hierarchy endpoint
H-Shay 5f50fd5
update docs and tests
H-Shay 76b86cf
update newsfragment
H-Shay 8f78840
Merge branch 'develop' into shay/admin_spaces
H-Shay 501257e
requested changes
H-Shay 6d8c5c0
requested changes
H-Shay 6148cb7
requested changes
H-Shay c187583
Merge branch 'develop' into shay/admin_spaces
H-Shay e119448
lint
H-Shay 99eb9eb
fix up docs
H-Shay b187d6f
requested changes
H-Shay 077e985
Merge branch 'develop' into shay/admin_spaces
H-Shay f360c98
lint
H-Shay 0e58b05
requested changes
H-Shay 7ed9800
wrapping
H-Shay ed84371
more wrapping
H-Shay 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,2 @@ | ||
| Add an [Admin API](https://element-hq.github.io/synapse/latest/usage/administration/admin_api/index.html) to allow an admin | ||
| to fetch the space/room hierarchy for a given space. |
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 |
|---|---|---|
|
|
@@ -116,6 +116,8 @@ def __init__(self, hs: "HomeServer"): | |
| str, | ||
| str, | ||
| bool, | ||
| bool, | ||
| bool, | ||
| Optional[int], | ||
| Optional[int], | ||
| Optional[str], | ||
|
|
@@ -133,6 +135,8 @@ async def get_room_hierarchy( | |
| requester: Requester, | ||
| requested_room_id: str, | ||
| suggested_only: bool = False, | ||
| omit_remote_room_hierarchy: bool = False, | ||
| admin_skip_room_visibility_check: bool = False, | ||
| max_depth: Optional[int] = None, | ||
| limit: Optional[int] = None, | ||
| from_token: Optional[str] = None, | ||
|
|
@@ -146,6 +150,10 @@ async def get_room_hierarchy( | |
| requested_room_id: The room ID to start the hierarchy at (the "root" room). | ||
| suggested_only: Whether we should only return children with the "suggested" | ||
| flag set. | ||
| omit_remote_room_hierarchy: Whether to skip reaching out over federation to get information on rooms which the server is not | ||
| currently joined to | ||
| admin_skip_room_visibility_check: Whether to skip checking if the room can be accessed by the requester, | ||
MadLittleMods marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| used for the admin endpoints. | ||
| max_depth: The maximum depth in the tree to explore, must be a | ||
| non-negative integer. | ||
|
|
||
|
|
@@ -173,6 +181,8 @@ async def get_room_hierarchy( | |
| requester.user.to_string(), | ||
| requested_room_id, | ||
| suggested_only, | ||
| omit_remote_room_hierarchy, | ||
| admin_skip_room_visibility_check, | ||
| max_depth, | ||
| limit, | ||
| from_token, | ||
|
|
@@ -182,6 +192,8 @@ async def get_room_hierarchy( | |
| requester.user.to_string(), | ||
| requested_room_id, | ||
| suggested_only, | ||
| omit_remote_room_hierarchy, | ||
| admin_skip_room_visibility_check, | ||
| max_depth, | ||
| limit, | ||
| from_token, | ||
|
|
@@ -193,6 +205,8 @@ async def _get_room_hierarchy( | |
| requester: str, | ||
| requested_room_id: str, | ||
| suggested_only: bool = False, | ||
| omit_remote_room_hierarchy: bool = False, | ||
| admin_skip_room_visibility_check: bool = False, | ||
| max_depth: Optional[int] = None, | ||
| limit: Optional[int] = None, | ||
| from_token: Optional[str] = None, | ||
|
|
@@ -204,17 +218,18 @@ async def _get_room_hierarchy( | |
| local_room = await self._store.is_host_joined( | ||
| requested_room_id, self._server_name | ||
| ) | ||
| if local_room and not await self._is_local_room_accessible( | ||
| requested_room_id, requester | ||
| ): | ||
| raise UnstableSpecAuthError( | ||
| 403, | ||
| "User %s not in room %s, and room previews are disabled" | ||
| % (requester, requested_room_id), | ||
| errcode=Codes.NOT_JOINED, | ||
| ) | ||
| if not admin_skip_room_visibility_check: | ||
| if local_room and not await self._is_local_room_accessible( | ||
| requested_room_id, requester | ||
| ): | ||
| raise UnstableSpecAuthError( | ||
| 403, | ||
| "User %s not in room %s, and room previews are disabled" | ||
| % (requester, requested_room_id), | ||
| errcode=Codes.NOT_JOINED, | ||
| ) | ||
|
|
||
| if not local_room: | ||
| if not local_room and not omit_remote_room_hierarchy: | ||
| room_hierarchy = await self._summarize_remote_room_hierarchy( | ||
| _RoomQueueEntry(requested_room_id, remote_room_hosts or ()), | ||
| False, | ||
|
|
@@ -223,12 +238,13 @@ async def _get_room_hierarchy( | |
| if not root_room_entry or not await self._is_remote_room_accessible( | ||
H-Shay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| requester, requested_room_id, root_room_entry.room | ||
| ): | ||
| raise UnstableSpecAuthError( | ||
| 403, | ||
| "User %s not in room %s, and room previews are disabled" | ||
| % (requester, requested_room_id), | ||
| errcode=Codes.NOT_JOINED, | ||
| ) | ||
| if not admin_skip_room_visibility_check: | ||
| raise UnstableSpecAuthError( | ||
| 403, | ||
| "User %s not in room %s, and room previews are disabled" | ||
| % (requester, requested_room_id), | ||
| errcode=Codes.NOT_JOINED, | ||
| ) | ||
|
|
||
| # If this is continuing a previous session, pull the persisted data. | ||
| if from_token: | ||
|
|
@@ -240,13 +256,17 @@ async def _get_room_hierarchy( | |
| except StoreError: | ||
| raise SynapseError(400, "Unknown pagination token", Codes.INVALID_PARAM) | ||
|
|
||
| # If the requester, room ID, suggested-only, or max depth were modified | ||
| # the session is invalid. | ||
| # If the requester, room ID, suggested-only, max depth, omit_remote_room_hierarchy, or admin_skip_room_visibility_check | ||
| # were modified the session is invalid. | ||
| if ( | ||
| requester != pagination_session["requester"] | ||
| or requested_room_id != pagination_session["room_id"] | ||
| or suggested_only != pagination_session["suggested_only"] | ||
| or max_depth != pagination_session["max_depth"] | ||
| or omit_remote_room_hierarchy | ||
| != pagination_session["omit_remote_room_hierarchy"] | ||
| or admin_skip_room_visibility_check | ||
| != pagination_session["admin_skip_room_visibility_check"] | ||
| ): | ||
| raise SynapseError(400, "Unknown pagination token", Codes.INVALID_PARAM) | ||
|
|
||
|
|
@@ -301,8 +321,12 @@ async def _get_room_hierarchy( | |
| None, | ||
| room_id, | ||
| suggested_only, | ||
| admin_skip_room_visibility_check=admin_skip_room_visibility_check, | ||
| ) | ||
|
|
||
| # if we are not fetching remote room details over federation, return what is | ||
| # known about the room | ||
| elif omit_remote_room_hierarchy: | ||
| room_entry = _RoomEntry(room_id, {"room_id": room_id}, ()) | ||
|
||
| # Otherwise, attempt to use information for federation. | ||
| else: | ||
| # A previous call might have included information for this room. | ||
|
|
@@ -378,6 +402,8 @@ async def _get_room_hierarchy( | |
| "room_id": requested_room_id, | ||
| "suggested_only": suggested_only, | ||
| "max_depth": max_depth, | ||
| "omit_remote_room_hierarchy": omit_remote_room_hierarchy, | ||
| "admin_skip_room_visibility_check": admin_skip_room_visibility_check, | ||
| # The stored state. | ||
| "room_queue": [ | ||
| attr.astuple(room_entry) for room_entry in room_queue | ||
|
|
@@ -460,6 +486,7 @@ async def _summarize_local_room( | |
| room_id: str, | ||
| suggested_only: bool, | ||
| include_children: bool = True, | ||
| admin_skip_room_visibility_check: bool = False, | ||
| ) -> Optional["_RoomEntry"]: | ||
| """ | ||
| Generate a room entry and a list of event entries for a given room. | ||
|
|
@@ -476,11 +503,16 @@ async def _summarize_local_room( | |
| Otherwise, all children are returned. | ||
| include_children: | ||
| Whether to include the events of any children. | ||
| admin_skip_room_visibility_check: Whether to skip checking if the room can be accessed by the requester, | ||
| used for the admin endpoints. | ||
|
|
||
| Returns: | ||
| A room entry if the room should be returned. None, otherwise. | ||
| """ | ||
| if not await self._is_local_room_accessible(room_id, requester, origin): | ||
| if ( | ||
| not admin_skip_room_visibility_check | ||
| and not await self._is_local_room_accessible(room_id, requester, origin) | ||
| ): | ||
| return None | ||
|
|
||
| room_entry = await self._build_room_entry(room_id, for_federation=bool(origin)) | ||
|
|
||
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
Oops, something went wrong.
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.