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 a new admin API to create a new device for a user #15611
Merged
clokep
merged 4 commits into
matrix-org:develop
from
sandhose:quenting/synapse-admin-post-device
May 17, 2023
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 a new admin API to create a new device for a user. |
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 |
|---|---|---|
|
|
@@ -137,6 +137,35 @@ 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]: | ||
| """Creates a new device for the user.""" | ||
| 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
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. Do we care to provide a display name? 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. I strictly implemented what we need right now in MAS, there is probably no need to make it more generic right now 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. Makes sense! 👍 |
||
|
|
||
| return HTTPStatus.CREATED, {} | ||
|
|
||
|
|
||
| class DeleteDevicesRestServlet(RestServlet): | ||
| """ | ||
|
|
||
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.