tuwunel_api/client/admin/users/
suspend.rs1use axum::extract::State;
2use synapse_admin_api::users::suspend::v1 as suspend;
3use tuwunel_core::{Err, Result};
4
5use crate::{Ruma, client::admin::require_admin};
6
7pub(crate) async fn admin_suspend_route(
12 State(services): State<crate::State>,
13 body: Ruma<suspend::Request>,
14) -> Result<suspend::Response> {
15 let sender_user = body.sender_user();
16
17 require_admin(&services, sender_user).await?;
18
19 if !services.globals.user_is_local(&body.user_id) {
20 return Err!(Request(InvalidParam("Can only suspend local users")));
21 }
22
23 if !services.users.exists(&body.user_id).await {
24 return Err!(Request(NotFound("User not found")));
25 }
26
27 if services.users.is_suspended(&body.user_id).await != body.suspend {
28 match body.suspend {
29 | true => services
30 .users
31 .set_suspended(&body.user_id, sender_user),
32 | false => services.users.clear_suspended(&body.user_id),
33 }
34 }
35
36 let result = suspend::Suspended::new(body.user_id.clone(), body.suspend);
37
38 Ok(suspend::Response::new(result))
39}