Skip to content

Commit aad4221

Browse files
committed
Add "erase" option to REST deactivate request body
This allows using the endpoint to deactivate a user without deleting it. TODO: make the request body optional.
1 parent b4c3de4 commit aad4221

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

crates/handlers/src/admin/v1/users/deactivate.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use aide::{NoApi, OperationIo, transform::TransformOperation};
88
use axum::{Json, response::IntoResponse};
99
use hyper::StatusCode;
1010
use mas_axum_utils::record_error;
11+
use schemars::JsonSchema;
12+
use serde::Deserialize;
1113
use mas_storage::{
1214
BoxRng,
1315
queue::{DeactivateUserJob, QueueJobRepositoryExt as _},
@@ -49,6 +51,14 @@ impl IntoResponse for RouteError {
4951
}
5052
}
5153

54+
/// # JSON payload for the `POST /api/admin/v1/users/:id/deactivate` endpoint
55+
#[derive(Deserialize, JsonSchema)]
56+
#[serde(rename = "DeactivateUserRequest")]
57+
pub struct Request {
58+
/// Whether the user should be GDPR-erased from the homeserver.
59+
erase: bool,
60+
}
61+
5262
pub fn doc(operation: TransformOperation) -> TransformOperation {
5363
operation
5464
.id("deactivateUser")
@@ -76,6 +86,7 @@ pub async fn handler(
7686
}: CallContext,
7787
NoApi(mut rng): NoApi<BoxRng>,
7888
id: UlidPathParam,
89+
Json(params): Json<Request>,
7990
) -> Result<Json<SingleResponse<User>>, RouteError> {
8091
let id = *id;
8192
let mut user = repo
@@ -90,7 +101,7 @@ pub async fn handler(
90101

91102
info!(%user.id, "Scheduling deactivation of user");
92103
repo.queue_job()
93-
.schedule_job(&mut rng, &clock, DeactivateUserJob::new(&user, true))
104+
.schedule_job(&mut rng, &clock, DeactivateUserJob::new(&user, params.erase))
94105
.await?;
95106

96107
repo.save().await?;

docs/api/spec.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,16 @@
13591359
"style": "simple"
13601360
}
13611361
],
1362+
"requestBody": {
1363+
"content": {
1364+
"application/json": {
1365+
"schema": {
1366+
"$ref": "#/components/schemas/DeactivateUserRequest"
1367+
}
1368+
}
1369+
},
1370+
"required": true
1371+
},
13621372
"responses": {
13631373
"200": {
13641374
"description": "User was deactivated",
@@ -3872,6 +3882,19 @@
38723882
}
38733883
}
38743884
},
3885+
"DeactivateUserRequest": {
3886+
"title": "JSON payload for the `POST /api/admin/v1/users/:id/deactivate` endpoint",
3887+
"type": "object",
3888+
"required": [
3889+
"erase"
3890+
],
3891+
"properties": {
3892+
"erase": {
3893+
"description": "Whether the user should be GDPR-erased from the homeserver.",
3894+
"type": "boolean"
3895+
}
3896+
}
3897+
},
38753898
"UserEmailFilter": {
38763899
"type": "object",
38773900
"properties": {

0 commit comments

Comments
 (0)