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.19/client-server-api/#put_matrixclientv1adminsuspenduserid
15
16    use ruma_common::{
17        OwnedUserId,
18        api::{OAuthClientScope, auth_scheme::AccessToken, request, response},
19        metadata,
20    };
21
22    metadata! {
23        method: PUT,
24        rate_limited: false,
25        authentication: AccessToken,
26        required_client_scopes: [
27            #[cfg(not(feature = "unstable-msc4484"))]
28            OAuthClientScope::ApiFullAccess,
29            #[cfg(feature = "unstable-msc4484")]
30            OAuthClientScope::ServerAdministration,
31        ],
32        history: {
33            unstable("uk.timedout.msc4323") => "/_matrix/client/unstable/uk.timedout.msc4323/admin/suspend/{user_id}",
34            1.18 => "/_matrix/client/v1/admin/suspend/{user_id}",
35        }
36    }
37
38    /// Request type for the `suspend_user` endpoint.
39    #[request]
40    pub struct Request {
41        /// The user to change the suspended status of.
42        #[ruma_api(path)]
43        pub user_id: OwnedUserId,
44
45        /// Whether to suspend the target account.
46        pub suspended: bool,
47    }
48
49    /// Response type for the `suspend_user` endpoint.
50    #[response]
51    pub struct Response {
52        /// Whether the target account is suspended.
53        pub suspended: bool,
54    }
55
56    impl Request {
57        /// Creates a new `Request` with the given user ID and suspended status.
58        pub fn new(user_id: OwnedUserId, suspended: bool) -> Self {
59            Self { user_id, suspended }
60        }
61    }
62
63    impl Response {
64        /// Creates a new `Response` with the given suspended status.
65        pub fn new(suspended: bool) -> Self {
66            Self { suspended }
67        }
68    }
69}