Skip to content

Commit 52c3a36

Browse files
authored
Make the admin API provision users synchronously (#4788)
2 parents e2aad08 + 0d613a5 commit 52c3a36

File tree

1 file changed

+15
-8
lines changed
  • crates/handlers/src/admin/v1/users

1 file changed

+15
-8
lines changed

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ use aide::{NoApi, OperationIo, transform::TransformOperation};
1010
use axum::{Json, extract::State, response::IntoResponse};
1111
use hyper::StatusCode;
1212
use mas_axum_utils::record_error;
13-
use mas_matrix::HomeserverConnection;
14-
use mas_storage::{
15-
BoxRng,
16-
queue::{ProvisionUserJob, QueueJobRepositoryExt as _},
17-
};
13+
use mas_matrix::{HomeserverConnection, ProvisionRequest};
14+
use mas_storage::BoxRng;
1815
use schemars::JsonSchema;
1916
use serde::Deserialize;
2017
use tracing::warn;
@@ -168,9 +165,13 @@ pub async fn handler(
168165

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

171-
repo.queue_job()
172-
.schedule_job(&mut rng, &clock, ProvisionUserJob::new(&user))
173-
.await?;
168+
homeserver
169+
.provision_user(&ProvisionRequest::new(
170+
homeserver.mxid(&user.username),
171+
&user.sub,
172+
))
173+
.await
174+
.map_err(RouteError::Homeserver)?;
174175

175176
repo.save().await?;
176177

@@ -183,6 +184,7 @@ pub async fn handler(
183184
#[cfg(test)]
184185
mod tests {
185186
use hyper::{Request, StatusCode};
187+
use mas_matrix::HomeserverConnection;
186188
use mas_storage::{RepositoryAccess, user::UserRepository};
187189
use sqlx::PgPool;
188190

@@ -218,6 +220,11 @@ mod tests {
218220
.unwrap();
219221

220222
assert_eq!(user.username, "alice");
223+
224+
// Check that the user was created on the homeserver
225+
let mxid = state.homeserver_connection.mxid("alice");
226+
let result = state.homeserver_connection.query_user(&mxid).await;
227+
assert!(result.is_ok());
221228
}
222229

223230
#[sqlx::test(migrator = "mas_storage_pg::MIGRATOR")]

0 commit comments

Comments
 (0)