From 085d49b2e2e1ceb1c1dd3425e28a9dedb92ee0fe Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Fri, 31 Mar 2023 15:26:06 +0100 Subject: [PATCH 1/2] Add the 'Log in as a user' admin API --- src/users.rs | 1 + src/users/login_as_a_user.rs | 3 +++ src/users/login_as_a_user/v1.rs | 48 +++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 src/users/login_as_a_user.rs create mode 100644 src/users/login_as_a_user/v1.rs diff --git a/src/users.rs b/src/users.rs index 3b34b6a..f4838b6 100644 --- a/src/users.rs +++ b/src/users.rs @@ -5,6 +5,7 @@ pub mod get_details; pub mod is_user_admin; pub mod list_joined_rooms; pub mod list_users; +pub mod login_as_a_user; pub mod reset_password; use ruma::{thirdparty::ThirdPartyIdentifier, SecondsSinceUnixEpoch}; diff --git a/src/users/login_as_a_user.rs b/src/users/login_as_a_user.rs new file mode 100644 index 0000000..22d64e2 --- /dev/null +++ b/src/users/login_as_a_user.rs @@ -0,0 +1,3 @@ +//! Different versions of the endpoint to log in as a user. + +pub mod v1; diff --git a/src/users/login_as_a_user/v1.rs b/src/users/login_as_a_user/v1.rs new file mode 100644 index 0000000..adb2321 --- /dev/null +++ b/src/users/login_as_a_user/v1.rs @@ -0,0 +1,48 @@ +//! [POST /_synapse/admin/v1/users/:user_id/login](https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#login-as-a-user) + +use ruma::{ + api::{metadata, request, response, Metadata}, + UserId, +}; + +const METADATA: Metadata = metadata! { + method: POST, + rate_limited: false, + authentication: AccessToken, + history: { + unstable => "/_synapse/admin/v1/users/:user_id/login", + } +}; + +#[request] +pub struct Request<'a> { + /// User to log in as. + #[ruma_api(path)] + pub user_id: &'a UserId, + + /// Optional: Integer UNIX timestamp in milliseconds for when the access token should expire. + /// If not specified, the returned access token does not expire. + #[serde(default, skip_serializing_if = "Option::is_none")] + #[ruma_api(body)] + pub valid_until_ms: Option, +} + +#[response] +pub struct Response { + /// An opaque access token string, that can be used to control the user. + pub access_token: String, +} + +impl<'a> Request<'a> { + /// Creates an `Request` with the given user ID. + pub fn new(user_id: &'a UserId, valid_until_ms: Option) -> Self { + Self { user_id, valid_until_ms } + } +} + +impl Response { + /// Creates a `Response` with the given admin flag. + pub fn new(access_token: String) -> Self { + Self { access_token } + } +} From c0b50ddd451e758bb132492439d67c684b749258 Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Fri, 14 Apr 2023 12:42:08 +0100 Subject: [PATCH 2/2] Fix wrong 'newtype body' --- src/users/login_as_a_user/v1.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/users/login_as_a_user/v1.rs b/src/users/login_as_a_user/v1.rs index adb2321..02a5435 100644 --- a/src/users/login_as_a_user/v1.rs +++ b/src/users/login_as_a_user/v1.rs @@ -23,7 +23,6 @@ pub struct Request<'a> { /// Optional: Integer UNIX timestamp in milliseconds for when the access token should expire. /// If not specified, the returned access token does not expire. #[serde(default, skip_serializing_if = "Option::is_none")] - #[ruma_api(body)] pub valid_until_ms: Option, }