Skip to main content

ruma_client_api/admin/
suspend_user.rs

1//! `PUT /_matrix/client/*/admin/suspend/{userId}`
2//!
3//! Sets the suspended status of a particular server-local user.
4//!
5//! The user calling this endpoint MUST be a server admin. The client SHOULD check that the user is
6//! allowed to suspend other users at the `GET /capabilities` endpoint prior to using this endpoint.
7//!
8//! In order to prevent user enumeration, servers MUST ensure that authorization is checked prior to
9//! trying to do account lookups.
10
11pub mod v1 {
12    //! `/v1/` ([spec])
13    //!
14    //! [spec]: https://spec.matrix.org/v1.18/client-server-api/#put_matrixclientv1adminsuspenduserid
15
16    use ruma_common::{
17        OwnedUserId,
18        api::{auth_scheme::AccessToken, request, response},
19        metadata,
20    };
21
22    metadata! {
23        method: PUT,
24        rate_limited: false,
25        authentication: AccessToken,
26        history: {
27            unstable("uk.timedout.msc4323") => "/_matrix/client/unstable/uk.timedout.msc4323/admin/suspend/{user_id}",
28            1.18 => "/_matrix/client/v1/admin/suspend/{user_id}",
29        }
30    }
31
32    /// Request type for the `suspend_user` endpoint.
33    #[request]
34    pub struct Request {
35        /// The user to change the suspended status of.
36        #[ruma_api(path)]
37        pub user_id: OwnedUserId,
38
39        /// Whether to suspend the target account.
40        pub suspended: bool,
41    }
42
43    /// Response type for the `suspend_user` endpoint.
44    #[response]
45    pub struct Response {
46        /// Whether the target account is suspended.
47        pub suspended: bool,
48    }
49
50    impl Request {
51        /// Creates a new `Request` with the given user ID and suspended status.
52        pub fn new(user_id: OwnedUserId, suspended: bool) -> Self {
53            Self { user_id, suspended }
54        }
55    }
56
57    impl Response {
58        /// Creates a new `Response` with the given suspended status.
59        pub fn new(suspended: bool) -> Self {
60            Self { suspended }
61        }
62    }
63}