Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions changelog.d/19281.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Admin API: add worker support to `GET /_synapse/admin/v2/users/<user_id>`.
5 changes: 5 additions & 0 deletions docs/workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ information.
^/_matrix/client/(api/v1|r0|v3|unstable)/directory/room/.*$
^/_matrix/client/(r0|v3|unstable)/capabilities$
^/_matrix/client/(r0|v3|unstable)/notifications$

# Admin API requests
^/_synapse/admin/v1/rooms/[^/]+$

# Encryption requests
Expand Down Expand Up @@ -300,6 +302,9 @@ Additionally, the following REST endpoints can be handled for GET requests:
# Presence requests
^/_matrix/client/(api/v1|r0|v3|unstable)/presence/

# Admin API requests
^/_synapse/admin/v2/users/[^/]+$

Pagination requests can also be handled, but all requests for a given
room must be routed to the same instance. Additionally, care must be taken to
ensure that the purge history admin API is not used while pagination requests
Expand Down
3 changes: 3 additions & 0 deletions synapse/rest/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
UserRegisterServlet,
UserReplaceMasterCrossSigningKeyRestServlet,
UserRestServletV2,
UserRestServletV2Get,
UsersRestServletV2,
UsersRestServletV3,
UserTokenRestServlet,
Expand Down Expand Up @@ -280,6 +281,8 @@ def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None:
# matrix_authentication_service integration uses the dedicated MAS API.
if hs.config.experimental.msc3861.enabled:
register_servlets_for_msc3861_delegation(hs, http_server)
else:
UserRestServletV2Get(hs).register(http_server)

return

Expand Down
38 changes: 21 additions & 17 deletions synapse/rest/admin/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def _parse_parameter_deactivated(self, request: SynapseRequest) -> bool | None:
return parse_boolean(request, "deactivated")


class UserRestServletV2(RestServlet):
class UserRestServletV2Get(RestServlet):
PATTERNS = admin_patterns("/users/(?P<user_id>[^/]*)$", "v2")

"""Get request to list user details.
Expand All @@ -220,22 +220,6 @@ class UserRestServletV2(RestServlet):

returns:
200 OK with user details if success otherwise an error.

Put request to allow an administrator to add or modify a user.
This needs user to have administrator access in Synapse.
We use PUT instead of POST since we already know the id of the user
object to create. POST could be used to create guests.

PUT /_synapse/admin/v2/users/<user_id>
{
"password": "secret",
"displayname": "User"
}

returns:
201 OK with new user object if user was created or
200 OK with modified user object if user was modified
otherwise an error.
"""

def __init__(self, hs: "HomeServer"):
Expand Down Expand Up @@ -267,6 +251,26 @@ async def on_GET(

return HTTPStatus.OK, user_info_dict


class UserRestServletV2(UserRestServletV2Get):
"""
Put request to allow an administrator to add or modify a user.
This needs user to have administrator access in Synapse.
We use PUT instead of POST since we already know the id of the user
object to create. POST could be used to create guests.

PUT /_synapse/admin/v2/users/<user_id>
{
"password": "secret",
"displayname": "User"
}

returns:
201 OK with new user object if user was created or
200 OK with modified user object if user was modified
otherwise an error.
"""

async def on_PUT(
self, request: SynapseRequest, user_id: str
) -> tuple[int, JsonMapping]:
Expand Down
Loading