Skip to main content

ruma_client_api/admin/
lock_user.rs

1//! `PUT /_matrix/client/*/admin/lock/{userId}`
2//!
3//! Sets the locked 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 lock 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_matrixclientv1adminlockuserid
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/lock/{user_id}",
34            1.18 => "/_matrix/client/v1/admin/lock/{user_id}",
35        }
36    }
37
38    /// Request type for the `lock_user` endpoint.
39    #[request]
40    pub struct Request {
41        /// The user to change the locked status of.
42        #[ruma_api(path)]
43        pub user_id: OwnedUserId,
44
45        /// Whether to lock the target account.
46        pub locked: bool,
47    }
48
49    /// Response type for the `lock_user` endpoint.
50    #[response]
51    pub struct Response {
52        /// Whether the target account is locked.
53        pub locked: bool,
54    }
55
56    impl Request {
57        /// Creates a new `Request` with the given user ID and locked status.
58        pub fn new(user_id: OwnedUserId, locked: bool) -> Self {
59            Self { user_id, locked }
60        }
61    }
62
63    impl Response {
64        /// Creates a new `Response` with the given locked status.
65        pub fn new(locked: bool) -> Self {
66            Self { locked }
67        }
68    }
69}