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

Add device management to admin API #7481

Merged
merged 6 commits into from
Jun 5, 2020
Merged
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/7481.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add admin APIs to allow server admins to manage users' devices. Contributed by @dklimpel.
209 changes: 209 additions & 0 deletions docs/admin_api/user_admin_api.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. contents::

Create or modify Account
========================

Expand Down Expand Up @@ -244,3 +246,210 @@ with a body of:
}

including an ``access_token`` of a server admin.


User devices
============

List all devices
----------------
Gets information about all devices for a specific ``user_id``.

**Usage**

A standard request to query the devices of an user:

::

GET /_synapse/admin/v2/users/<user_id>/devices

{}

Response:

.. code:: json

{
"devices": [
{
"device_id": "QBUAZIFURK",
"display_name": "android",
"last_seen_ip": "1.2.3.4",
"last_seen_ts": 1474491775024,
"user_id": "<user_id>"
},
{
"device_id": "AUIECTSRND",
"display_name": "ios",
"last_seen_ip": "1.2.3.5",
"last_seen_ts": 1474491775025,
"user_id": "<user_id>"
}
]
}

**Parameters**

The following query parameters are available:

- ``user_id`` - fully qualified: for example, ``@user:server.com``.

The following fields are possible in the JSON response body:

- ``devices`` - An array of objects, each containing information about a device.
Device objects contain the following fields:

- ``device_id`` - Identifier of device.
- ``display_name`` - Display name set by the user for this device.
Absent if no name has been set.
- ``last_seen_ip`` - The IP address where this device was last seen.
(May be a few minutes out of date, for efficiency reasons).
- ``last_seen_ts`` - The timestamp (in milliseconds since the unix epoch) when this
devices was last seen. (May be a few minutes out of date, for efficiency reasons).
- ``user_id`` - Owner of device.

Delete multiple devices
------------------
Deletes the given devices for a specific ``user_id``, and invalidates
any access token associated with them.

**Usage**

A standard request to delete devices:

::

POST /_synapse/admin/v2/users/<user_id>/delete_devices

{
"devices": [
"QBUAZIFURK",
"AUIECTSRND"
],
}


Response:

.. code:: json

{}

**Parameters**

The following query parameters are available:

- ``user_id`` - fully qualified: for example, ``@user:server.com``.

The following fields are required in the JSON request body:

- ``devices`` - The list of device IDs to delete.

Show a device
---------------
Gets information on a single device, by ``device_id`` for a specific ``user_id``.

**Usage**

A standard request to get a device:

::

GET /_synapse/admin/v2/users/<user_id>/devices/<device_id>

{}


Response:

.. code:: json

{
"device_id": "<device_id>",
"display_name": "android",
"last_seen_ip": "1.2.3.4",
"last_seen_ts": 1474491775024,
"user_id": "<user_id>"
}

**Parameters**

The following query parameters are available:

- ``user_id`` - fully qualified: for example, ``@user:server.com``.
- ``device_id`` - The device to retrieve.

The following fields are possible in the JSON response body:

- ``device_id`` - Identifier of device.
- ``display_name`` - Display name set by the user for this device.
Absent if no name has been set.
- ``last_seen_ip`` - The IP address where this device was last seen.
(May be a few minutes out of date, for efficiency reasons).
- ``last_seen_ts`` - The timestamp (in milliseconds since the unix epoch) when this
devices was last seen. (May be a few minutes out of date, for efficiency reasons).
- ``user_id`` - Owner of device.

Update a device
---------------
Updates the metadata on the given ``device_id`` for a specific ``user_id``.

**Usage**

A standard request to update a device:

::

PUT /_synapse/admin/v2/users/<user_id>/devices/<device_id>

{
"display_name": "My other phone"
}


Response:

.. code:: json

{}

**Parameters**

The following query parameters are available:

- ``user_id`` - fully qualified: for example, ``@user:server.com``.
- ``device_id`` - The device to update.

The following fields are required in the JSON request body:

- ``display_name`` - The new display name for this device. If not given,
the display name is unchanged.

Delete a device
---------------
Deletes the given ``device_id`` for a specific ``user_id``,
and invalidates any access token associated with it.

**Usage**

A standard request for delete a device:

::

DELETE /_synapse/admin/v2/users/<user_id>/devices/<device_id>

{}


Response:

.. code:: json

{}

**Parameters**

The following query parameters are available:

- ``user_id`` - fully qualified: for example, ``@user:server.com``.
- ``device_id`` - The device to delete.
8 changes: 8 additions & 0 deletions synapse/rest/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
assert_requester_is_admin,
historical_admin_path_patterns,
)
from synapse.rest.admin.devices import (
DeleteDevicesRestServlet,
DeviceRestServlet,
DevicesRestServlet,
)
from synapse.rest.admin.groups import DeleteGroupAdminRestServlet
from synapse.rest.admin.media import ListMediaInRoom, register_servlets_for_media_repo
from synapse.rest.admin.purge_room_servlet import PurgeRoomServlet
Expand Down Expand Up @@ -202,6 +207,9 @@ def register_servlets(hs, http_server):
UserAdminServlet(hs).register(http_server)
UserRestServletV2(hs).register(http_server)
UsersRestServletV2(hs).register(http_server)
DeviceRestServlet(hs).register(http_server)
DevicesRestServlet(hs).register(http_server)
DeleteDevicesRestServlet(hs).register(http_server)


def register_servlets_for_client_rest_resource(hs, http_server):
Expand Down
Loading