-
Notifications
You must be signed in to change notification settings - Fork 424
Add memberships admin API
#19260
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
base: develop
Are you sure you want to change the base?
Add memberships admin API
#19260
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add `memberships` endpoint to the admin API. This is useful for forensics and T&S purpose. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -747,6 +747,27 @@ async def get_rooms_user_currently_banned_from( | |
|
|
||
| return frozenset(room_ids) | ||
|
|
||
| async def get_memberships_for_user(self, user_id: str) -> dict[str, str]: | ||
| """Returns a dict of room_id to membership state for a given user. | ||
|
|
||
| If a remote user only returns rooms this server is currently | ||
| participating in. | ||
| """ | ||
|
|
||
| rows = cast( | ||
| list[tuple[str, str]], | ||
| await self.db_pool.simple_select_list( | ||
| "current_state_events", | ||
| keyvalues={ | ||
| "type": EventTypes.Member, | ||
| "state_key": user_id, | ||
| }, | ||
| retcols=["room_id", "membership"], | ||
| desc="get_memberships_for_user", | ||
| ), | ||
| ) | ||
| return dict(rows) | ||
|
|
||
| @cached(max_entries=500000, iterable=True) | ||
| async def get_rooms_for_user(self, user_id: str) -> frozenset[str]: | ||
|
Contributor
Author
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. Should we change this to use
Contributor
Author
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. Another option would be to make |
||
| """Returns a set of room_ids the user is currently joined to. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want a cache here ? if yes we also need to add invalidation.
I didn't do it because it should be used not that often since it is only used by the admin API (for now).