Skip to content

Commit f8944b6

Browse files
authored
Merge branch 'main' into ref-merge/7463ed4ba9395708362e095f33bc381ca47e1b6a
2 parents 7463ed4 + dee5902 commit f8944b6

33 files changed

+910
-489
lines changed

Cargo.lock

Lines changed: 35 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ features = ["serde", "clock"]
166166

167167
# CLI argument parsing
168168
[workspace.dependencies.clap]
169-
version = "4.5.40"
169+
version = "4.5.41"
170170
features = ["derive"]
171171

172172
# Object Identifiers (OIDs) as constants
@@ -273,7 +273,7 @@ features = ["client", "server", "http1", "http2"]
273273

274274
# Additional Hyper utilties
275275
[workspace.dependencies.hyper-util]
276-
version = "0.1.14"
276+
version = "0.1.15"
277277
features = [
278278
"client",
279279
"server",
@@ -473,7 +473,7 @@ features = ["std", "pkcs5", "encryption"]
473473

474474
# Public Suffix List
475475
[workspace.dependencies.psl]
476-
version = "2.1.123"
476+
version = "2.1.124"
477477

478478
# Prometheus metrics
479479
[workspace.dependencies.prometheus]
@@ -512,11 +512,11 @@ version = "2.1.1"
512512

513513
# Matrix-related types
514514
[workspace.dependencies.ruma-common]
515-
version = "0.15.3"
515+
version = "0.15.4"
516516

517517
# TLS stack
518518
[workspace.dependencies.rustls]
519-
version = "0.23.28"
519+
version = "0.23.29"
520520

521521
# PEM parsing for rustls
522522
[workspace.dependencies.rustls-pemfile]
@@ -591,7 +591,7 @@ version = "0.7.1"
591591

592592
# Custom serialization helpers
593593
[workspace.dependencies.serde_with]
594-
version = "3.13.0"
594+
version = "3.14.0"
595595
features = ["hex", "chrono"]
596596

597597
# YAML serialization

crates/cli/src/commands/server.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,9 @@ impl Options {
173173
test_mailer_in_background(&mailer, Duration::from_secs(30));
174174

175175
info!("Starting task worker");
176-
mas_tasks::init(
176+
mas_tasks::init_and_run(
177177
PgRepositoryFactory::new(pool.clone()),
178+
SystemClock::default(),
178179
&mailer,
179180
homeserver_connection.clone(),
180181
url_builder.clone(),

crates/cli/src/commands/worker.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use clap::Parser;
1010
use figment::Figment;
1111
use mas_config::{AppConfig, ConfigurationSection};
1212
use mas_router::UrlBuilder;
13+
use mas_storage::SystemClock;
1314
use mas_storage_pg::PgRepositoryFactory;
1415
use tracing::{info, info_span};
1516

@@ -63,8 +64,9 @@ impl Options {
6364
drop(config);
6465

6566
info!("Starting task scheduler");
66-
mas_tasks::init(
67+
mas_tasks::init_and_run(
6768
PgRepositoryFactory::new(pool.clone()),
69+
SystemClock::default(),
6870
&mailer,
6971
conn,
7072
url_builder,

crates/handlers/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ mas-axum-utils.workspace = true
7272
mas-config.workspace = true
7373
mas-context.workspace = true
7474
mas-data-model.workspace = true
75+
mas-email.workspace = true
7576
mas-http.workspace = true
7677
mas-i18n.workspace = true
7778
mas-iana.workspace = true
@@ -83,6 +84,7 @@ mas-policy.workspace = true
8384
mas-router.workspace = true
8485
mas-storage.workspace = true
8586
mas-storage-pg.workspace = true
87+
mas-tasks.workspace = true
8688
mas-templates.workspace = true
8789
oauth2-types.workspace = true
8890
zxcvbn.workspace = true

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

Lines changed: 64 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ pub async fn handler(
105105
mod tests {
106106
use chrono::Duration;
107107
use hyper::{Request, StatusCode};
108+
use insta::assert_json_snapshot;
108109
use mas_storage::{Clock, RepositoryAccess, user::UserRepository};
109-
use sqlx::{PgPool, types::Json};
110+
use sqlx::PgPool;
110111

111112
use crate::test_utils::{RequestBuilderExt, ResponseExt, TestState, setup};
112113

@@ -137,15 +138,37 @@ mod tests {
137138
serde_json::json!(state.clock.now())
138139
);
139140

140-
// It should have scheduled a deactivation job for the user
141-
// XXX: we don't have a good way to look for the deactivation job
142-
let job: Json<serde_json::Value> = sqlx::query_scalar(
143-
"SELECT payload FROM queue_jobs WHERE queue_name = 'deactivate-user'",
144-
)
145-
.fetch_one(&pool)
146-
.await
147-
.expect("Deactivation job to be scheduled");
148-
assert_eq!(job["user_id"], serde_json::json!(user.id));
141+
// Make sure to run the jobs in the queue
142+
state.run_jobs_in_queue().await;
143+
144+
let request = Request::get(format!("/api/admin/v1/users/{}", user.id))
145+
.bearer(&token)
146+
.empty();
147+
let response = state.request(request).await;
148+
response.assert_status(StatusCode::OK);
149+
let body: serde_json::Value = response.json();
150+
151+
assert_json_snapshot!(body, @r#"
152+
{
153+
"data": {
154+
"type": "user",
155+
"id": "01FSHN9AG0MZAA6S4AF7CTV32E",
156+
"attributes": {
157+
"username": "alice",
158+
"created_at": "2022-01-16T14:40:00Z",
159+
"locked_at": "2022-01-16T14:40:00Z",
160+
"deactivated_at": "2022-01-16T14:40:00Z",
161+
"admin": false
162+
},
163+
"links": {
164+
"self": "/api/admin/v1/users/01FSHN9AG0MZAA6S4AF7CTV32E"
165+
}
166+
},
167+
"links": {
168+
"self": "/api/admin/v1/users/01FSHN9AG0MZAA6S4AF7CTV32E"
169+
}
170+
}
171+
"#);
149172
}
150173

151174
#[sqlx::test(migrator = "mas_storage_pg::MIGRATOR")]
@@ -179,15 +202,37 @@ mod tests {
179202
serde_json::json!(state.clock.now())
180203
);
181204

182-
// It should have scheduled a deactivation job for the user
183-
// XXX: we don't have a good way to look for the deactivation job
184-
let job: Json<serde_json::Value> = sqlx::query_scalar(
185-
"SELECT payload FROM queue_jobs WHERE queue_name = 'deactivate-user'",
186-
)
187-
.fetch_one(&pool)
188-
.await
189-
.expect("Deactivation job to be scheduled");
190-
assert_eq!(job["user_id"], serde_json::json!(user.id));
205+
// Make sure to run the jobs in the queue
206+
state.run_jobs_in_queue().await;
207+
208+
let request = Request::get(format!("/api/admin/v1/users/{}", user.id))
209+
.bearer(&token)
210+
.empty();
211+
let response = state.request(request).await;
212+
response.assert_status(StatusCode::OK);
213+
let body: serde_json::Value = response.json();
214+
215+
assert_json_snapshot!(body, @r#"
216+
{
217+
"data": {
218+
"type": "user",
219+
"id": "01FSHN9AG0MZAA6S4AF7CTV32E",
220+
"attributes": {
221+
"username": "alice",
222+
"created_at": "2022-01-16T14:40:00Z",
223+
"locked_at": "2022-01-16T14:40:00Z",
224+
"deactivated_at": "2022-01-16T14:41:00Z",
225+
"admin": false
226+
},
227+
"links": {
228+
"self": "/api/admin/v1/users/01FSHN9AG0MZAA6S4AF7CTV32E"
229+
}
230+
},
231+
"links": {
232+
"self": "/api/admin/v1/users/01FSHN9AG0MZAA6S4AF7CTV32E"
233+
}
234+
}
235+
"#);
191236
}
192237

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

0 commit comments

Comments
 (0)