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..02a5435 --- /dev/null +++ b/src/users/login_as_a_user/v1.rs @@ -0,0 +1,47 @@ +//! [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")] + 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 } + } +}