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

Add a new admin API to create a new device for a user #15611

Merged
merged 4 commits into from
May 17, 2023
Merged
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
Next Next commit
Add a POST /_synapse/admin/v2/users/{user_id}/devices API to provisio…
…n a new device
sandhose committed May 17, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 2ad1cc9d746494378d4fc15e198edc72d86f972a
28 changes: 28 additions & 0 deletions synapse/rest/admin/devices.py
Original file line number Diff line number Diff line change
@@ -137,6 +137,34 @@ async def on_GET(
devices = await self.device_handler.get_devices_by_user(target_user.to_string())
return HTTPStatus.OK, {"devices": devices, "total": len(devices)}

async def on_POST(
self, request: SynapseRequest, user_id: str
) -> Tuple[int, JsonDict]:
await assert_requester_is_admin(self.auth, request)

target_user = UserID.from_string(user_id)
if not self.is_mine(target_user):
raise SynapseError(
HTTPStatus.BAD_REQUEST, "Can only create devices for local users"
)

u = await self.store.get_user_by_id(target_user.to_string())
if u is None:
raise NotFoundError("Unknown user")

body = parse_json_object_from_request(request)
device_id = body.get("device_id")
if not device_id:
raise SynapseError(HTTPStatus.BAD_REQUEST, "Missing device_id")
if not isinstance(device_id, str):
raise SynapseError(HTTPStatus.BAD_REQUEST, "device_id must be a string")

await self.device_handler.check_device_registered(
user_id=user_id, device_id=device_id
)
Comment on lines +163 to +165
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we care to provide a display name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I strictly implemented what we need right now in MAS, there is probably no need to make it more generic right now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! 👍


return HTTPStatus.CREATED, {}


class DeleteDevicesRestServlet(RestServlet):
"""