Skip to content

Commit 0d613a5

Browse files
committed
Always add users synchronously with admin API
1 parent e792b62 commit 0d613a5

File tree

2 files changed

+8
-43
lines changed

2 files changed

+8
-43
lines changed

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

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ use axum::{Json, extract::State, response::IntoResponse};
1111
use hyper::StatusCode;
1212
use mas_axum_utils::record_error;
1313
use mas_matrix::{HomeserverConnection, ProvisionRequest};
14-
use mas_storage::{
15-
BoxRng,
16-
queue::{ProvisionUserJob, QueueJobRepositoryExt as _},
17-
};
14+
use mas_storage::BoxRng;
1815
use schemars::JsonSchema;
1916
use serde::Deserialize;
2017
use tracing::warn;
@@ -106,10 +103,6 @@ pub struct Request {
106103
/// tokens (like with admin access) for them
107104
#[serde(default)]
108105
skip_homeserver_check: bool,
109-
110-
/// Delay the response until the user has been created on the homeserver.
111-
#[serde(default)]
112-
add_synchronously: bool,
113106
}
114107

115108
pub fn doc(operation: TransformOperation) -> TransformOperation {
@@ -172,19 +165,13 @@ pub async fn handler(
172165

173166
let user = repo.user().add(&mut rng, &clock, params.username).await?;
174167

175-
if params.add_synchronously {
176-
homeserver
177-
.provision_user(&ProvisionRequest::new(
178-
homeserver.mxid(&user.username),
179-
&user.sub,
180-
))
181-
.await
182-
.map_err(RouteError::Homeserver)?;
183-
} else {
184-
repo.queue_job()
185-
.schedule_job(&mut rng, &clock, ProvisionUserJob::new(&user))
186-
.await?;
187-
}
168+
homeserver
169+
.provision_user(&ProvisionRequest::new(
170+
homeserver.mxid(&user.username),
171+
&user.sub,
172+
))
173+
.await
174+
.map_err(RouteError::Homeserver)?;
188175

189176
repo.save().await?;
190177

@@ -233,23 +220,6 @@ mod tests {
233220
.unwrap();
234221

235222
assert_eq!(user.username, "alice");
236-
}
237-
238-
#[sqlx::test(migrator = "mas_storage_pg::MIGRATOR")]
239-
async fn test_add_user_synchronously(pool: PgPool) {
240-
setup();
241-
let mut state = TestState::from_pool(pool).await.unwrap();
242-
let token = state.token_with_scope("urn:mas:admin").await;
243-
244-
let request = Request::post("/api/admin/v1/users")
245-
.bearer(&token)
246-
.json(serde_json::json!({
247-
"username": "alice",
248-
"add_synchronously": true,
249-
}));
250-
251-
let response = state.request(request).await;
252-
response.assert_status(StatusCode::CREATED);
253223

254224
// Check that the user was created on the homeserver
255225
let mxid = state.homeserver_connection.mxid("alice");

docs/api/spec.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3807,11 +3807,6 @@
38073807
"description": "Skip checking with the homeserver whether the username is available.\n\nUse this with caution! The main reason to use this, is when a user used by an application service needs to exist in MAS to craft special tokens (like with admin access) for them",
38083808
"default": false,
38093809
"type": "boolean"
3810-
},
3811-
"add_synchronously": {
3812-
"description": "Delay the response until the user has been created on the homeserver.",
3813-
"default": false,
3814-
"type": "boolean"
38153810
}
38163811
}
38173812
},

0 commit comments

Comments
 (0)