From bdabc5e8273f1c4f4a380530a1415596796ebaa5 Mon Sep 17 00:00:00 2001 From: Raphael Lullis Date: Wed, 6 Mar 2024 11:15:13 +0100 Subject: [PATCH 01/31] Add curl to base images (#4510) Having a tool like curl or wget can help us to run healthchecks on docker-based deployments more easily. This commit adds curl to the list of deb packages that are installed as external dependencies --- docker/Dockerfile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 1bbf4ddbd..0630b6e50 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -75,18 +75,19 @@ RUN --mount=type=cache,target=./target,uid=10001,gid=10001 set -ex; \ mv "./target/$CARGO_BUILD_TARGET/$RUST_RELEASE_MODE/lemmy_server" /home/lemmy/lemmy_server; \ fi + # amd64 base runner FROM ${AMD_RUNNER_IMAGE} AS runner-linux-amd64 -# Federation needs CA certificates -RUN apt update && apt install -y libssl-dev libpq-dev ca-certificates +# Add system packages that are needed: federation needs CA certificates, curl can be used for healthchecks +RUN apt update && apt install -y libssl-dev libpq-dev ca-certificates curl COPY --from=build-amd64 --chmod=0755 /lemmy/lemmy_server /usr/local/bin # arm base runner FROM ${ARM_RUNNER_IMAGE} AS runner-linux-arm64 -RUN apt update && apt install -y ca-certificates libssl-dev libpq-dev +RUN apt update && apt install -y libssl-dev libpq-dev ca-certificates curl COPY --from=build-arm64 --chmod=0755 /home/lemmy/lemmy_server /usr/local/bin From fed6b61eaf1a6baea1af9dd64126d1039ba11541 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Wed, 6 Mar 2024 17:21:46 +0100 Subject: [PATCH 02/31] Upgrade apub lib, correct webfinger content-type (#4498) * Upgrade apub lib, correct webfinger content-type * fmt * fix test by avoiding network fetch --- Cargo.lock | 98 +++++++++---------- Cargo.toml | 2 +- crates/api_common/Cargo.toml | 3 - crates/api_common/src/context.rs | 42 +------- crates/api_common/src/request.rs | 2 +- crates/apub/assets/mastodon/objects/page.json | 16 +-- crates/apub/src/objects/post.rs | 24 ++--- crates/routes/src/webfinger.rs | 8 +- 8 files changed, 78 insertions(+), 117 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a5194f393..e4c55f082 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,9 +16,9 @@ checksum = "8f27d075294830fcab6f66e320dab524bc6d048f4a151698e153205559113772" [[package]] name = "activitypub_federation" -version = "0.5.1-beta.1" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "866db431760d14a7360f12e75ad48f3265b5b89cd2303e548a02bcc8983e4fcd" +checksum = "eee115a53849bbcac6c953495b5f9322b56680c0a1bdef6813183f0453f9ee3c" dependencies = [ "activitystreams-kinds", "actix-web", @@ -35,7 +35,7 @@ dependencies = [ "http-signature-normalization", "http-signature-normalization-reqwest", "httpdate", - "itertools 0.12.0", + "itertools 0.12.1", "moka", "once_cell", "openssl", @@ -112,9 +112,9 @@ dependencies = [ [[package]] name = "actix-http" -version = "3.5.1" +version = "3.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "129d4c88e98860e1758c5de288d1632b07970a16d59bdf7b8d66053d582bb71f" +checksum = "d223b13fd481fc0d1f83bb12659ae774d9e3601814c68a0bc539731698cca743" dependencies = [ "actix-codec", "actix-rt", @@ -236,9 +236,9 @@ dependencies = [ [[package]] name = "actix-tls" -version = "3.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "929e47cc23865cdb856e59673cfba2d28f00b3bbd060dfc80e33a00a3cea8317" +checksum = "d4cce60a2f2b477bc72e5cde0af1812a6e82d8fd85b5570a5dcf2a5bf2c5be5f" dependencies = [ "actix-rt", "actix-service", @@ -265,9 +265,9 @@ dependencies = [ [[package]] name = "actix-web" -version = "4.4.1" +version = "4.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e43428f3bf11dee6d166b00ec2df4e3aa8cc1606aaa0b7433c146852e2f4e03b" +checksum = "43a6556ddebb638c2358714d853257ed226ece6023ef9364f23f0c70737ea984" dependencies = [ "actix-codec", "actix-http", @@ -851,9 +851,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.32" +version = "0.4.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41daef31d7a747c5c847246f36de49ced6f7403b4cdabc807a97b5cc184cda7a" +checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" dependencies = [ "android-tzdata", "iana-time-zone", @@ -1564,9 +1564,9 @@ checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" [[package]] name = "dyn-clone" -version = "1.0.16" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "545b22097d44f8a9581187cdf93de7a71e4722bf51200cfaba810865b49a495d" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" [[package]] name = "either" @@ -2026,7 +2026,7 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap 2.1.0", + "indexmap 2.2.5", "slab", "tokio", "tokio-util", @@ -2401,9 +2401,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.1.0" +version = "2.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +checksum = "7b0b929d511467233429c45a44ac1dcaa21ba0f5ba11e4879e6ed28ddb4f9df4" dependencies = [ "equivalent", "hashbrown 0.14.3", @@ -2465,9 +2465,9 @@ dependencies = [ [[package]] name = "itertools" -version = "0.12.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25db6b064527c5d482d0423354fcd07a89a2dfe07b67892e62411946db7f07b0" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" dependencies = [ "either", ] @@ -2578,7 +2578,6 @@ dependencies = [ "activitypub_federation", "actix-web", "anyhow", - "async-trait", "chrono", "encoding", "enum-map", @@ -2649,7 +2648,7 @@ dependencies = [ "html2md", "html2text", "http", - "itertools 0.12.0", + "itertools 0.12.1", "lemmy_api_common", "lemmy_db_schema", "lemmy_db_views", @@ -2884,7 +2883,7 @@ dependencies = [ "futures", "html2text", "http", - "itertools 0.12.0", + "itertools 0.12.1", "lettre", "markdown-it", "once_cell", @@ -3236,9 +3235,9 @@ dependencies = [ [[package]] name = "moka" -version = "0.12.4" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad9dc9808102655926a6086abd0b9965ebefd4a39ef0d184f074c34ba5049ec6" +checksum = "b1911e88d5831f748a4097a43862d129e3c6fca831eecac9b8db6d01d93c9de2" dependencies = [ "async-lock", "async-trait", @@ -3380,9 +3379,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "openssl" -version = "0.10.63" +version = "0.10.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c9d69dd87a29568d4d017cfe8ec518706046a05184e5aea92d0af890b803c8" +checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" dependencies = [ "bitflags 2.4.2", "cfg-if", @@ -3412,9 +3411,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.99" +version = "0.9.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22e1bf214306098e4832460f797824c05d25aacdf896f64a985fb0fd992454ae" +checksum = "dda2b0f344e78efc2facf7d195d098df0dd72151b26ab98da807afc26c198dff" dependencies = [ "cc", "libc", @@ -3457,7 +3456,7 @@ checksum = "1e32339a5dc40459130b3bd269e9892439f55b33e772d2a9d402a789baaf4e8a" dependencies = [ "futures-core", "futures-sink", - "indexmap 2.1.0", + "indexmap 2.2.5", "js-sys", "once_cell", "pin-project-lite", @@ -3854,7 +3853,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5699cc8a63d1aa2b1ee8e12b9ad70ac790d65788cd36101fa37f87ea46c4cef" dependencies = [ "base64 0.21.7", - "indexmap 2.1.0", + "indexmap 2.2.5", "line-wrap", "quick-xml 0.31.0", "serde", @@ -4308,9 +4307,9 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "reqwest" -version = "0.11.23" +version = "0.11.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37b1ae8d9ac08420c66222fb9096fc5de435c3c48542bc5336c51892cffafb41" +checksum = "c6920094eb85afde5e4a138be3f2de8bbdf28000f0029e72c45025a56b042251" dependencies = [ "async-compression", "base64 0.21.7", @@ -4338,6 +4337,7 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", + "sync_wrapper", "system-configuration", "tokio", "tokio-native-tls", @@ -4690,9 +4690,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.195" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" dependencies = [ "serde_derive", ] @@ -4708,9 +4708,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.195" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", @@ -4719,11 +4719,11 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.111" +version = "1.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" +checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" dependencies = [ - "indexmap 2.1.0", + "indexmap 2.2.5", "itoa", "ryu", "serde", @@ -4769,7 +4769,7 @@ dependencies = [ "chrono", "hex", "indexmap 1.9.3", - "indexmap 2.1.0", + "indexmap 2.2.5", "serde", "serde_json", "serde_with_macros", @@ -5204,18 +5204,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.56" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" +checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.56" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" dependencies = [ "proc-macro2", "quote", @@ -5284,9 +5284,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.35.1" +version = "1.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" +checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" dependencies = [ "backtrace", "bytes", @@ -5467,7 +5467,7 @@ version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.1.0", + "indexmap 2.2.5", "serde", "serde_spanned", "toml_datetime", @@ -5480,7 +5480,7 @@ version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d34d383cd00a163b4a5b85053df514d45bc330f6de7737edfe0a93311d1eaa03" dependencies = [ - "indexmap 2.1.0", + "indexmap 2.2.5", "serde", "serde_spanned", "toml_datetime", @@ -6068,9 +6068,9 @@ checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" [[package]] name = "wasm-streams" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4609d447824375f43e1ffbc051b50ad8f4b3ae8219680c94452ea05eb240ac7" +checksum = "b65dc4c90b63b118468cf747d8bf3566c1913ef60be765b5730ead9e0a3ba129" dependencies = [ "futures-util", "js-sys", diff --git a/Cargo.toml b/Cargo.toml index 98bf79b8c..037d03919 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -96,7 +96,7 @@ lemmy_routes = { version = "=0.19.3", path = "./crates/routes" } lemmy_db_views = { version = "=0.19.3", path = "./crates/db_views" } lemmy_db_views_actor = { version = "=0.19.3", path = "./crates/db_views_actor" } lemmy_db_views_moderator = { version = "=0.19.3", path = "./crates/db_views_moderator" } -activitypub_federation = { version = "0.5.1-beta.1", default-features = false, features = [ +activitypub_federation = { version = "0.5.1", default-features = false, features = [ "actix-web", ] } diesel = "2.1.4" diff --git a/crates/api_common/Cargo.toml b/crates/api_common/Cargo.toml index 0192099f3..3acd7d4ca 100644 --- a/crates/api_common/Cargo.toml +++ b/crates/api_common/Cargo.toml @@ -54,7 +54,6 @@ tracing = { workspace = true, optional = true } reqwest-middleware = { workspace = true, optional = true } regex = { workspace = true } rosetta-i18n = { workspace = true, optional = true } -anyhow = { workspace = true } futures = { workspace = true, optional = true } uuid = { workspace = true, optional = true } tokio = { workspace = true, optional = true } @@ -64,7 +63,6 @@ once_cell = { workspace = true, optional = true } actix-web = { workspace = true, optional = true } enum-map = { workspace = true } urlencoding = { workspace = true } -async-trait = { workspace = true } mime = { version = "0.3.17", optional = true } webpage = { version = "1.6", default-features = false, features = [ "serde", @@ -73,7 +71,6 @@ encoding = { version = "0.2.33", optional = true } jsonwebtoken = { version = "8.3.0", optional = true } # necessary for wasmt compilation getrandom = { version = "0.2.12", features = ["js"] } -task-local-extensions = "0.1.4" [package.metadata.cargo-machete] ignored = ["getrandom"] diff --git a/crates/api_common/src/context.rs b/crates/api_common/src/context.rs index 8d8dc5013..ba9eb4074 100644 --- a/crates/api_common/src/context.rs +++ b/crates/api_common/src/context.rs @@ -1,6 +1,5 @@ use crate::request::client_builder; use activitypub_federation::config::{Data, FederationConfig}; -use anyhow::anyhow; use lemmy_db_schema::{ source::secret::Secret, utils::{build_db_pool_for_tests, ActualDbPool, DbPool}, @@ -9,10 +8,8 @@ use lemmy_utils::{ rate_limit::RateLimitCell, settings::{structs::Settings, SETTINGS}, }; -use reqwest::{Request, Response}; -use reqwest_middleware::{ClientBuilder, ClientWithMiddleware, Middleware, Next}; +use reqwest_middleware::{ClientBuilder, ClientWithMiddleware}; use std::sync::Arc; -use task_local_extensions::Extensions; #[derive(Clone)] pub struct LemmyContext { @@ -55,32 +52,16 @@ impl LemmyContext { &self.rate_limit_cell } - /// Initialize a context for use in tests, optionally blocks network requests. + /// Initialize a context for use in tests which blocks federation network calls. /// /// Do not use this in production code. pub async fn init_test_context() -> Data { - Self::build_test_context(true).await - } - - /// Initialize a context for use in tests, with network requests allowed. - /// TODO: get rid of this if possible. - /// - /// Do not use this in production code. - pub async fn init_test_context_with_networking() -> Data { - Self::build_test_context(false).await - } - - async fn build_test_context(block_networking: bool) -> Data { // call this to run migrations let pool = build_db_pool_for_tests().await; let client = client_builder(&SETTINGS).build().expect("build client"); - let mut client = ClientBuilder::new(client); - if block_networking { - client = client.with(BlockedMiddleware); - } - let client = client.build(); + let client = ClientBuilder::new(client).build(); let secret = Secret { id: 0, jwt_secret: String::new(), @@ -92,24 +73,11 @@ impl LemmyContext { let config = FederationConfig::builder() .domain(context.settings().hostname.clone()) .app_data(context) + // Dont allow any network fetches + .http_fetch_limit(0) .build() .await .expect("build federation config"); config.to_request_data() } } - -struct BlockedMiddleware; - -/// A reqwest middleware which blocks all requests -#[async_trait::async_trait] -impl Middleware for BlockedMiddleware { - async fn handle( - &self, - _req: Request, - _extensions: &mut Extensions, - _next: Next<'_>, - ) -> reqwest_middleware::Result { - Err(anyhow!("Network requests not allowed").into()) - } -} diff --git a/crates/api_common/src/request.rs b/crates/api_common/src/request.rs index 1eab50bc5..d3e307da5 100644 --- a/crates/api_common/src/request.rs +++ b/crates/api_common/src/request.rs @@ -327,7 +327,7 @@ mod tests { #[tokio::test] #[serial] async fn test_link_metadata() { - let context = LemmyContext::init_test_context_with_networking().await; + let context = LemmyContext::init_test_context().await; let sample_url = Url::parse("https://gitlab.com/IzzyOnDroid/repo/-/wikis/FAQ").unwrap(); let sample_res = fetch_link_metadata(&sample_url, false, &context) .await diff --git a/crates/apub/assets/mastodon/objects/page.json b/crates/apub/assets/mastodon/objects/page.json index ec4c13080..2965b4b8d 100644 --- a/crates/apub/assets/mastodon/objects/page.json +++ b/crates/apub/assets/mastodon/objects/page.json @@ -11,21 +11,21 @@ "votersCount": "toot:votersCount" } ], - "id": "https://dice.camp/users/thekernelinyellow/statuses/110830743680706519", + "id": "https://masto.qa.urbanwildlife.biz/users/mastodon/statuses/110830743680706519", "type": "Note", "summary": null, "inReplyTo": null, "published": "2023-08-04T09:55:39Z", - "url": "https://dice.camp/@thekernelinyellow/110830743680706519", - "attributedTo": "https://dice.camp/users/thekernelinyellow", + "url": "https://masto.qa.urbanwildlife.biz/110830743680706519", + "attributedTo": "https://masto.qa.urbanwildlife.biz/users/mastodon", "to": ["https://www.w3.org/ns/activitystreams#Public"], "cc": [ - "https://dice.camp/users/thekernelinyellow/followers", + "https://masto.qa.urbanwildlife.biz/users/mastodon/followers", "https://enterprise.lemmy.ml/c/tenforward", "https://enterprise.lemmy.ml/c/tenforward/followers" ], "sensitive": false, - "atomUri": "https://dice.camp/users/thekernelinyellow/statuses/110830743680706519", + "atomUri": "https://masto.qa.urbanwildlife.biz/statuses/110830743680706519", "inReplyToAtomUri": null, "conversation": "tag:dice.camp,2023-08-04:objectId=29969291:objectType=Conversation", "content": "

@tenforward Variable never resetting at refresh

Hi! I'm using a variable to count elements in my generator but every time I generate a new character, the counter's value carries on from the previous one. Is there a function to reset it (I set it to 0 at the beginning of the file)

", @@ -41,12 +41,12 @@ } ], "replies": { - "id": "https://dice.camp/users/thekernelinyellow/statuses/110830743680706519/replies", + "id": "https://masto.qa.urbanwildlife.biz/users/mastodon/statuses/110830743680706519/replies", "type": "Collection", "first": { "type": "CollectionPage", - "next": "https://dice.camp/users/thekernelinyellow/statuses/110830743680706519/replies?only_other_accounts=true&page=true", - "partOf": "https://dice.camp/users/thekernelinyellow/statuses/110830743680706519/replies", + "next": "https://masto.qa.urbanwildlife.biz/users/mastodon/statuses/110830743680706519/replies?only_other_accounts=true&page=true", + "partOf": "https://masto.qa.urbanwildlife.biz/users/mastodon/statuses/110830743680706519/replies", "items": [] } } diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index 47d7f53c6..8b8ae093b 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -302,8 +302,7 @@ mod tests { use super::*; use crate::{ objects::{ - community::{tests::parse_lemmy_community, ApubCommunity}, - instance::ApubSite, + community::tests::parse_lemmy_community, person::{tests::parse_lemmy_person, ApubPerson}, }, protocol::tests::file_to_json_object, @@ -333,7 +332,10 @@ mod tests { assert!(!post.featured_community); assert_eq!(context.request_count(), 0); - cleanup(&context, person, site, community, post).await?; + Post::delete(&mut context.pool(), post.id).await?; + Person::delete(&mut context.pool(), person.id).await?; + Community::delete(&mut context.pool(), community.id).await?; + Site::delete(&mut context.pool(), site.id).await?; Ok(()) } @@ -341,29 +343,19 @@ mod tests { #[serial] async fn test_convert_mastodon_post_title() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; - let (person, site) = parse_lemmy_person(&context).await?; let community = parse_lemmy_community(&context).await?; + let json = file_to_json_object("assets/mastodon/objects/person.json")?; + let person = ApubPerson::from_json(json, &context).await?; + let json = file_to_json_object("assets/mastodon/objects/page.json")?; let post = ApubPost::from_json(json, &context).await?; assert_eq!(post.name, "Variable never resetting at refresh"); - cleanup(&context, person, site, community, post).await?; - Ok(()) - } - - async fn cleanup( - context: &Data, - person: ApubPerson, - site: ApubSite, - community: ApubCommunity, - post: ApubPost, - ) -> LemmyResult<()> { Post::delete(&mut context.pool(), post.id).await?; Person::delete(&mut context.pool(), person.id).await?; Community::delete(&mut context.pool(), community.id).await?; - Site::delete(&mut context.pool(), site.id).await?; Ok(()) } } diff --git a/crates/routes/src/webfinger.rs b/crates/routes/src/webfinger.rs index ffceb4028..b9da07c56 100644 --- a/crates/routes/src/webfinger.rs +++ b/crates/routes/src/webfinger.rs @@ -1,6 +1,6 @@ use activitypub_federation::{ config::Data, - fetch::webfinger::{extract_webfinger_name, Webfinger, WebfingerLink}, + fetch::webfinger::{extract_webfinger_name, Webfinger, WebfingerLink, WEBFINGER_CONTENT_TYPE}, }; use actix_web::{web, web::Query, HttpResponse}; use lemmy_api_common::context::LemmyContext; @@ -70,7 +70,11 @@ async fn get_webfinger_response( ..Default::default() }; - Ok(HttpResponse::Ok().json(json)) + Ok( + HttpResponse::Ok() + .content_type(&WEBFINGER_CONTENT_TYPE) + .json(json), + ) } fn webfinger_link_for_actor( From f228f9d7a9b34ea5f19ed9f14bf5874771533b14 Mon Sep 17 00:00:00 2001 From: battmdpkq <134909256+battmdpkq@users.noreply.github.com> Date: Fri, 8 Mar 2024 17:38:20 +0800 Subject: [PATCH 03/31] fix some typos (#4519) Signed-off-by: battmdpkq --- crates/api_common/src/build_response.rs | 2 +- crates/apub/src/http/community.rs | 2 +- crates/db_schema/src/source/mod.rs | 2 +- crates/utils/src/rate_limit/rate_limiter.rs | 2 +- crates/utils/src/utils/validation.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/api_common/src/build_response.rs b/crates/api_common/src/build_response.rs index 5ca819334..6fb96e113 100644 --- a/crates/api_common/src/build_response.rs +++ b/crates/api_common/src/build_response.rs @@ -87,7 +87,7 @@ pub async fn build_post_response( Ok(Json(PostResponse { post_view })) } -// TODO: this function is a mess and should be split up to handle email seperately +// TODO: this function is a mess and should be split up to handle email separately #[tracing::instrument(skip_all)] pub async fn send_local_notifs( mentions: Vec, diff --git a/crates/apub/src/http/community.rs b/crates/apub/src/http/community.rs index 73e620dbe..83ccdacf9 100644 --- a/crates/apub/src/http/community.rs +++ b/crates/apub/src/http/community.rs @@ -72,7 +72,7 @@ pub(crate) async fn get_apub_community_followers( } /// Returns the community outbox, which is populated by a maximum of 20 posts (but no other -/// activites like votes or comments). +/// activities like votes or comments). pub(crate) async fn get_apub_community_outbox( info: web::Path, context: Data, diff --git a/crates/db_schema/src/source/mod.rs b/crates/db_schema/src/source/mod.rs index 9a6e4941a..bccb7c8ce 100644 --- a/crates/db_schema/src/source/mod.rs +++ b/crates/db_schema/src/source/mod.rs @@ -44,6 +44,6 @@ pub mod tagline; /// value is not sent by Lemmy. Necessary for crates which rely on Rust API such as lemmy-stats-crawler. fn placeholder_apub_url() -> DbUrl { DbUrl(Box::new( - Url::parse("http://example.com").expect("parse placeholer url"), + Url::parse("http://example.com").expect("parse placeholder url"), )) } diff --git a/crates/utils/src/rate_limit/rate_limiter.rs b/crates/utils/src/rate_limit/rate_limiter.rs index 7c68003d8..d452fcbb3 100644 --- a/crates/utils/src/rate_limit/rate_limiter.rs +++ b/crates/utils/src/rate_limit/rate_limiter.rs @@ -212,7 +212,7 @@ impl RateLimitedGroup { now: InstantSecs, config: BucketConfig, ) -> bool { - #[allow(clippy::indexing_slicing)] // `EnumMap` has no `get` funciton + #[allow(clippy::indexing_slicing)] // `EnumMap` has no `get` function let bucket = &mut self.total[action_type]; let new_bucket = bucket.update(now, config); diff --git a/crates/utils/src/utils/validation.rs b/crates/utils/src/utils/validation.rs index da989a61b..23ef9744a 100644 --- a/crates/utils/src/utils/validation.rs +++ b/crates/utils/src/utils/validation.rs @@ -204,7 +204,7 @@ pub fn site_description_length_check(description: &str) -> LemmyResult<()> { ) } -/// Check minumum and maximum length of input string. If the string is too short or too long, the +/// Check minimum and maximum length of input string. If the string is too short or too long, the /// corresponding error is returned. /// /// HTML frontends specify maximum input length using `maxlength` attribute. From bc2e75d5a3825b3f1f135b607437815086584add Mon Sep 17 00:00:00 2001 From: Nutomic Date: Fri, 8 Mar 2024 16:16:05 +0100 Subject: [PATCH 04/31] Add @dullbananas to codeowners (#4521) --- .github/CODEOWNERS | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 3d1bd7c72..cdf891126 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,3 +1,3 @@ -* @Nutomic @dessalines @phiresky +* @Nutomic @dessalines @phiresky @dullbananas crates/apub/ @Nutomic -migrations/ @dessalines @phiresky +migrations/ @dessalines @phiresky @dullbananas From 00f7778485168039d038e2596323b833f229d33b Mon Sep 17 00:00:00 2001 From: Nutomic Date: Fri, 8 Mar 2024 16:17:26 +0100 Subject: [PATCH 05/31] Store thumbnails in db table local_image (#4512) * Store thumbnails in db table local_image * fmt --- crates/api_common/src/request.rs | 14 ++++++++++++-- crates/db_schema/src/schema.rs | 2 +- crates/db_schema/src/source/images.rs | 7 ++----- crates/routes/src/images.rs | 2 +- .../down.sql | 3 +++ .../2024-03-06-104706_local_image_user_opt/up.sql | 3 +++ 6 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 migrations/2024-03-06-104706_local_image_user_opt/down.sql create mode 100644 migrations/2024-03-06-104706_local_image_user_opt/up.sql diff --git a/crates/api_common/src/request.rs b/crates/api_common/src/request.rs index d3e307da5..aaae7f866 100644 --- a/crates/api_common/src/request.rs +++ b/crates/api_common/src/request.rs @@ -4,7 +4,10 @@ use crate::{ utils::proxy_image_link, }; use encoding::{all::encodings, DecoderTrap}; -use lemmy_db_schema::newtypes::DbUrl; +use lemmy_db_schema::{ + newtypes::DbUrl, + source::images::{LocalImage, LocalImageForm}, +}; use lemmy_utils::{ error::{LemmyError, LemmyErrorType}, settings::structs::{PictrsImageMode, Settings}, @@ -184,7 +187,6 @@ struct PictrsResponse { #[derive(Deserialize, Debug)] struct PictrsFile { file: String, - #[allow(dead_code)] delete_token: String, } @@ -287,6 +289,14 @@ async fn generate_pictrs_thumbnail( context.settings().get_protocol_and_hostname(), response.files.first().expect("missing pictrs file").file ))?; + for uploaded_image in response.files { + let form = LocalImageForm { + local_user_id: None, + pictrs_alias: uploaded_image.file.to_string(), + pictrs_delete_token: uploaded_image.delete_token.to_string(), + }; + LocalImage::create(&mut context.pool(), &form).await?; + } Ok(thumbnail_url) } else { Err(LemmyErrorType::PictrsResponseError(response.msg))? diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index 739ff8482..632f7d0bb 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -342,7 +342,7 @@ diesel::table! { diesel::table! { local_image (pictrs_alias) { - local_user_id -> Int4, + local_user_id -> Nullable, pictrs_alias -> Text, pictrs_delete_token -> Text, published -> Timestamptz, diff --git a/crates/db_schema/src/source/images.rs b/crates/db_schema/src/source/images.rs index f8befb856..3bf2a5bb8 100644 --- a/crates/db_schema/src/source/images.rs +++ b/crates/db_schema/src/source/images.rs @@ -2,11 +2,9 @@ use crate::newtypes::{DbUrl, LocalUserId}; #[cfg(feature = "full")] use crate::schema::{local_image, remote_image}; use chrono::{DateTime, Utc}; -use serde_with::skip_serializing_none; use std::fmt::Debug; use typed_builder::TypedBuilder; -#[skip_serializing_none] #[derive(PartialEq, Eq, Debug, Clone)] #[cfg_attr(feature = "full", derive(Queryable, Associations))] #[cfg_attr(feature = "full", diesel(table_name = local_image))] @@ -15,7 +13,7 @@ use typed_builder::TypedBuilder; diesel(belongs_to(crate::source::local_user::LocalUser)) )] pub struct LocalImage { - pub local_user_id: LocalUserId, + pub local_user_id: Option, pub pictrs_alias: String, pub pictrs_delete_token: String, pub published: DateTime, @@ -25,14 +23,13 @@ pub struct LocalImage { #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = local_image))] pub struct LocalImageForm { - pub local_user_id: LocalUserId, + pub local_user_id: Option, pub pictrs_alias: String, pub pictrs_delete_token: String, } /// Stores all images which are hosted on remote domains. When attempting to proxy an image, it /// is checked against this table to avoid Lemmy being used as a general purpose proxy. -#[skip_serializing_none] #[derive(PartialEq, Eq, Debug, Clone)] #[cfg_attr(feature = "full", derive(Queryable, Identifiable))] #[cfg_attr(feature = "full", diesel(table_name = remote_image))] diff --git a/crates/routes/src/images.rs b/crates/routes/src/images.rs index f40b3c10c..58ca9c8ef 100644 --- a/crates/routes/src/images.rs +++ b/crates/routes/src/images.rs @@ -114,7 +114,7 @@ async fn upload( if let Some(images) = &images.files { for uploaded_image in images { let form = LocalImageForm { - local_user_id: local_user_view.local_user.id, + local_user_id: Some(local_user_view.local_user.id), pictrs_alias: uploaded_image.file.to_string(), pictrs_delete_token: uploaded_image.delete_token.to_string(), }; diff --git a/migrations/2024-03-06-104706_local_image_user_opt/down.sql b/migrations/2024-03-06-104706_local_image_user_opt/down.sql new file mode 100644 index 000000000..45d890467 --- /dev/null +++ b/migrations/2024-03-06-104706_local_image_user_opt/down.sql @@ -0,0 +1,3 @@ +ALTER TABLE local_image + ALTER COLUMN local_user_id SET NOT NULL; + diff --git a/migrations/2024-03-06-104706_local_image_user_opt/up.sql b/migrations/2024-03-06-104706_local_image_user_opt/up.sql new file mode 100644 index 000000000..b80098161 --- /dev/null +++ b/migrations/2024-03-06-104706_local_image_user_opt/up.sql @@ -0,0 +1,3 @@ +ALTER TABLE local_image + ALTER COLUMN local_user_id DROP NOT NULL; + From 5859502a2a788bf8160ecdaeb79ed24a06f98729 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Fri, 8 Mar 2024 16:23:15 +0100 Subject: [PATCH 06/31] Fix missing private key for signed fetch (#4516) * Fix missing private key for signed fetch (fixes #4451) * clippy * instance actor name and webfinger * better webfinger handling * upgrade lib * update test asset --- Cargo.lock | 6 +- Cargo.toml | 2 +- .../apub/assets/lemmy/objects/instance.json | 1 + crates/apub/src/objects/instance.rs | 1 + crates/apub/src/protocol/objects/instance.rs | 4 +- crates/db_schema/src/source/site.rs | 2 + crates/db_views/src/site_view.rs | 7 +- crates/routes/src/webfinger.rs | 75 +++++++++++-------- 8 files changed, 55 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e4c55f082..b9ebfa540 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,9 +16,9 @@ checksum = "8f27d075294830fcab6f66e320dab524bc6d048f4a151698e153205559113772" [[package]] name = "activitypub_federation" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eee115a53849bbcac6c953495b5f9322b56680c0a1bdef6813183f0453f9ee3c" +checksum = "a028034c642d3ed16b535f98f48b3df30397833c183d68852d79de16650d5ed5" dependencies = [ "activitystreams-kinds", "actix-web", @@ -2577,7 +2577,6 @@ version = "0.19.3" dependencies = [ "activitypub_federation", "actix-web", - "anyhow", "chrono", "encoding", "enum-map", @@ -2599,7 +2598,6 @@ dependencies = [ "serde", "serde_with", "serial_test", - "task-local-extensions", "tokio", "tracing", "ts-rs", diff --git a/Cargo.toml b/Cargo.toml index 037d03919..5e0cdb16e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -96,7 +96,7 @@ lemmy_routes = { version = "=0.19.3", path = "./crates/routes" } lemmy_db_views = { version = "=0.19.3", path = "./crates/db_views" } lemmy_db_views_actor = { version = "=0.19.3", path = "./crates/db_views_actor" } lemmy_db_views_moderator = { version = "=0.19.3", path = "./crates/db_views_moderator" } -activitypub_federation = { version = "0.5.1", default-features = false, features = [ +activitypub_federation = { version = "0.5.2", default-features = false, features = [ "actix-web", ] } diesel = "2.1.4" diff --git a/crates/apub/assets/lemmy/objects/instance.json b/crates/apub/assets/lemmy/objects/instance.json index 1e07043d9..92053bac6 100644 --- a/crates/apub/assets/lemmy/objects/instance.json +++ b/crates/apub/assets/lemmy/objects/instance.json @@ -2,6 +2,7 @@ "type": "Application", "id": "https://enterprise.lemmy.ml/", "name": "Enterprise", + "preferredUsername": "enterprise.lemmy.ml", "summary": "A test instance", "content": "

Enterprise sidebar

\\n", "mediaType": "text/html", diff --git a/crates/apub/src/objects/instance.rs b/crates/apub/src/objects/instance.rs index 165378ab6..8f4f163db 100644 --- a/crates/apub/src/objects/instance.rs +++ b/crates/apub/src/objects/instance.rs @@ -96,6 +96,7 @@ impl Object for ApubSite { kind: ApplicationType::Application, id: self.id().into(), name: self.name.clone(), + preferred_username: data.domain().to_string(), content: self.sidebar.as_ref().map(|d| markdown_to_html(d)), source: self.sidebar.clone().map(Source::new), summary: self.description.clone(), diff --git a/crates/apub/src/protocol/objects/instance.rs b/crates/apub/src/protocol/objects/instance.rs index 17623719c..8f6a0f368 100644 --- a/crates/apub/src/protocol/objects/instance.rs +++ b/crates/apub/src/protocol/objects/instance.rs @@ -19,8 +19,10 @@ pub struct Instance { #[serde(rename = "type")] pub(crate) kind: ApplicationType, pub(crate) id: ObjectId, - // site name + /// site name pub(crate) name: String, + /// instance domain, necessary for mastodon authorized fetch + pub(crate) preferred_username: String, pub(crate) inbox: Url, /// mandatory field in activitypub, lemmy currently serves an empty outbox pub(crate) outbox: Url, diff --git a/crates/db_schema/src/source/site.rs b/crates/db_schema/src/source/site.rs index 754acb2aa..40ba14f96 100644 --- a/crates/db_schema/src/source/site.rs +++ b/crates/db_schema/src/source/site.rs @@ -34,7 +34,9 @@ pub struct Site { pub last_refreshed_at: DateTime, /// The site inbox pub inbox_url: DbUrl, + #[serde(skip)] pub private_key: Option, + #[serde(skip)] pub public_key: String, pub instance_id: InstanceId, /// If present, nsfw content is visible by default. Should be displayed by frontends/clients diff --git a/crates/db_views/src/site_view.rs b/crates/db_views/src/site_view.rs index 17819fdd7..52074c982 100644 --- a/crates/db_views/src/site_view.rs +++ b/crates/db_views/src/site_view.rs @@ -9,7 +9,7 @@ use lemmy_db_schema::{ impl SiteView { pub async fn read_local(pool: &mut DbPool<'_>) -> Result { let conn = &mut get_conn(pool).await?; - let mut res = site::table + site::table .inner_join(local_site::table) .inner_join( local_site_rate_limit::table.on(local_site::id.eq(local_site_rate_limit::local_site_id)), @@ -22,9 +22,6 @@ impl SiteView { site_aggregates::all_columns, )) .first::(conn) - .await?; - - res.site.private_key = None; - Ok(res) + .await } } diff --git a/crates/routes/src/webfinger.rs b/crates/routes/src/webfinger.rs index b9da07c56..95092b244 100644 --- a/crates/routes/src/webfinger.rs +++ b/crates/routes/src/webfinger.rs @@ -38,43 +38,54 @@ async fn get_webfinger_response( ) -> Result { let name = extract_webfinger_name(&info.resource, &context)?; - let user_id: Option = Person::read_from_name(&mut context.pool(), name, false) - .await - .ok() - .map(|c| c.actor_id.into()); - let community_id: Option = Community::read_from_name(&mut context.pool(), name, false) - .await - .ok() - .and_then(|c| { - if c.visibility == CommunityVisibility::Public { - let id: Url = c.actor_id.into(); - Some(id) - } else { - None - } - }); + let links = if name == context.settings().hostname { + // webfinger response for instance actor (required for mastodon authorized fetch) + let url = Url::parse(&context.settings().get_protocol_and_hostname())?; + vec![webfinger_link_for_actor(Some(url), "none", &context)] + } else { + // webfinger response for user/community + let user_id: Option = Person::read_from_name(&mut context.pool(), name, false) + .await + .ok() + .map(|c| c.actor_id.into()); + let community_id: Option = Community::read_from_name(&mut context.pool(), name, false) + .await + .ok() + .and_then(|c| { + if c.visibility == CommunityVisibility::Public { + let id: Url = c.actor_id.into(); + Some(id) + } else { + None + } + }); - // Mastodon seems to prioritize the last webfinger item in case of duplicates. Put - // community last so that it gets prioritized. For Lemmy the order doesnt matter. - let links = vec![ - webfinger_link_for_actor(user_id, "Person", &context), - webfinger_link_for_actor(community_id, "Group", &context), - ] + // Mastodon seems to prioritize the last webfinger item in case of duplicates. Put + // community last so that it gets prioritized. For Lemmy the order doesnt matter. + vec![ + webfinger_link_for_actor(user_id, "Person", &context), + webfinger_link_for_actor(community_id, "Group", &context), + ] + } .into_iter() .flatten() - .collect(); + .collect::>(); - let json = Webfinger { - subject: info.resource.clone(), - links, - ..Default::default() - }; + if links.is_empty() { + Ok(HttpResponse::NotFound().finish()) + } else { + let json = Webfinger { + subject: info.resource.clone(), + links, + ..Default::default() + }; - Ok( - HttpResponse::Ok() - .content_type(&WEBFINGER_CONTENT_TYPE) - .json(json), - ) + Ok( + HttpResponse::Ok() + .content_type(&WEBFINGER_CONTENT_TYPE) + .json(json), + ) + } } fn webfinger_link_for_actor( From 10bf7464b1b22227ae3fa246a9cd6327a2617aaf Mon Sep 17 00:00:00 2001 From: Dessalines Date: Fri, 8 Mar 2024 11:53:57 -0500 Subject: [PATCH 07/31] Add code of conduct rules to issue template. (#4523) --- .github/ISSUE_TEMPLATE/BUG_REPORT.yml | 2 ++ .github/ISSUE_TEMPLATE/FEATURE_REQUEST.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.github/ISSUE_TEMPLATE/BUG_REPORT.yml b/.github/ISSUE_TEMPLATE/BUG_REPORT.yml index a4028afd0..3d3caa261 100644 --- a/.github/ISSUE_TEMPLATE/BUG_REPORT.yml +++ b/.github/ISSUE_TEMPLATE/BUG_REPORT.yml @@ -20,6 +20,8 @@ body: required: true - label: Is this only a single bug? Do not put multiple bugs in one issue. required: true + - label: Do you agree to follow the rules in our [Code of Conduct](https://join-lemmy.org/docs/code_of_conduct.html)? + required: true - label: Is this a backend issue? Use the [lemmy-ui](https://github.com/LemmyNet/lemmy-ui) repo for UI / frontend issues. required: true - type: textarea diff --git a/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.yml b/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.yml index 40ef2caf3..f50a93ff2 100644 --- a/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.yml +++ b/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.yml @@ -20,6 +20,8 @@ body: required: true - label: Is this a backend issue? Use the [lemmy-ui](https://github.com/LemmyNet/lemmy-ui) repo for UI / frontend issues. required: true + - label: Do you agree to follow the rules in our [Code of Conduct](https://join-lemmy.org/docs/code_of_conduct.html)? + required: true - type: textarea id: problem attributes: From 5d361d63ef86ed4e136b123a115a951f560be0f3 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Mon, 11 Mar 2024 21:27:05 +0100 Subject: [PATCH 08/31] Change 2FA to use hostname as issuer (fixes #4518) (#4525) --- crates/api/src/lib.rs | 10 +++------- crates/api/src/local_user/login.rs | 6 +++++- crates/api/src/local_user/update_totp.rs | 6 ++---- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/crates/api/src/lib.rs b/crates/api/src/lib.rs index fda0bea6f..814dd67eb 100644 --- a/crates/api/src/lib.rs +++ b/crates/api/src/lib.rs @@ -135,11 +135,7 @@ pub(crate) fn generate_totp_2fa_secret() -> String { Secret::generate_secret().to_string() } -pub(crate) fn build_totp_2fa( - site_name: &str, - username: &str, - secret: &str, -) -> Result { +fn build_totp_2fa(hostname: &str, username: &str, secret: &str) -> Result { let sec = Secret::Raw(secret.as_bytes().to_vec()); let sec_bytes = sec .to_bytes() @@ -151,7 +147,7 @@ pub(crate) fn build_totp_2fa( 1, 30, sec_bytes, - Some(site_name.to_string()), + Some(hostname.to_string()), username.to_string(), ) .with_lemmy_type(LemmyErrorType::CouldntGenerateTotp) @@ -272,7 +268,7 @@ mod tests { #[test] fn test_build_totp() { let generated_secret = generate_totp_2fa_secret(); - let totp = build_totp_2fa("lemmy", "my_name", &generated_secret); + let totp = build_totp_2fa("lemmy.ml", "my_name", &generated_secret); assert!(totp.is_ok()); } } diff --git a/crates/api/src/local_user/login.rs b/crates/api/src/local_user/login.rs index 1fe337f3c..4eae762be 100644 --- a/crates/api/src/local_user/login.rs +++ b/crates/api/src/local_user/login.rs @@ -50,7 +50,11 @@ pub async fn login( // Check the totp if enabled if local_user_view.local_user.totp_2fa_enabled { - check_totp_2fa_valid(&local_user_view, &data.totp_2fa_token, &site_view.site.name)?; + check_totp_2fa_valid( + &local_user_view, + &data.totp_2fa_token, + &context.settings().hostname, + )?; } let jwt = Claims::generate(local_user_view.local_user.id, req, &context).await?; diff --git a/crates/api/src/local_user/update_totp.rs b/crates/api/src/local_user/update_totp.rs index 15833ae8a..8f37213e2 100644 --- a/crates/api/src/local_user/update_totp.rs +++ b/crates/api/src/local_user/update_totp.rs @@ -8,7 +8,7 @@ use lemmy_db_schema::{ source::local_user::{LocalUser, LocalUserUpdateForm}, traits::Crud, }; -use lemmy_db_views::structs::{LocalUserView, SiteView}; +use lemmy_db_views::structs::LocalUserView; use lemmy_utils::error::LemmyError; /// Enable or disable two-factor-authentication. The current setting is determined from @@ -25,12 +25,10 @@ pub async fn update_totp( local_user_view: LocalUserView, context: Data, ) -> Result, LemmyError> { - let site_view = SiteView::read_local(&mut context.pool()).await?; - check_totp_2fa_valid( &local_user_view, &Some(data.totp_token.clone()), - &site_view.site.name, + &context.settings().hostname, )?; // toggle the 2fa setting From 45c56df4e8fd30e852a9ca2670ca492d8d18fdad Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 12 Mar 2024 06:24:27 -0400 Subject: [PATCH 09/31] Adding git cliff to help generate changelogs. (#4522) --- cliff.toml | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 cliff.toml diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 000000000..d8975a171 --- /dev/null +++ b/cliff.toml @@ -0,0 +1,86 @@ +# git-cliff ~ configuration file +# https://git-cliff.org/docs/configuration + +[remote.github] +owner = "LemmyNet" +repo = "lemmy" +# token = "" + +[changelog] +# template for the changelog body +# https://keats.github.io/tera/docs/#introduction +body = """ +## What's Changed + +{%- if version %} in {{ version }}{%- endif -%} +{% for commit in commits %} + {% if commit.github.pr_title -%} + {%- set commit_message = commit.github.pr_title -%} + {%- else -%} + {%- set commit_message = commit.message -%} + {%- endif -%} + * {{ commit_message | split(pat="\n") | first | trim }}\ + {% if commit.github.username %} by @{{ commit.github.username }}{%- endif -%} + {% if commit.github.pr_number %} in \ + [#{{ commit.github.pr_number }}]({{ self::remote_url() }}/pull/{{ commit.github.pr_number }}) \ + {%- endif %} +{%- endfor -%} + +{% if github.contributors | filter(attribute="is_first_time", value=true) | length != 0 %} + {% raw %}\n{% endraw -%} + ## New Contributors +{%- endif %}\ +{% for contributor in github.contributors | filter(attribute="is_first_time", value=true) %} + * @{{ contributor.username }} made their first contribution + {%- if contributor.pr_number %} in \ + [#{{ contributor.pr_number }}]({{ self::remote_url() }}/pull/{{ contributor.pr_number }}) \ + {%- endif %} +{%- endfor -%} + +{% if version %} + {% if previous.version %} + **Full Changelog**: {{ self::remote_url() }}/compare/{{ previous.version }}...{{ version }} + {% endif %} +{% else -%} + {% raw %}\n{% endraw %} +{% endif %} + +{%- macro remote_url() -%} + https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }} +{%- endmacro -%} +""" +# remove the leading and trailing whitespace from the template +trim = true +# changelog footer +footer = """ + +""" +# postprocessors +postprocessors = [] + +[git] +# parse the commits based on https://www.conventionalcommits.org +conventional_commits = false +# filter out the commits that are not conventional +filter_unconventional = true +# process each line of a commit as an individual commit +split_commits = false +# regex for preprocessing the commit messages +commit_preprocessors = [ + # remove issue numbers from commits + { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "" }, +] +# protect breaking changes from being skipped due to matching a skipping commit_parser +protect_breaking_commits = false +# filter out the commits that are not matched by commit parsers +filter_commits = false +# regex for matching git tags +tag_pattern = "[0-9].*" +# regex for skipping tags +skip_tags = "beta|alpha" +# regex for ignoring tags +ignore_tags = "rc" +# sort the tags topologically +topo_order = false +# sort the commits inside sections by oldest/newest order +sort_commits = "newest" From 15f02f00a95d3d31ee1ec91c089e370daef7b59f Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 13 Mar 2024 12:10:58 -0400 Subject: [PATCH 10/31] Add a vote_display_mode local_user setting. (#4450) * Add a vote_display_mode local_user setting. - Fixes #4449 * Changing HideDownvotes to Score. * Adding ScoreAndDownvote display mode. * Adding upvote and downvote mode. * Extracting vote_display_mode to another table. * Fixing fmt. * Remove published and updated columns. --------- Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com> --- crates/api/src/local_user/save_settings.rs | 11 ++++ crates/api_common/src/person.rs | 8 ++- crates/api_crud/src/user/create.rs | 2 + crates/apub/src/api/user_settings_backup.rs | 24 ++++++++ crates/db_schema/src/impls/local_user.rs | 7 +++ .../src/impls/local_user_vote_display_mode.rs | 57 +++++++++++++++++++ crates/db_schema/src/impls/mod.rs | 1 + crates/db_schema/src/schema.rs | 12 ++++ crates/db_schema/src/source/local_user.rs | 2 + .../source/local_user_vote_display_mode.rs | 51 +++++++++++++++++ crates/db_schema/src/source/mod.rs | 1 + crates/db_views/src/comment_report_view.rs | 2 + crates/db_views/src/comment_view.rs | 2 + crates/db_views/src/local_user_view.rs | 9 ++- crates/db_views/src/post_report_view.rs | 2 + crates/db_views/src/post_view.rs | 3 + crates/db_views/src/structs.rs | 2 + .../down.sql | 2 + .../up.sql | 18 ++++++ 19 files changed, 211 insertions(+), 5 deletions(-) create mode 100644 crates/db_schema/src/impls/local_user_vote_display_mode.rs create mode 100644 crates/db_schema/src/source/local_user_vote_display_mode.rs create mode 100644 migrations/2024-02-12-211114_add_vote_display_mode_setting/down.sql create mode 100644 migrations/2024-02-12-211114_add_vote_display_mode_setting/up.sql diff --git a/crates/api/src/local_user/save_settings.rs b/crates/api/src/local_user/save_settings.rs index 79b95133e..d918bdc00 100644 --- a/crates/api/src/local_user/save_settings.rs +++ b/crates/api/src/local_user/save_settings.rs @@ -14,6 +14,7 @@ use lemmy_db_schema::{ source::{ actor_language::LocalUserLanguage, local_user::{LocalUser, LocalUserUpdateForm}, + local_user_vote_display_mode::{LocalUserVoteDisplayMode, LocalUserVoteDisplayModeUpdateForm}, person::{Person, PersonUpdateForm}, }, traits::Crud, @@ -136,5 +137,15 @@ pub async fn save_user_settings( .await .ok(); + // Update the vote display modes + let vote_display_modes_form = LocalUserVoteDisplayModeUpdateForm { + score: data.show_scores, + upvotes: data.show_upvotes, + downvotes: data.show_downvotes, + upvote_percentage: data.show_upvote_percentage, + }; + LocalUserVoteDisplayMode::update(&mut context.pool(), local_user_id, &vote_display_modes_form) + .await?; + Ok(Json(SuccessResponse::default())) } diff --git a/crates/api_common/src/person.rs b/crates/api_common/src/person.rs index c5011d2f9..7af966164 100644 --- a/crates/api_common/src/person.rs +++ b/crates/api_common/src/person.rs @@ -86,8 +86,6 @@ pub struct SaveUserSettings { pub show_nsfw: Option, pub blur_nsfw: Option, pub auto_expand: Option, - /// Show post and comment scores. - pub show_scores: Option, /// Your user's theme. pub theme: Option, pub default_sort_type: Option, @@ -122,6 +120,7 @@ pub struct SaveUserSettings { pub open_links_in_new_tab: Option, /// Enable infinite scroll pub infinite_scroll_enabled: Option, + /// A post-view mode that changes how multiple post listings look. pub post_listing_mode: Option, /// Whether to allow keyboard navigation (for browsing and interacting with posts and comments). pub enable_keyboard_navigation: Option, @@ -129,6 +128,11 @@ pub struct SaveUserSettings { pub enable_animated_images: Option, /// Whether to auto-collapse bot comments. pub collapse_bot_comments: Option, + /// Some vote display mode settings + pub show_scores: Option, + pub show_upvotes: Option, + pub show_downvotes: Option, + pub show_upvote_percentage: Option, } #[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] diff --git a/crates/api_crud/src/user/create.rs b/crates/api_crud/src/user/create.rs index 50df1edbf..29e16cb20 100644 --- a/crates/api_crud/src/user/create.rs +++ b/crates/api_crud/src/user/create.rs @@ -21,6 +21,7 @@ use lemmy_db_schema::{ source::{ captcha_answer::{CaptchaAnswer, CheckCaptchaAnswer}, local_user::{LocalUser, LocalUserInsertForm}, + local_user_vote_display_mode::LocalUserVoteDisplayMode, person::{Person, PersonInsertForm}, registration_application::{RegistrationApplication, RegistrationApplicationInsertForm}, }, @@ -183,6 +184,7 @@ pub async fn register( if local_site.require_email_verification { let local_user_view = LocalUserView { local_user: inserted_local_user, + local_user_vote_display_mode: LocalUserVoteDisplayMode::default(), person: inserted_person, counts: PersonAggregates::default(), }; diff --git a/crates/apub/src/api/user_settings_backup.rs b/crates/apub/src/api/user_settings_backup.rs index ebe2940d4..a2e6c55ac 100644 --- a/crates/apub/src/api/user_settings_backup.rs +++ b/crates/apub/src/api/user_settings_backup.rs @@ -17,6 +17,7 @@ use lemmy_db_schema::{ instance::Instance, instance_block::{InstanceBlock, InstanceBlockForm}, local_user::{LocalUser, LocalUserUpdateForm}, + local_user_vote_display_mode::{LocalUserVoteDisplayMode, LocalUserVoteDisplayModeUpdateForm}, person::{Person, PersonUpdateForm}, person_block::{PersonBlock, PersonBlockForm}, post::{PostSaved, PostSavedForm}, @@ -50,6 +51,7 @@ pub struct UserSettingsBackup { // TODO: might be worth making a separate struct for settings backup, to avoid breakage in case // fields are renamed, and to avoid storing unnecessary fields like person_id or email pub settings: Option, + pub vote_display_mode_settings: Option, #[serde(default)] pub followed_communities: Vec>, #[serde(default)] @@ -80,6 +82,7 @@ pub async fn export_settings( matrix_id: local_user_view.person.matrix_user_id, bot_account: local_user_view.person.bot_account.into(), settings: Some(local_user_view.local_user), + vote_display_mode_settings: Some(local_user_view.local_user_vote_display_mode), followed_communities: vec_into(lists.followed_communities), blocked_communities: vec_into(lists.blocked_communities), blocked_instances: lists.blocked_instances, @@ -132,6 +135,27 @@ pub async fn import_settings( ) .await?; + // Update the vote display mode settings + let vote_display_mode_form = LocalUserVoteDisplayModeUpdateForm { + score: data.vote_display_mode_settings.as_ref().map(|s| s.score), + upvotes: data.vote_display_mode_settings.as_ref().map(|s| s.upvotes), + downvotes: data + .vote_display_mode_settings + .as_ref() + .map(|s| s.downvotes), + upvote_percentage: data + .vote_display_mode_settings + .as_ref() + .map(|s| s.upvote_percentage), + }; + + LocalUserVoteDisplayMode::update( + &mut context.pool(), + local_user_view.local_user.id, + &vote_display_mode_form, + ) + .await?; + let url_count = data.followed_communities.len() + data.blocked_communities.len() + data.blocked_users.len() diff --git a/crates/db_schema/src/impls/local_user.rs b/crates/db_schema/src/impls/local_user.rs index 14da24bae..14ae65469 100644 --- a/crates/db_schema/src/impls/local_user.rs +++ b/crates/db_schema/src/impls/local_user.rs @@ -4,6 +4,7 @@ use crate::{ source::{ actor_language::{LocalUserLanguage, SiteLanguage}, local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm}, + local_user_vote_display_mode::{LocalUserVoteDisplayMode, LocalUserVoteDisplayModeInsertForm}, }, traits::Crud, utils::{ @@ -211,6 +212,12 @@ impl Crud for LocalUser { LocalUserLanguage::update(pool, vec![], local_user_.id).await?; } + // Create their vote_display_modes + let vote_display_mode_form = LocalUserVoteDisplayModeInsertForm::builder() + .local_user_id(local_user_.id) + .build(); + LocalUserVoteDisplayMode::create(pool, &vote_display_mode_form).await?; + Ok(local_user_) } async fn update( diff --git a/crates/db_schema/src/impls/local_user_vote_display_mode.rs b/crates/db_schema/src/impls/local_user_vote_display_mode.rs new file mode 100644 index 000000000..4458fc1b6 --- /dev/null +++ b/crates/db_schema/src/impls/local_user_vote_display_mode.rs @@ -0,0 +1,57 @@ +use crate::{ + newtypes::LocalUserId, + schema::local_user_vote_display_mode, + source::local_user_vote_display_mode::{ + LocalUserVoteDisplayMode, + LocalUserVoteDisplayModeInsertForm, + LocalUserVoteDisplayModeUpdateForm, + }, + utils::{get_conn, DbPool}, +}; +use diesel::{dsl::insert_into, result::Error, QueryDsl}; +use diesel_async::RunQueryDsl; + +impl LocalUserVoteDisplayMode { + pub async fn read(pool: &mut DbPool<'_>) -> Result { + let conn = &mut get_conn(pool).await?; + local_user_vote_display_mode::table + .first::(conn) + .await + } + + pub async fn create( + pool: &mut DbPool<'_>, + form: &LocalUserVoteDisplayModeInsertForm, + ) -> Result { + let conn = &mut get_conn(pool).await?; + insert_into(local_user_vote_display_mode::table) + .values(form) + .get_result::(conn) + .await + } + pub async fn update( + pool: &mut DbPool<'_>, + local_user_id: LocalUserId, + form: &LocalUserVoteDisplayModeUpdateForm, + ) -> Result<(), Error> { + // avoid error "There are no changes to save. This query cannot be built" + if form.is_empty() { + return Ok(()); + } + let conn = &mut get_conn(pool).await?; + diesel::update(local_user_vote_display_mode::table.find(local_user_id)) + .set(form) + .get_result::(conn) + .await?; + Ok(()) + } +} + +impl LocalUserVoteDisplayModeUpdateForm { + fn is_empty(&self) -> bool { + self.score.is_none() + && self.upvotes.is_none() + && self.downvotes.is_none() + && self.upvote_percentage.is_none() + } +} diff --git a/crates/db_schema/src/impls/mod.rs b/crates/db_schema/src/impls/mod.rs index 6d4549b14..711a6c4e6 100644 --- a/crates/db_schema/src/impls/mod.rs +++ b/crates/db_schema/src/impls/mod.rs @@ -18,6 +18,7 @@ pub mod language; pub mod local_site; pub mod local_site_rate_limit; pub mod local_user; +pub mod local_user_vote_display_mode; pub mod login_token; pub mod moderator; pub mod password_reset_request; diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index 632f7d0bb..a61b2d24f 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -454,6 +454,16 @@ diesel::table! { } } +diesel::table! { + local_user_vote_display_mode (local_user_id) { + local_user_id -> Int4, + score -> Bool, + upvotes -> Bool, + downvotes -> Bool, + upvote_percentage -> Bool, + } +} + diesel::table! { login_token (token) { token -> Text, @@ -961,6 +971,7 @@ diesel::joinable!(local_site_rate_limit -> local_site (local_site_id)); diesel::joinable!(local_user -> person (person_id)); diesel::joinable!(local_user_language -> language (language_id)); diesel::joinable!(local_user_language -> local_user (local_user_id)); +diesel::joinable!(local_user_vote_display_mode -> local_user (local_user_id)); diesel::joinable!(login_token -> local_user (user_id)); diesel::joinable!(mod_add_community -> community (community_id)); diesel::joinable!(mod_ban_from_community -> community (community_id)); @@ -1043,6 +1054,7 @@ diesel::allow_tables_to_appear_in_same_query!( local_site_rate_limit, local_user, local_user_language, + local_user_vote_display_mode, login_token, mod_add, mod_add_community, diff --git a/crates/db_schema/src/source/local_user.rs b/crates/db_schema/src/source/local_user.rs index 97a0921da..f159232f7 100644 --- a/crates/db_schema/src/source/local_user.rs +++ b/crates/db_schema/src/source/local_user.rs @@ -36,6 +36,7 @@ pub struct LocalUser { pub show_avatars: bool, pub send_notifications_to_email: bool, /// Whether to show comment / post scores. + // TODO now that there is a vote_display_mode, this can be gotten rid of in future releases. pub show_scores: bool, /// Whether to show bot accounts. pub show_bot_accounts: bool, @@ -55,6 +56,7 @@ pub struct LocalUser { pub infinite_scroll_enabled: bool, /// Whether the person is an admin. pub admin: bool, + /// A post-view mode that changes how multiple post listings look. pub post_listing_mode: PostListingMode, pub totp_2fa_enabled: bool, /// Whether to allow keyboard navigation (for browsing and interacting with posts and comments). diff --git a/crates/db_schema/src/source/local_user_vote_display_mode.rs b/crates/db_schema/src/source/local_user_vote_display_mode.rs new file mode 100644 index 000000000..314d99e4a --- /dev/null +++ b/crates/db_schema/src/source/local_user_vote_display_mode.rs @@ -0,0 +1,51 @@ +use crate::newtypes::LocalUserId; +#[cfg(feature = "full")] +use crate::schema::local_user_vote_display_mode; +use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; +use typed_builder::TypedBuilder; + +#[skip_serializing_none] +#[derive(PartialEq, Eq, Debug, Clone, Default, Serialize, Deserialize)] +#[cfg_attr(feature = "full", derive(Queryable, Selectable, Identifiable, TS))] +#[cfg_attr(feature = "full", diesel(table_name = local_user_vote_display_mode))] +#[cfg_attr(feature = "full", diesel(primary_key(local_user_id)))] +#[cfg_attr( + feature = "full", + diesel(belongs_to(crate::source::local_site::LocalUser)) +)] +#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))] +#[cfg_attr(feature = "full", ts(export))] +/// The vote display settings for your user. +pub struct LocalUserVoteDisplayMode { + pub local_user_id: LocalUserId, + pub score: bool, + pub upvotes: bool, + pub downvotes: bool, + pub upvote_percentage: bool, +} + +#[derive(Clone, TypedBuilder)] +#[builder(field_defaults(default))] +#[cfg_attr(feature = "full", derive(Insertable))] +#[cfg_attr(feature = "full", diesel(table_name = local_user_vote_display_mode))] +pub struct LocalUserVoteDisplayModeInsertForm { + #[builder(!default)] + pub local_user_id: LocalUserId, + pub score: Option, + pub upvotes: Option, + pub downvotes: Option, + pub upvote_percentage: Option, +} + +#[derive(Clone, Default)] +#[cfg_attr(feature = "full", derive(AsChangeset))] +#[cfg_attr(feature = "full", diesel(table_name = local_user_vote_display_mode))] +pub struct LocalUserVoteDisplayModeUpdateForm { + pub score: Option, + pub upvotes: Option, + pub downvotes: Option, + pub upvote_percentage: Option, +} diff --git a/crates/db_schema/src/source/mod.rs b/crates/db_schema/src/source/mod.rs index bccb7c8ce..ab82a114c 100644 --- a/crates/db_schema/src/source/mod.rs +++ b/crates/db_schema/src/source/mod.rs @@ -23,6 +23,7 @@ pub mod language; pub mod local_site; pub mod local_site_rate_limit; pub mod local_user; +pub mod local_user_vote_display_mode; pub mod login_token; pub mod moderator; pub mod password_reset_request; diff --git a/crates/db_views/src/comment_report_view.rs b/crates/db_views/src/comment_report_view.rs index 6f3322b39..817ae1694 100644 --- a/crates/db_views/src/comment_report_view.rs +++ b/crates/db_views/src/comment_report_view.rs @@ -223,6 +223,7 @@ mod tests { community::{Community, CommunityInsertForm, CommunityModerator, CommunityModeratorForm}, instance::Instance, local_user::{LocalUser, LocalUserInsertForm}, + local_user_vote_display_mode::LocalUserVoteDisplayMode, person::{Person, PersonInsertForm}, post::{Post, PostInsertForm}, }, @@ -258,6 +259,7 @@ mod tests { let timmy_local_user = LocalUser::create(pool, &new_local_user).await.unwrap(); let timmy_view = LocalUserView { local_user: timmy_local_user, + local_user_vote_display_mode: LocalUserVoteDisplayMode::default(), person: inserted_timmy.clone(), counts: Default::default(), }; diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index a72d0b210..40065672c 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -441,6 +441,7 @@ mod tests { instance::Instance, language::Language, local_user::{LocalUser, LocalUserInsertForm}, + local_user_vote_display_mode::LocalUserVoteDisplayMode, person::{Person, PersonInsertForm}, person_block::{PersonBlock, PersonBlockForm}, post::{Post, PostInsertForm}, @@ -614,6 +615,7 @@ mod tests { let timmy_local_user_view = LocalUserView { local_user: inserted_timmy_local_user.clone(), + local_user_vote_display_mode: LocalUserVoteDisplayMode::default(), person: inserted_timmy_person.clone(), counts: Default::default(), }; diff --git a/crates/db_views/src/local_user_view.rs b/crates/db_views/src/local_user_view.rs index cb9ab86c4..96d6a3530 100644 --- a/crates/db_views/src/local_user_view.rs +++ b/crates/db_views/src/local_user_view.rs @@ -4,7 +4,7 @@ use diesel::{result::Error, BoolExpressionMethods, ExpressionMethods, JoinOnDsl, use diesel_async::RunQueryDsl; use lemmy_db_schema::{ newtypes::{LocalUserId, PersonId}, - schema::{local_user, person, person_aggregates}, + schema::{local_user, local_user_vote_display_mode, person, person_aggregates}, utils::{ functions::{coalesce, lower}, DbConn, @@ -33,6 +33,7 @@ fn queries<'a>( ) -> Queries>, impl ListFn<'a, LocalUserView, ListMode>> { let selection = ( local_user::all_columns, + local_user_vote_display_mode::all_columns, person::all_columns, person_aggregates::all_columns, ); @@ -58,6 +59,7 @@ fn queries<'a>( _ => query, }; query + .inner_join(local_user_vote_display_mode::table) .inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id))) .select(selection) .first::(&mut conn) @@ -68,10 +70,11 @@ fn queries<'a>( match mode { ListMode::AdminsWithEmails => { local_user::table - .filter(local_user::email.is_not_null()) - .filter(local_user::admin.eq(true)) + .inner_join(local_user_vote_display_mode::table) .inner_join(person::table) .inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id))) + .filter(local_user::email.is_not_null()) + .filter(local_user::admin.eq(true)) .select(selection) .load::(&mut conn) .await diff --git a/crates/db_views/src/post_report_view.rs b/crates/db_views/src/post_report_view.rs index ddd12d226..ea59d6b64 100644 --- a/crates/db_views/src/post_report_view.rs +++ b/crates/db_views/src/post_report_view.rs @@ -206,6 +206,7 @@ mod tests { community::{Community, CommunityInsertForm, CommunityModerator, CommunityModeratorForm}, instance::Instance, local_user::{LocalUser, LocalUserInsertForm}, + local_user_vote_display_mode::LocalUserVoteDisplayMode, person::{Person, PersonInsertForm}, post::{Post, PostInsertForm}, post_report::{PostReport, PostReportForm}, @@ -241,6 +242,7 @@ mod tests { let timmy_local_user = LocalUser::create(pool, &new_local_user).await.unwrap(); let timmy_view = LocalUserView { local_user: timmy_local_user, + local_user_vote_display_mode: LocalUserVoteDisplayMode::default(), person: inserted_timmy.clone(), counts: Default::default(), }; diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index ed9cd0952..b9522d47b 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -749,6 +749,7 @@ mod tests { instance_block::{InstanceBlock, InstanceBlockForm}, language::Language, local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm}, + local_user_vote_display_mode::LocalUserVoteDisplayMode, person::{Person, PersonInsertForm}, person_block::{PersonBlock, PersonBlockForm}, post::{Post, PostHide, PostInsertForm, PostLike, PostLikeForm, PostRead, PostUpdateForm}, @@ -871,11 +872,13 @@ mod tests { let inserted_bot_post = Post::create(pool, &new_bot_post).await?; let local_user_view = LocalUserView { local_user: inserted_local_user, + local_user_vote_display_mode: LocalUserVoteDisplayMode::default(), person: inserted_person, counts: Default::default(), }; let blocked_local_user_view = LocalUserView { local_user: inserted_blocked_local_user, + local_user_vote_display_mode: LocalUserVoteDisplayMode::default(), person: inserted_blocked_person, counts: Default::default(), }; diff --git a/crates/db_views/src/structs.rs b/crates/db_views/src/structs.rs index 9b2d8d602..1a90f7c24 100644 --- a/crates/db_views/src/structs.rs +++ b/crates/db_views/src/structs.rs @@ -11,6 +11,7 @@ use lemmy_db_schema::{ local_site::LocalSite, local_site_rate_limit::LocalSiteRateLimit, local_user::LocalUser, + local_user_vote_display_mode::LocalUserVoteDisplayMode, person::Person, post::Post, post_report::PostReport, @@ -73,6 +74,7 @@ pub struct CommentView { /// A local user view. pub struct LocalUserView { pub local_user: LocalUser, + pub local_user_vote_display_mode: LocalUserVoteDisplayMode, pub person: Person, pub counts: PersonAggregates, } diff --git a/migrations/2024-02-12-211114_add_vote_display_mode_setting/down.sql b/migrations/2024-02-12-211114_add_vote_display_mode_setting/down.sql new file mode 100644 index 000000000..e6daaedde --- /dev/null +++ b/migrations/2024-02-12-211114_add_vote_display_mode_setting/down.sql @@ -0,0 +1,2 @@ +DROP TABLE local_user_vote_display_mode; + diff --git a/migrations/2024-02-12-211114_add_vote_display_mode_setting/up.sql b/migrations/2024-02-12-211114_add_vote_display_mode_setting/up.sql new file mode 100644 index 000000000..a76e3c122 --- /dev/null +++ b/migrations/2024-02-12-211114_add_vote_display_mode_setting/up.sql @@ -0,0 +1,18 @@ +-- Create an extra table to hold local user vote display settings +-- Score and Upvote percentage are turned on by default. +CREATE TABLE local_user_vote_display_mode ( + local_user_id int REFERENCES local_user ON UPDATE CASCADE ON DELETE CASCADE NOT NULL, + score boolean DEFAULT TRUE NOT NULL, + upvotes boolean DEFAULT FALSE NOT NULL, + downvotes boolean DEFAULT FALSE NOT NULL, + upvote_percentage boolean DEFAULT TRUE NOT NULL, + PRIMARY KEY (local_user_id) +); + +-- Insert rows for every local user +INSERT INTO local_user_vote_display_mode (local_user_id) +SELECT + id +FROM + local_user; + From 255e69563362093036c64472ce9939439cbe2738 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 13 Mar 2024 12:11:24 -0400 Subject: [PATCH 11/31] Adding extra fields to PostReport and CommentReport views. (#4520) - Fixes #4200 --- crates/db_views/src/comment_report_view.rs | 57 +++++++++++++ crates/db_views/src/post_report_view.rs | 93 +++++++++++++++++++++- crates/db_views/src/structs.rs | 13 +++ 3 files changed, 162 insertions(+), 1 deletion(-) diff --git a/crates/db_views/src/comment_report_view.rs b/crates/db_views/src/comment_report_view.rs index 817ae1694..1aa3bb6e7 100644 --- a/crates/db_views/src/comment_report_view.rs +++ b/crates/db_views/src/comment_report_view.rs @@ -18,10 +18,14 @@ use lemmy_db_schema::{ comment_aggregates, comment_like, comment_report, + comment_saved, community, + community_follower, community_moderator, community_person_ban, + local_user, person, + person_block, post, }, utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, @@ -64,6 +68,45 @@ fn queries<'a>() -> Queries< ), ), ) + .left_join( + aliases::community_moderator1.on( + community::id + .eq(aliases::community_moderator1.field(community_moderator::community_id)) + .and( + aliases::community_moderator1 + .field(community_moderator::person_id) + .eq(comment::creator_id), + ), + ), + ) + .left_join( + local_user::table.on( + comment::creator_id + .eq(local_user::person_id) + .and(local_user::admin.eq(true)), + ), + ) + .left_join( + person_block::table.on( + comment::creator_id + .eq(person_block::target_id) + .and(person_block::person_id.eq(my_person_id)), + ), + ) + .left_join( + community_follower::table.on( + post::community_id + .eq(community_follower::community_id) + .and(community_follower::person_id.eq(my_person_id)), + ), + ) + .left_join( + comment_saved::table.on( + comment::id + .eq(comment_saved::comment_id) + .and(comment_saved::person_id.eq(my_person_id)), + ), + ) .select(( comment_report::all_columns, comment::all_columns, @@ -73,6 +116,14 @@ fn queries<'a>() -> Queries< aliases::person1.fields(person::all_columns), comment_aggregates::all_columns, community_person_ban::community_id.nullable().is_not_null(), + aliases::community_moderator1 + .field(community_moderator::community_id) + .nullable() + .is_not_null(), + local_user::admin.nullable().is_not_null(), + person_block::target_id.nullable().is_not_null(), + community_follower::pending.nullable(), + comment_saved::published.nullable().is_not_null(), comment_like::score.nullable(), aliases::person2.fields(person::all_columns).nullable(), )) @@ -230,6 +281,7 @@ mod tests { traits::{Crud, Joinable, Reportable}, utils::{build_db_pool_for_tests, RANK_DEFAULT}, CommunityVisibility, + SubscribedType, }; use pretty_assertions::assert_eq; use serial_test::serial; @@ -352,6 +404,11 @@ mod tests { comment_report: inserted_jessica_report.clone(), comment: inserted_comment.clone(), post: inserted_post, + creator_is_moderator: true, + creator_is_admin: false, + creator_blocked: false, + subscribed: SubscribedType::NotSubscribed, + saved: false, community: Community { id: inserted_community.id, name: inserted_community.name, diff --git a/crates/db_views/src/post_report_view.rs b/crates/db_views/src/post_report_view.rs index ea59d6b64..0f1f3639c 100644 --- a/crates/db_views/src/post_report_view.rs +++ b/crates/db_views/src/post_report_view.rs @@ -14,15 +14,31 @@ use lemmy_db_schema::{ newtypes::{CommunityId, PersonId, PostId, PostReportId}, schema::{ community, + community_follower, community_moderator, community_person_ban, + local_user, person, + person_block, + person_post_aggregates, post, post_aggregates, + post_hide, post_like, + post_read, post_report, + post_saved, + }, + utils::{ + functions::coalesce, + get_conn, + limit_and_offset, + DbConn, + DbPool, + ListFn, + Queries, + ReadFn, }, - utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, }; fn queries<'a>() -> Queries< @@ -42,6 +58,67 @@ fn queries<'a>() -> Queries< .and(community_person_ban::person_id.eq(post::creator_id)), ), ) + .left_join( + aliases::community_moderator1.on( + aliases::community_moderator1 + .field(community_moderator::community_id) + .eq(post::community_id) + .and( + aliases::community_moderator1 + .field(community_moderator::person_id) + .eq(my_person_id), + ), + ), + ) + .left_join( + local_user::table.on( + post::creator_id + .eq(local_user::person_id) + .and(local_user::admin.eq(true)), + ), + ) + .left_join( + post_saved::table.on( + post::id + .eq(post_saved::post_id) + .and(post_saved::person_id.eq(my_person_id)), + ), + ) + .left_join( + post_read::table.on( + post::id + .eq(post_read::post_id) + .and(post_read::person_id.eq(my_person_id)), + ), + ) + .left_join( + post_hide::table.on( + post::id + .eq(post_hide::post_id) + .and(post_hide::person_id.eq(my_person_id)), + ), + ) + .left_join( + person_block::table.on( + post::creator_id + .eq(person_block::target_id) + .and(person_block::person_id.eq(my_person_id)), + ), + ) + .left_join( + person_post_aggregates::table.on( + post::id + .eq(person_post_aggregates::post_id) + .and(person_post_aggregates::person_id.eq(my_person_id)), + ), + ) + .left_join( + community_follower::table.on( + post::community_id + .eq(community_follower::community_id) + .and(community_follower::person_id.eq(my_person_id)), + ), + ) .left_join( post_like::table.on( post::id @@ -61,7 +138,21 @@ fn queries<'a>() -> Queries< person::all_columns, aliases::person1.fields(person::all_columns), community_person_ban::community_id.nullable().is_not_null(), + aliases::community_moderator1 + .field(community_moderator::community_id) + .nullable() + .is_not_null(), + local_user::admin.nullable().is_not_null(), + community_follower::pending.nullable(), + post_saved::post_id.nullable().is_not_null(), + post_read::post_id.nullable().is_not_null(), + post_hide::post_id.nullable().is_not_null(), + person_block::target_id.nullable().is_not_null(), post_like::score.nullable(), + coalesce( + post_aggregates::comments.nullable() - person_post_aggregates::read_comments.nullable(), + post_aggregates::comments, + ), post_aggregates::all_columns, aliases::person2.fields(person::all_columns.nullable()), )) diff --git a/crates/db_views/src/structs.rs b/crates/db_views/src/structs.rs index 1a90f7c24..18fa7efa9 100644 --- a/crates/db_views/src/structs.rs +++ b/crates/db_views/src/structs.rs @@ -42,6 +42,11 @@ pub struct CommentReportView { pub comment_creator: Person, pub counts: CommentAggregates, pub creator_banned_from_community: bool, + pub creator_is_moderator: bool, + pub creator_is_admin: bool, + pub creator_blocked: bool, + pub subscribed: SubscribedType, + pub saved: bool, pub my_vote: Option, pub resolver: Option, } @@ -92,7 +97,15 @@ pub struct PostReportView { pub creator: Person, pub post_creator: Person, pub creator_banned_from_community: bool, + pub creator_is_moderator: bool, + pub creator_is_admin: bool, + pub subscribed: SubscribedType, + pub saved: bool, + pub read: bool, + pub hidden: bool, + pub creator_blocked: bool, pub my_vote: Option, + pub unread_comments: i64, pub counts: PostAggregates, pub resolver: Option, } From f1de7b7590b8c0a29666e785316572101f427420 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Thu, 14 Mar 2024 17:16:45 +0100 Subject: [PATCH 12/31] Automatically include apub hashtag with posts (fixes #3906) (#4533) --- crates/apub/src/objects/post.rs | 8 +++++++- crates/apub/src/protocol/objects/page.rs | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index 8b8ae093b..2b211fff9 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -5,7 +5,7 @@ use crate::{ objects::{read_from_string_or_source_opt, verify_is_remote_object}, protocol::{ objects::{ - page::{Attachment, AttributedTo, Page, PageType}, + page::{Attachment, AttributedTo, Hashtag, HashtagType, Page, PageType}, LanguageTag, }, ImageObject, @@ -124,6 +124,11 @@ impl Object for ApubPost { }) .into_iter() .collect(); + let hashtag = Hashtag { + href: self.ap_id.clone().into(), + name: format!("#{}", &community.name), + kind: HashtagType::Hashtag, + }; let page = Page { kind: PageType::Page, @@ -144,6 +149,7 @@ impl Object for ApubPost { updated: self.updated, audience: Some(community.actor_id.into()), in_reply_to: None, + tag: vec![hashtag], }; Ok(page) } diff --git a/crates/apub/src/protocol/objects/page.rs b/crates/apub/src/protocol/objects/page.rs index d6111843e..170778297 100644 --- a/crates/apub/src/protocol/objects/page.rs +++ b/crates/apub/src/protocol/objects/page.rs @@ -66,6 +66,8 @@ pub struct Page { pub(crate) updated: Option>, pub(crate) language: Option, pub(crate) audience: Option>, + #[serde(deserialize_with = "deserialize_skip_error", default)] + pub(crate) tag: Vec, } #[derive(Clone, Debug, Deserialize, Serialize)] @@ -140,6 +142,19 @@ pub(crate) struct AttributedToPeertube { pub id: ObjectId, } +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Hashtag { + pub(crate) href: Url, + pub(crate) name: String, + #[serde(rename = "type")] + pub(crate) kind: HashtagType, +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub enum HashtagType { + Hashtag, +} + impl Page { /// Only mods can change the post's locked status. So if it is changed from the default value, /// it is a mod action and needs to be verified as such. From 835d3291344af94f4b7d4878e06d33d07c671092 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Thu, 14 Mar 2024 21:57:56 +0100 Subject: [PATCH 13/31] Fix longstanding bug that breaks initial community view (fixes #3529) (#4535) --- crates/apub/src/api/list_comments.rs | 7 +++++-- crates/apub/src/api/list_posts.rs | 7 +++++-- crates/apub/src/objects/community.rs | 15 +++++++++------ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/crates/apub/src/api/list_comments.rs b/crates/apub/src/api/list_comments.rs index 3ae85cdcc..c83756f54 100644 --- a/crates/apub/src/api/list_comments.rs +++ b/crates/apub/src/api/list_comments.rs @@ -27,8 +27,11 @@ pub async fn list_comments( check_private_instance(&local_user_view, &local_site)?; let community_id = if let Some(name) = &data.community_name { - Some(resolve_actor_identifier::(name, &context, &None, true).await?) - .map(|c| c.id) + Some( + resolve_actor_identifier::(name, &context, &local_user_view, true) + .await?, + ) + .map(|c| c.id) } else { data.community_id }; diff --git a/crates/apub/src/api/list_posts.rs b/crates/apub/src/api/list_posts.rs index b2ca95648..384f1b60e 100644 --- a/crates/apub/src/api/list_posts.rs +++ b/crates/apub/src/api/list_posts.rs @@ -30,8 +30,11 @@ pub async fn list_posts( let page = data.page; let limit = data.limit; let community_id = if let Some(name) = &data.community_name { - Some(resolve_actor_identifier::(name, &context, &None, true).await?) - .map(|c| c.id) + Some( + resolve_actor_identifier::(name, &context, &local_user_view, true) + .await?, + ) + .map(|c| c.id) } else { data.community_id }; diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index ad8472915..e71f6d9b5 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -177,18 +177,21 @@ impl Object for ApubCommunity { let community: ApubCommunity = community.into(); - // Fetching mods and outbox is not necessary for Lemmy to work, so ignore errors. Besides, - // we need to ignore these errors so that tests can work entirely offline. + // These collections are not necessary for Lemmy to work, so ignore errors. let community_ = community.clone(); let context_ = context.reset_request_count(); spawn_try_task(async move { - group.outbox.dereference(&community_, &context_).await?; - group.followers.dereference(&community_, &context_).await?; + group.outbox.dereference(&community_, &context_).await.ok(); + group + .followers + .dereference(&community_, &context_) + .await + .ok(); if let Some(featured) = group.featured { - featured.dereference(&community_, &context_).await?; + featured.dereference(&community_, &context_).await.ok(); } if let Some(moderators) = group.attributed_to { - moderators.dereference(&community_, &context_).await?; + moderators.dereference(&community_, &context_).await.ok(); } Ok(()) }); From 0e7080337b9dcce0d4161fe9290798393c20388f Mon Sep 17 00:00:00 2001 From: Nutomic Date: Thu, 14 Mar 2024 22:31:54 +0100 Subject: [PATCH 14/31] Dont allow admins to post in community with `posting_restricted_to_mods` (fixes #3571) (#4534) * Dont allow admins to post in community with `posting_restricted_to_mods` (fixes #3571) * fmt --- crates/api_crud/src/post/create.rs | 6 +++--- crates/apub/src/objects/post.rs | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index c52cfaf80..07d577f51 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -29,7 +29,7 @@ use lemmy_db_schema::{ CommunityVisibility, }; use lemmy_db_views::structs::LocalUserView; -use lemmy_db_views_actor::structs::CommunityView; +use lemmy_db_views_actor::structs::CommunityModeratorView; use lemmy_utils::{ error::{LemmyError, LemmyErrorExt, LemmyErrorType}, spawn_try_task, @@ -83,10 +83,10 @@ pub async fn create_post( let community = Community::read(&mut context.pool(), community_id).await?; if community.posting_restricted_to_mods { let community_id = data.community_id; - let is_mod = CommunityView::is_mod_or_admin( + let is_mod = CommunityModeratorView::is_community_moderator( &mut context.pool(), - local_user_view.local_user.person_id, community_id, + local_user_view.local_user.person_id, ) .await?; if !is_mod { diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index 2b211fff9..ff42b9cbd 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -26,7 +26,6 @@ use lemmy_api_common::{ context::LemmyContext, request::fetch_link_metadata_opt, utils::{ - is_mod_or_admin, local_site_opt_to_sensitive, local_site_opt_to_slur_regex, process_markdown_opt, @@ -43,6 +42,7 @@ use lemmy_db_schema::{ }, traits::Crud, }; +use lemmy_db_views_actor::structs::CommunityModeratorView; use lemmy_utils::{ error::LemmyError, utils::{markdown::markdown_to_html, slurs::check_slurs_opt, validation::check_url_scheme}, @@ -185,7 +185,8 @@ impl Object for ApubPost { let creator = page.creator()?.dereference(context).await?; let community = page.community(context).await?; if community.posting_restricted_to_mods { - is_mod_or_admin(&mut context.pool(), &creator, community.id).await?; + CommunityModeratorView::is_community_moderator(&mut context.pool(), community.id, creator.id) + .await?; } let mut name = page .name From 19a1a077c5b236e16fe5346765fd824715b8cf52 Mon Sep 17 00:00:00 2001 From: flamingos-cant <45780476+flamingo-cant-draw@users.noreply.github.com> Date: Fri, 15 Mar 2024 11:03:29 +0000 Subject: [PATCH 15/31] Add a blocklist for URLs. (#4515) * Add a blocklist for URLs. * Fix SQL format * Make clippy happy. * Use regex for URL matching. * Escape regex chars in URLs. * Use post for modification. * Make URL block regex static and remove API routes. * Add date fields to table and use transaction. * Use Cache for blocklist. * Rename check_links + move list to parameters of process_markdown. * SQL format. * Format, again. * Remove println. * Add API test. * Set a shorter lifetime for regex in debug mode. * Add missing macro. * Update lemmy-js-client * Update api_test/pnpm-lock.yaml * Don't break other tests * Use different URL for test --------- Co-authored-by: Dessalines Co-authored-by: Nutomic --- api_tests/package.json | 2 +- api_tests/pnpm-lock.yaml | 8 +- api_tests/src/post.spec.ts | 23 ++ crates/api/src/local_user/save_settings.rs | 6 +- crates/api/src/site/leave_admin.rs | 3 + crates/api_common/Cargo.toml | 2 + crates/api_common/src/site.rs | 4 + crates/api_common/src/utils.rs | 63 +++- crates/api_crud/src/comment/create.rs | 4 +- crates/api_crud/src/comment/update.rs | 10 +- crates/api_crud/src/community/create.rs | 5 +- crates/api_crud/src/community/update.rs | 5 +- crates/api_crud/src/post/create.rs | 6 +- crates/api_crud/src/post/update.rs | 7 +- crates/api_crud/src/private_message/create.rs | 4 +- crates/api_crud/src/private_message/update.rs | 5 +- crates/api_crud/src/site/create.rs | 4 +- crates/api_crud/src/site/read.rs | 3 + crates/api_crud/src/site/update.rs | 12 +- crates/apub/src/objects/comment.rs | 5 +- crates/apub/src/objects/community.rs | 5 +- crates/apub/src/objects/instance.rs | 10 +- crates/apub/src/objects/person.rs | 4 +- crates/apub/src/objects/post.rs | 4 +- crates/apub/src/objects/private_message.rs | 5 +- .../src/impls/local_site_url_blocklist.rs | 49 ++++ crates/db_schema/src/impls/mod.rs | 1 + crates/db_schema/src/schema.rs | 10 + .../src/source/local_site_url_blocklist.rs | 28 ++ crates/db_schema/src/source/mod.rs | 1 + crates/utils/src/error.rs | 1 + crates/utils/src/utils/markdown/mod.rs | 271 +++++++++++------- crates/utils/src/utils/validation.rs | 67 ++++- .../2024-03-06-201637_url_blocklist/down.sql | 3 + .../2024-03-06-201637_url_blocklist/up.sql | 7 + 35 files changed, 514 insertions(+), 133 deletions(-) create mode 100644 crates/db_schema/src/impls/local_site_url_blocklist.rs create mode 100644 crates/db_schema/src/source/local_site_url_blocklist.rs create mode 100644 migrations/2024-03-06-201637_url_blocklist/down.sql create mode 100644 migrations/2024-03-06-201637_url_blocklist/up.sql diff --git a/api_tests/package.json b/api_tests/package.json index 9e7042f2d..f6c436312 100644 --- a/api_tests/package.json +++ b/api_tests/package.json @@ -27,7 +27,7 @@ "eslint": "^8.57.0", "eslint-plugin-prettier": "^5.0.1", "jest": "^29.5.0", - "lemmy-js-client": "0.19.4-alpha.6", + "lemmy-js-client": "0.19.4-alpha.8", "prettier": "^3.2.5", "ts-jest": "^29.1.0", "typescript": "^5.3.3" diff --git a/api_tests/pnpm-lock.yaml b/api_tests/pnpm-lock.yaml index 213111ab1..321fffc8b 100644 --- a/api_tests/pnpm-lock.yaml +++ b/api_tests/pnpm-lock.yaml @@ -30,8 +30,8 @@ devDependencies: specifier: ^29.5.0 version: 29.7.0(@types/node@20.11.22) lemmy-js-client: - specifier: 0.19.4-alpha.6 - version: 0.19.4-alpha.6 + specifier: 0.19.4-alpha.8 + version: 0.19.4-alpha.8 prettier: specifier: ^3.2.5 version: 3.2.5 @@ -2390,8 +2390,8 @@ packages: engines: {node: '>=6'} dev: true - /lemmy-js-client@0.19.4-alpha.6: - resolution: {integrity: sha512-x4htMlpoZ7hzrhrIk82aompVxbpu2ZDWtmWNGraM0+27nUCDf6gYxJH5nb5R/o39BQe5KSHq6zoBdliBwAY40w==} + /lemmy-js-client@0.19.4-alpha.8: + resolution: {integrity: sha512-8vjqUYVOhyUTcmG9FvPLjrWziVwNa2/Zi+kSflTrajJsK0V+5DclJ5dhdVMUQ4DEA70gb0OuNMDlipPG2FoS5A==} dependencies: cross-fetch: 4.0.0 form-data: 4.0.0 diff --git a/api_tests/src/post.spec.ts b/api_tests/src/post.spec.ts index 02080c4cc..59a0557bf 100644 --- a/api_tests/src/post.spec.ts +++ b/api_tests/src/post.spec.ts @@ -18,6 +18,7 @@ import { resolveBetaCommunity, createComment, deletePost, + delay, removePost, getPost, unfollowRemotes, @@ -710,3 +711,25 @@ test("Fetch post via redirect", async () => { expect(gammaPost.post?.post.ap_id).toBe(alphaPost.post_view.post.ap_id); await unfollowRemotes(alpha); }); + +test("Block post that contains banned URL", async () => { + let editSiteForm: EditSite = { + blocked_urls: ["https://evil.com/"], + }; + + await epsilon.editSite(editSiteForm); + + await delay(500); + + if (!betaCommunity) { + throw "Missing beta community"; + } + + expect( + createPost(epsilon, betaCommunity.community.id, "https://evil.com"), + ).rejects.toStrictEqual(Error("blocked_url")); + + // Later tests need this to be empty + editSiteForm.blocked_urls = []; + await epsilon.editSite(editSiteForm); +}); diff --git a/crates/api/src/local_user/save_settings.rs b/crates/api/src/local_user/save_settings.rs index d918bdc00..927496416 100644 --- a/crates/api/src/local_user/save_settings.rs +++ b/crates/api/src/local_user/save_settings.rs @@ -3,6 +3,7 @@ use lemmy_api_common::{ context::LemmyContext, person::SaveUserSettings, utils::{ + get_url_blocklist, local_site_to_slur_regex, process_markdown_opt, proxy_image_link_opt_api, @@ -35,7 +36,10 @@ pub async fn save_user_settings( let site_view = SiteView::read_local(&mut context.pool()).await?; let slur_regex = local_site_to_slur_regex(&site_view.local_site); - let bio = diesel_option_overwrite(process_markdown_opt(&data.bio, &slur_regex, &context).await?); + let url_blocklist = get_url_blocklist(&context).await?; + let bio = diesel_option_overwrite( + process_markdown_opt(&data.bio, &slur_regex, &url_blocklist, &context).await?, + ); let avatar = proxy_image_link_opt_api(&data.avatar, &context).await?; let banner = proxy_image_link_opt_api(&data.banner, &context).await?; diff --git a/crates/api/src/site/leave_admin.rs b/crates/api/src/site/leave_admin.rs index 77e28332b..0d149d07d 100644 --- a/crates/api/src/site/leave_admin.rs +++ b/crates/api/src/site/leave_admin.rs @@ -4,6 +4,7 @@ use lemmy_db_schema::{ source::{ actor_language::SiteLanguage, language::Language, + local_site_url_blocklist::LocalSiteUrlBlocklist, local_user::{LocalUser, LocalUserUpdateForm}, moderator::{ModAdd, ModAddForm}, tagline::Tagline, @@ -62,6 +63,7 @@ pub async fn leave_admin( let taglines = Tagline::get_all(&mut context.pool(), site_view.local_site.id).await?; let custom_emojis = CustomEmojiView::get_all(&mut context.pool(), site_view.local_site.id).await?; + let blocked_urls = LocalSiteUrlBlocklist::get_all(&mut context.pool()).await?; Ok(Json(GetSiteResponse { site_view, @@ -72,5 +74,6 @@ pub async fn leave_admin( discussion_languages, taglines, custom_emojis, + blocked_urls, })) } diff --git a/crates/api_common/Cargo.toml b/crates/api_common/Cargo.toml index 3acd7d4ca..47545446f 100644 --- a/crates/api_common/Cargo.toml +++ b/crates/api_common/Cargo.toml @@ -59,6 +59,8 @@ uuid = { workspace = true, optional = true } tokio = { workspace = true, optional = true } reqwest = { workspace = true, optional = true } ts-rs = { workspace = true, optional = true } +moka.workspace = true +anyhow.workspace = true once_cell = { workspace = true, optional = true } actix-web = { workspace = true, optional = true } enum-map = { workspace = true } diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index bed81c2e4..d87cbdaaf 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -6,6 +6,7 @@ use lemmy_db_schema::{ federation_queue_state::FederationQueueState, instance::Instance, language::Language, + local_site_url_blocklist::LocalSiteUrlBlocklist, tagline::Tagline, }, ListingType, @@ -268,6 +269,8 @@ pub struct EditSite { pub allowed_instances: Option>, /// A list of blocked instances. pub blocked_instances: Option>, + /// A list of blocked URLs + pub blocked_urls: Option>, /// A list of taglines shown at the top of the front page. pub taglines: Option>, pub registration_mode: Option, @@ -305,6 +308,7 @@ pub struct GetSiteResponse { pub taglines: Vec, /// A list of custom emojis your site supports. pub custom_emojis: Vec, + pub blocked_urls: Vec, } #[skip_serializing_none] diff --git a/crates/api_common/src/utils.rs b/crates/api_common/src/utils.rs index d51751854..b13d21f9f 100644 --- a/crates/api_common/src/utils.rs +++ b/crates/api_common/src/utils.rs @@ -17,6 +17,7 @@ use lemmy_db_schema::{ instance_block::InstanceBlock, local_site::LocalSite, local_site_rate_limit::LocalSiteRateLimit, + local_site_url_blocklist::LocalSiteUrlBlocklist, password_reset_request::PasswordResetRequest, person::{Person, PersonUpdateForm}, person_block::PersonBlock, @@ -38,18 +39,24 @@ use lemmy_utils::{ rate_limit::{ActionType, BucketConfig}, settings::structs::{PictrsImageMode, Settings}, utils::{ - markdown::markdown_rewrite_image_links, + markdown::{markdown_check_for_blocked_urls, markdown_rewrite_image_links}, slurs::{build_slur_regex, remove_slurs}, }, }; -use regex::Regex; +use moka::future::Cache; +use once_cell::sync::Lazy; +use regex::{escape, Regex, RegexSet}; use rosetta_i18n::{Language, LanguageId}; -use std::collections::HashSet; +use std::{collections::HashSet, time::Duration}; use tracing::warn; use url::{ParseError, Url}; use urlencoding::encode; pub static AUTH_COOKIE_NAME: &str = "jwt"; +#[cfg(debug_assertions)] +static URL_BLOCKLIST_RECHECK_DELAY: Duration = Duration::from_millis(500); +#[cfg(not(debug_assertions))] +static URL_BLOCKLIST_RECHECK_DELAY: Duration = Duration::from_secs(60); #[tracing::instrument(skip_all)] pub async fn is_mod_or_admin( @@ -516,6 +523,47 @@ pub fn local_site_opt_to_sensitive(local_site: &Option) -> bool { .unwrap_or(false) } +pub async fn get_url_blocklist(context: &LemmyContext) -> LemmyResult { + static URL_BLOCKLIST: Lazy> = Lazy::new(|| { + Cache::builder() + .max_capacity(1) + .time_to_live(URL_BLOCKLIST_RECHECK_DELAY) + .build() + }); + + Ok( + URL_BLOCKLIST + .try_get_with::<_, LemmyError>((), async { + let urls = LocalSiteUrlBlocklist::get_all(&mut context.pool()).await?; + + let regexes = urls.iter().map(|url| { + let url = &url.url; + let parsed = Url::parse(url).expect("Coundln't parse URL."); + if url.ends_with('/') { + format!( + "({}://)?{}{}?", + parsed.scheme(), + escape(parsed.domain().expect("No domain.")), + escape(parsed.path()) + ) + } else { + format!( + "({}://)?{}{}", + parsed.scheme(), + escape(parsed.domain().expect("No domain.")), + escape(parsed.path()) + ) + } + }); + + let set = RegexSet::new(regexes)?; + Ok(set) + }) + .await + .map_err(|e| anyhow::anyhow!("Failed to build URL blocklist due to `{}`", e))?, + ) +} + pub async fn send_application_approved_email( user: &LocalUserView, settings: &Settings, @@ -867,9 +915,13 @@ fn limit_expire_time(expires: DateTime) -> LemmyResult pub async fn process_markdown( text: &str, slur_regex: &Option, + url_blocklist: &RegexSet, context: &LemmyContext, ) -> LemmyResult { let text = remove_slurs(text, slur_regex); + + markdown_check_for_blocked_urls(&text, url_blocklist)?; + if context.settings().pictrs_config()?.image_mode() == PictrsImageMode::ProxyAllImages { let (text, links) = markdown_rewrite_image_links(text); RemoteImage::create(&mut context.pool(), links).await?; @@ -882,10 +934,13 @@ pub async fn process_markdown( pub async fn process_markdown_opt( text: &Option, slur_regex: &Option, + url_blocklist: &RegexSet, context: &LemmyContext, ) -> LemmyResult> { match text { - Some(t) => process_markdown(t, slur_regex, context).await.map(Some), + Some(t) => process_markdown(t, slur_regex, url_blocklist, context) + .await + .map(Some), None => Ok(None), } } diff --git a/crates/api_crud/src/comment/create.rs b/crates/api_crud/src/comment/create.rs index e5a869223..9269ec382 100644 --- a/crates/api_crud/src/comment/create.rs +++ b/crates/api_crud/src/comment/create.rs @@ -10,6 +10,7 @@ use lemmy_api_common::{ check_post_deleted_or_removed, generate_local_apub_endpoint, get_post, + get_url_blocklist, is_mod_or_admin, local_site_to_slur_regex, process_markdown, @@ -44,7 +45,8 @@ pub async fn create_comment( let local_site = LocalSite::read(&mut context.pool()).await?; let slur_regex = local_site_to_slur_regex(&local_site); - let content = process_markdown(&data.content, &slur_regex, &context).await?; + let url_blocklist = get_url_blocklist(&context).await?; + let content = process_markdown(&data.content, &slur_regex, &url_blocklist, &context).await?; is_valid_body_field(&Some(content.clone()), false)?; // Check for a community ban diff --git a/crates/api_crud/src/comment/update.rs b/crates/api_crud/src/comment/update.rs index 2d6bf79be..e814ebd6b 100644 --- a/crates/api_crud/src/comment/update.rs +++ b/crates/api_crud/src/comment/update.rs @@ -5,7 +5,12 @@ use lemmy_api_common::{ comment::{CommentResponse, EditComment}, context::LemmyContext, send_activity::{ActivityChannel, SendActivityData}, - utils::{check_community_user_action, local_site_to_slur_regex, process_markdown_opt}, + utils::{ + check_community_user_action, + get_url_blocklist, + local_site_to_slur_regex, + process_markdown_opt, + }, }; use lemmy_db_schema::{ source::{ @@ -54,7 +59,8 @@ pub async fn update_comment( .await?; let slur_regex = local_site_to_slur_regex(&local_site); - let content = process_markdown_opt(&data.content, &slur_regex, &context).await?; + let url_blocklist = get_url_blocklist(&context).await?; + let content = process_markdown_opt(&data.content, &slur_regex, &url_blocklist, &context).await?; is_valid_body_field(&content, false)?; let comment_id = data.comment_id; diff --git a/crates/api_crud/src/community/create.rs b/crates/api_crud/src/community/create.rs index ef2da9ef8..679655078 100644 --- a/crates/api_crud/src/community/create.rs +++ b/crates/api_crud/src/community/create.rs @@ -9,6 +9,7 @@ use lemmy_api_common::{ generate_inbox_url, generate_local_apub_endpoint, generate_shared_inbox_url, + get_url_blocklist, is_admin, local_site_to_slur_regex, process_markdown_opt, @@ -53,9 +54,11 @@ pub async fn create_community( } let slur_regex = local_site_to_slur_regex(&local_site); + let url_blocklist = get_url_blocklist(&context).await?; check_slurs(&data.name, &slur_regex)?; check_slurs(&data.title, &slur_regex)?; - let description = process_markdown_opt(&data.description, &slur_regex, &context).await?; + let description = + process_markdown_opt(&data.description, &slur_regex, &url_blocklist, &context).await?; let icon = proxy_image_link_api(&data.icon, &context).await?; let banner = proxy_image_link_api(&data.banner, &context).await?; diff --git a/crates/api_crud/src/community/update.rs b/crates/api_crud/src/community/update.rs index 14bb5c326..83ffded13 100644 --- a/crates/api_crud/src/community/update.rs +++ b/crates/api_crud/src/community/update.rs @@ -7,6 +7,7 @@ use lemmy_api_common::{ send_activity::{ActivityChannel, SendActivityData}, utils::{ check_community_mod_action, + get_url_blocklist, local_site_to_slur_regex, process_markdown_opt, proxy_image_link_opt_api, @@ -36,8 +37,10 @@ pub async fn update_community( let local_site = LocalSite::read(&mut context.pool()).await?; let slur_regex = local_site_to_slur_regex(&local_site); + let url_blocklist = get_url_blocklist(&context).await?; check_slurs_opt(&data.title, &slur_regex)?; - let description = process_markdown_opt(&data.description, &slur_regex, &context).await?; + let description = + process_markdown_opt(&data.description, &slur_regex, &url_blocklist, &context).await?; is_valid_body_field(&data.description, false)?; let description = diesel_option_overwrite(description); diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index 07d577f51..fabab6b09 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -9,6 +9,7 @@ use lemmy_api_common::{ utils::{ check_community_user_action, generate_local_apub_endpoint, + get_url_blocklist, honeypot_check, local_site_to_slur_regex, mark_post_as_read, @@ -38,6 +39,7 @@ use lemmy_utils::{ validation::{ check_url_scheme, clean_url_params, + is_url_blocked, is_valid_alt_text_field, is_valid_body_field, is_valid_post_title, @@ -60,8 +62,9 @@ pub async fn create_post( let slur_regex = local_site_to_slur_regex(&local_site); check_slurs(&data.name, &slur_regex)?; + let url_blocklist = get_url_blocklist(&context).await?; - let body = process_markdown_opt(&data.body, &slur_regex, &context).await?; + let body = process_markdown_opt(&data.body, &slur_regex, &url_blocklist, &context).await?; let data_url = data.url.as_ref(); let url = data_url.map(clean_url_params); // TODO no good way to handle a "clear" let custom_thumbnail = data.custom_thumbnail.as_ref().map(clean_url_params); @@ -69,6 +72,7 @@ pub async fn create_post( is_valid_post_title(&data.name)?; is_valid_body_field(&body, true)?; is_valid_alt_text_field(&data.alt_text)?; + is_url_blocked(&url, &url_blocklist)?; check_url_scheme(&url)?; check_url_scheme(&custom_thumbnail)?; diff --git a/crates/api_crud/src/post/update.rs b/crates/api_crud/src/post/update.rs index 6db65dffe..08c5425b9 100644 --- a/crates/api_crud/src/post/update.rs +++ b/crates/api_crud/src/post/update.rs @@ -8,6 +8,7 @@ use lemmy_api_common::{ send_activity::{ActivityChannel, SendActivityData}, utils::{ check_community_user_action, + get_url_blocklist, local_site_to_slur_regex, process_markdown_opt, proxy_image_link_opt_apub, @@ -30,6 +31,7 @@ use lemmy_utils::{ validation::{ check_url_scheme, clean_url_params, + is_url_blocked, is_valid_alt_text_field, is_valid_body_field, is_valid_post_title, @@ -51,9 +53,11 @@ pub async fn update_post( let url = data.url.as_ref().map(clean_url_params); let custom_thumbnail = data.custom_thumbnail.as_ref().map(clean_url_params); + let url_blocklist = get_url_blocklist(&context).await?; + let slur_regex = local_site_to_slur_regex(&local_site); check_slurs_opt(&data.name, &slur_regex)?; - let body = process_markdown_opt(&data.body, &slur_regex, &context).await?; + let body = process_markdown_opt(&data.body, &slur_regex, &url_blocklist, &context).await?; if let Some(name) = &data.name { is_valid_post_title(name)?; @@ -61,6 +65,7 @@ pub async fn update_post( is_valid_body_field(&body, true)?; is_valid_alt_text_field(&data.alt_text)?; + is_url_blocked(&url, &url_blocklist)?; check_url_scheme(&url)?; check_url_scheme(&custom_thumbnail)?; diff --git a/crates/api_crud/src/private_message/create.rs b/crates/api_crud/src/private_message/create.rs index c4832ec70..32d8b99e6 100644 --- a/crates/api_crud/src/private_message/create.rs +++ b/crates/api_crud/src/private_message/create.rs @@ -8,6 +8,7 @@ use lemmy_api_common::{ check_person_block, generate_local_apub_endpoint, get_interface_language, + get_url_blocklist, local_site_to_slur_regex, process_markdown, send_email_to_user, @@ -36,7 +37,8 @@ pub async fn create_private_message( let local_site = LocalSite::read(&mut context.pool()).await?; let slur_regex = local_site_to_slur_regex(&local_site); - let content = process_markdown(&data.content, &slur_regex, &context).await?; + let url_blocklist = get_url_blocklist(&context).await?; + let content = process_markdown(&data.content, &slur_regex, &url_blocklist, &context).await?; is_valid_body_field(&Some(content.clone()), false)?; check_person_block( diff --git a/crates/api_crud/src/private_message/update.rs b/crates/api_crud/src/private_message/update.rs index dfcf522a8..29063fd10 100644 --- a/crates/api_crud/src/private_message/update.rs +++ b/crates/api_crud/src/private_message/update.rs @@ -4,7 +4,7 @@ use lemmy_api_common::{ context::LemmyContext, private_message::{EditPrivateMessage, PrivateMessageResponse}, send_activity::{ActivityChannel, SendActivityData}, - utils::{local_site_to_slur_regex, process_markdown}, + utils::{get_url_blocklist, local_site_to_slur_regex, process_markdown}, }; use lemmy_db_schema::{ source::{ @@ -37,7 +37,8 @@ pub async fn update_private_message( // Doing the update let slur_regex = local_site_to_slur_regex(&local_site); - let content = process_markdown(&data.content, &slur_regex, &context).await?; + let url_blocklist = get_url_blocklist(&context).await?; + let content = process_markdown(&data.content, &slur_regex, &url_blocklist, &context).await?; is_valid_body_field(&Some(content.clone()), false)?; let private_message_id = data.private_message_id; diff --git a/crates/api_crud/src/site/create.rs b/crates/api_crud/src/site/create.rs index b5441bffe..76aae405e 100644 --- a/crates/api_crud/src/site/create.rs +++ b/crates/api_crud/src/site/create.rs @@ -6,6 +6,7 @@ use lemmy_api_common::{ site::{CreateSite, SiteResponse}, utils::{ generate_shared_inbox_url, + get_url_blocklist, is_admin, local_site_rate_limit_to_rate_limit_config, local_site_to_slur_regex, @@ -58,7 +59,8 @@ pub async fn create_site( let keypair = generate_actor_keypair()?; let slur_regex = local_site_to_slur_regex(&local_site); - let sidebar = process_markdown_opt(&data.sidebar, &slur_regex, &context).await?; + let url_blocklist = get_url_blocklist(&context).await?; + let sidebar = process_markdown_opt(&data.sidebar, &slur_regex, &url_blocklist, &context).await?; let icon = proxy_image_link_opt_api(&data.icon, &context).await?; let banner = proxy_image_link_opt_api(&data.banner, &context).await?; diff --git a/crates/api_crud/src/site/read.rs b/crates/api_crud/src/site/read.rs index b64503666..e99a222fa 100644 --- a/crates/api_crud/src/site/read.rs +++ b/crates/api_crud/src/site/read.rs @@ -6,6 +6,7 @@ use lemmy_api_common::{ use lemmy_db_schema::source::{ actor_language::{LocalUserLanguage, SiteLanguage}, language::Language, + local_site_url_blocklist::LocalSiteUrlBlocklist, tagline::Tagline, }; use lemmy_db_views::structs::{CustomEmojiView, LocalUserView, SiteView}; @@ -47,6 +48,7 @@ pub async fn get_site( let taglines = Tagline::get_all(&mut context.pool(), site_view.local_site.id).await?; let custom_emojis = CustomEmojiView::get_all(&mut context.pool(), site_view.local_site.id).await?; + let blocked_urls = LocalSiteUrlBlocklist::get_all(&mut context.pool()).await?; Ok(GetSiteResponse { site_view, admins, @@ -56,6 +58,7 @@ pub async fn get_site( discussion_languages, taglines, custom_emojis, + blocked_urls, }) }) .await diff --git a/crates/api_crud/src/site/update.rs b/crates/api_crud/src/site/update.rs index 17e81937e..809dbe498 100644 --- a/crates/api_crud/src/site/update.rs +++ b/crates/api_crud/src/site/update.rs @@ -4,6 +4,7 @@ use lemmy_api_common::{ context::LemmyContext, site::{EditSite, SiteResponse}, utils::{ + get_url_blocklist, is_admin, local_site_rate_limit_to_rate_limit_config, local_site_to_slur_regex, @@ -18,6 +19,7 @@ use lemmy_db_schema::{ federation_blocklist::FederationBlockList, local_site::{LocalSite, LocalSiteUpdateForm}, local_site_rate_limit::{LocalSiteRateLimit, LocalSiteRateLimitUpdateForm}, + local_site_url_blocklist::LocalSiteUrlBlocklist, local_user::LocalUser, site::{Site, SiteUpdateForm}, tagline::Tagline, @@ -34,6 +36,7 @@ use lemmy_utils::{ validation::{ build_and_check_regex, check_site_visibility_valid, + check_urls_are_valid, is_valid_body_field, site_description_length_check, site_name_length_check, @@ -61,7 +64,8 @@ pub async fn update_site( } let slur_regex = local_site_to_slur_regex(&local_site); - let sidebar = process_markdown_opt(&data.sidebar, &slur_regex, &context).await?; + let url_blocklist = get_url_blocklist(&context).await?; + let sidebar = process_markdown_opt(&data.sidebar, &slur_regex, &url_blocklist, &context).await?; let icon = proxy_image_link_opt_api(&data.icon, &context).await?; let banner = proxy_image_link_opt_api(&data.banner, &context).await?; @@ -137,6 +141,11 @@ pub async fn update_site( let blocked = data.blocked_instances.clone(); FederationBlockList::replace(&mut context.pool(), blocked).await?; + if let Some(url_blocklist) = data.blocked_urls.clone() { + let parsed_urls = check_urls_are_valid(&url_blocklist)?; + LocalSiteUrlBlocklist::replace(&mut context.pool(), parsed_urls).await?; + } + // TODO can't think of a better way to do this. // If the server suddenly requires email verification, or required applications, no old users // will be able to log in. It really only wants this to be a requirement for NEW signups. @@ -578,6 +587,7 @@ mod tests { captcha_difficulty: None, allowed_instances: None, blocked_instances: None, + blocked_urls: None, taglines: None, registration_mode: site_registration_mode, reports_email_admins: None, diff --git a/crates/apub/src/objects/comment.rs b/crates/apub/src/objects/comment.rs index 6d8d814bf..ba7cc914f 100644 --- a/crates/apub/src/objects/comment.rs +++ b/crates/apub/src/objects/comment.rs @@ -18,7 +18,7 @@ use activitypub_federation::{ use chrono::{DateTime, Utc}; use lemmy_api_common::{ context::LemmyContext, - utils::{is_mod_or_admin, local_site_opt_to_slur_regex, process_markdown}, + utils::{get_url_blocklist, is_mod_or_admin, local_site_opt_to_slur_regex, process_markdown}, }; use lemmy_db_schema::{ source::{ @@ -165,7 +165,8 @@ impl Object for ApubComment { let local_site = LocalSite::read(&mut context.pool()).await.ok(); let slur_regex = &local_site_opt_to_slur_regex(&local_site); - let content = process_markdown(&content, slur_regex, context).await?; + let url_blocklist = get_url_blocklist(context).await?; + let content = process_markdown(&content, slur_regex, &url_blocklist, context).await?; let language_id = LanguageTag::to_language_id_single(note.language, &mut context.pool()).await?; diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index e71f6d9b5..7630d80b2 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -21,6 +21,7 @@ use lemmy_api_common::{ generate_featured_url, generate_moderators_url, generate_outbox_url, + get_url_blocklist, local_site_opt_to_slur_regex, process_markdown_opt, proxy_image_link_opt_apub, @@ -141,8 +142,10 @@ impl Object for ApubCommunity { let local_site = LocalSite::read(&mut context.pool()).await.ok(); let slur_regex = &local_site_opt_to_slur_regex(&local_site); + let url_blocklist = get_url_blocklist(context).await?; let description = read_from_string_or_source_opt(&group.summary, &None, &group.source); - let description = process_markdown_opt(&description, slur_regex, context).await?; + let description = + process_markdown_opt(&description, slur_regex, &url_blocklist, context).await?; let icon = proxy_image_link_opt_apub(group.icon.map(|i| i.url), context).await?; let banner = proxy_image_link_opt_apub(group.image.map(|i| i.url), context).await?; diff --git a/crates/apub/src/objects/instance.rs b/crates/apub/src/objects/instance.rs index 8f4f163db..6894643d6 100644 --- a/crates/apub/src/objects/instance.rs +++ b/crates/apub/src/objects/instance.rs @@ -19,7 +19,12 @@ use activitypub_federation::{ use chrono::{DateTime, Utc}; use lemmy_api_common::{ context::LemmyContext, - utils::{local_site_opt_to_slur_regex, process_markdown_opt, proxy_image_link_opt_apub}, + utils::{ + get_url_blocklist, + local_site_opt_to_slur_regex, + process_markdown_opt, + proxy_image_link_opt_apub, + }, }; use lemmy_db_schema::{ newtypes::InstanceId, @@ -138,8 +143,9 @@ impl Object for ApubSite { let local_site = LocalSite::read(&mut context.pool()).await.ok(); let slur_regex = &local_site_opt_to_slur_regex(&local_site); + let url_blocklist = get_url_blocklist(context).await?; let sidebar = read_from_string_or_source_opt(&apub.content, &None, &apub.source); - let sidebar = process_markdown_opt(&sidebar, slur_regex, context).await?; + let sidebar = process_markdown_opt(&sidebar, slur_regex, &url_blocklist, context).await?; let icon = proxy_image_link_opt_apub(apub.icon.map(|i| i.url), context).await?; let banner = proxy_image_link_opt_apub(apub.image.map(|i| i.url), context).await?; diff --git a/crates/apub/src/objects/person.rs b/crates/apub/src/objects/person.rs index 7bfb68a04..d4456344f 100644 --- a/crates/apub/src/objects/person.rs +++ b/crates/apub/src/objects/person.rs @@ -22,6 +22,7 @@ use lemmy_api_common::{ context::LemmyContext, utils::{ generate_outbox_url, + get_url_blocklist, local_site_opt_to_slur_regex, process_markdown_opt, proxy_image_link_opt_apub, @@ -152,8 +153,9 @@ impl Object for ApubPerson { let local_site = LocalSite::read(&mut context.pool()).await.ok(); let slur_regex = &local_site_opt_to_slur_regex(&local_site); + let url_blocklist = get_url_blocklist(context).await?; let bio = read_from_string_or_source_opt(&person.summary, &None, &person.source); - let bio = process_markdown_opt(&bio, slur_regex, context).await?; + let bio = process_markdown_opt(&bio, slur_regex, &url_blocklist, context).await?; let avatar = proxy_image_link_opt_apub(person.icon.map(|i| i.url), context).await?; let banner = proxy_image_link_opt_apub(person.image.map(|i| i.url), context).await?; diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index ff42b9cbd..15184b622 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -26,6 +26,7 @@ use lemmy_api_common::{ context::LemmyContext, request::fetch_link_metadata_opt, utils::{ + get_url_blocklist, local_site_opt_to_sensitive, local_site_opt_to_slur_regex, process_markdown_opt, @@ -246,9 +247,10 @@ impl Object for ApubPost { let thumbnail_url = proxy_image_link_opt_apub(thumbnail_url, context).await?; let slur_regex = &local_site_opt_to_slur_regex(&local_site); + let url_blocklist = get_url_blocklist(context).await?; let body = read_from_string_or_source_opt(&page.content, &page.media_type, &page.source); - let body = process_markdown_opt(&body, slur_regex, context).await?; + let body = process_markdown_opt(&body, slur_regex, &url_blocklist, context).await?; let language_id = LanguageTag::to_language_id_single(page.language, &mut context.pool()).await?; diff --git a/crates/apub/src/objects/private_message.rs b/crates/apub/src/objects/private_message.rs index d5c00632f..647510802 100644 --- a/crates/apub/src/objects/private_message.rs +++ b/crates/apub/src/objects/private_message.rs @@ -14,7 +14,7 @@ use activitypub_federation::{ use chrono::{DateTime, Utc}; use lemmy_api_common::{ context::LemmyContext, - utils::{check_person_block, local_site_opt_to_slur_regex, process_markdown}, + utils::{check_person_block, get_url_blocklist, local_site_opt_to_slur_regex, process_markdown}, }; use lemmy_db_schema::{ source::{ @@ -127,8 +127,9 @@ impl Object for ApubPrivateMessage { let local_site = LocalSite::read(&mut context.pool()).await.ok(); let slur_regex = &local_site_opt_to_slur_regex(&local_site); + let url_blocklist = get_url_blocklist(context).await?; let content = read_from_string_or_source(¬e.content, &None, ¬e.source); - let content = process_markdown(&content, slur_regex, context).await?; + let content = process_markdown(&content, slur_regex, &url_blocklist, context).await?; let form = PrivateMessageInsertForm { creator_id: creator.id, diff --git a/crates/db_schema/src/impls/local_site_url_blocklist.rs b/crates/db_schema/src/impls/local_site_url_blocklist.rs new file mode 100644 index 000000000..73dedabce --- /dev/null +++ b/crates/db_schema/src/impls/local_site_url_blocklist.rs @@ -0,0 +1,49 @@ +use crate::{ + schema::local_site_url_blocklist, + source::local_site_url_blocklist::{LocalSiteUrlBlocklist, LocalSiteUrlBlocklistForm}, + utils::{get_conn, DbPool}, +}; +use diesel::{dsl::insert_into, result::Error}; +use diesel_async::{AsyncPgConnection, RunQueryDsl}; + +impl LocalSiteUrlBlocklist { + pub async fn replace(pool: &mut DbPool<'_>, url_blocklist: Vec) -> Result<(), Error> { + let conn = &mut get_conn(pool).await?; + + conn + .build_transaction() + .run(|conn| { + Box::pin(async move { + use crate::schema::local_site_url_blocklist::dsl::local_site_url_blocklist; + + Self::clear(conn).await?; + + let forms = url_blocklist + .into_iter() + .map(|url| LocalSiteUrlBlocklistForm { url, updated: None }) + .collect::>(); + + insert_into(local_site_url_blocklist) + .values(forms) + .execute(conn) + .await?; + + Ok(()) + }) as _ + }) + .await + } + + async fn clear(conn: &mut AsyncPgConnection) -> Result { + diesel::delete(local_site_url_blocklist::table) + .execute(conn) + .await + } + + pub async fn get_all(pool: &mut DbPool<'_>) -> Result, Error> { + let conn = &mut get_conn(pool).await?; + local_site_url_blocklist::table + .get_results::(conn) + .await + } +} diff --git a/crates/db_schema/src/impls/mod.rs b/crates/db_schema/src/impls/mod.rs index 711a6c4e6..3a4e71307 100644 --- a/crates/db_schema/src/impls/mod.rs +++ b/crates/db_schema/src/impls/mod.rs @@ -17,6 +17,7 @@ pub mod instance_block; pub mod language; pub mod local_site; pub mod local_site_rate_limit; +pub mod local_site_url_blocklist; pub mod local_user; pub mod local_user_vote_display_mode; pub mod login_token; diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index a61b2d24f..408ed0540 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -409,6 +409,15 @@ diesel::table! { } } +diesel::table! { + local_site_url_blocklist (id) { + id -> Int4, + url -> Text, + published -> Timestamptz, + updated -> Nullable, + } +} + diesel::table! { use diesel::sql_types::*; use super::sql_types::SortTypeEnum; @@ -1052,6 +1061,7 @@ diesel::allow_tables_to_appear_in_same_query!( local_image, local_site, local_site_rate_limit, + local_site_url_blocklist, local_user, local_user_language, local_user_vote_display_mode, diff --git a/crates/db_schema/src/source/local_site_url_blocklist.rs b/crates/db_schema/src/source/local_site_url_blocklist.rs new file mode 100644 index 000000000..4ac0893ec --- /dev/null +++ b/crates/db_schema/src/source/local_site_url_blocklist.rs @@ -0,0 +1,28 @@ +#[cfg(feature = "full")] +use crate::schema::local_site_url_blocklist; +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; + +#[skip_serializing_none] +#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "full", derive(Queryable, Selectable, Identifiable, TS))] +#[cfg_attr(feature = "full", diesel(table_name = local_site_url_blocklist))] +#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))] +#[cfg_attr(feature = "full", ts(export))] +pub struct LocalSiteUrlBlocklist { + pub id: i32, + pub url: String, + pub published: DateTime, + pub updated: Option>, +} + +#[derive(Default, Clone)] +#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] +#[cfg_attr(feature = "full", diesel(table_name = local_site_url_blocklist))] +pub struct LocalSiteUrlBlocklistForm { + pub url: String, + pub updated: Option>, +} diff --git a/crates/db_schema/src/source/mod.rs b/crates/db_schema/src/source/mod.rs index ab82a114c..3a6501717 100644 --- a/crates/db_schema/src/source/mod.rs +++ b/crates/db_schema/src/source/mod.rs @@ -22,6 +22,7 @@ pub mod instance_block; pub mod language; pub mod local_site; pub mod local_site_rate_limit; +pub mod local_site_url_blocklist; pub mod local_user; pub mod local_user_vote_display_mode; pub mod login_token; diff --git a/crates/utils/src/error.rs b/crates/utils/src/error.rs index 9da018960..d25845894 100644 --- a/crates/utils/src/error.rs +++ b/crates/utils/src/error.rs @@ -135,6 +135,7 @@ pub enum LemmyErrorType { CouldntSetAllRegistrationsAccepted, CouldntSetAllEmailVerified, Banned, + BlockedUrl, CouldntGetComments, CouldntGetPosts, InvalidUrl, diff --git a/crates/utils/src/utils/markdown/mod.rs b/crates/utils/src/utils/markdown/mod.rs index bee2dcb94..c3def13a7 100644 --- a/crates/utils/src/utils/markdown/mod.rs +++ b/crates/utils/src/utils/markdown/mod.rs @@ -1,6 +1,7 @@ -use crate::settings::SETTINGS; +use crate::{error::LemmyResult, settings::SETTINGS, LemmyErrorType}; use markdown_it::{plugins::cmark::inline::image::Image, MarkdownIt}; use once_cell::sync::Lazy; +use regex::RegexSet; use url::Url; use urlencoding::encode; @@ -98,6 +99,13 @@ pub fn markdown_rewrite_image_links(mut src: String) -> (String, Vec) { (src, links) } +pub fn markdown_check_for_blocked_urls(text: &str, blocklist: &RegexSet) -> LemmyResult<()> { + if blocklist.is_match(text) { + Err(LemmyErrorType::BlockedUrl)? + } + Ok(()) +} + #[cfg(test)] mod tests { #![allow(clippy::unwrap_used)] @@ -109,65 +117,65 @@ mod tests { #[test] fn test_basic_markdown() { let tests: Vec<_> = vec![ - ( - "headings", - "# h1\n## h2\n### h3\n#### h4\n##### h5\n###### h6", - "

h1

\n

h2

\n

h3

\n

h4

\n
h5
\n
h6
\n" - ), - ( - "line breaks", - "First\rSecond", - "

First\nSecond

\n"), - ( - "emphasis", - "__bold__ **bold** *italic* ***bold+italic***", - "

bold bold italic bold+italic

\n" - ), - ( - "blockquotes", - "> #### Hello\n > \n > - Hola\n > - 안영 \n>> Goodbye\n", - "
\n

Hello

\n
    \n
  • Hola
  • \n
  • 안영
  • \n
\n
\n

Goodbye

\n
\n
\n" - ), - ( - "lists (ordered, unordered)", - "1. pen\n2. apple\n3. apple pen\n- pen\n- pineapple\n- pineapple pen", - "
    \n
  1. pen
  2. \n
  3. apple
  4. \n
  5. apple pen
  6. \n
\n
    \n
  • pen
  • \n
  • pineapple
  • \n
  • pineapple pen
  • \n
\n" - ), - ( - "code and code blocks", - "this is my amazing `code snippet` and my amazing ```code block```", - "

this is my amazing code snippet and my amazing code block

\n" - ), - // Links with added nofollow attribute - ( - "links", - "[Lemmy](https://join-lemmy.org/ \"Join Lemmy!\")", - "

Lemmy

\n" - ), - // Remote images with proxy - ( - "images", - "![My linked image](https://example.com/image.png \"image alt text\")", - "

\"My

\n" - ), - // Local images without proxy - ( - "images", - "![My linked image](https://lemmy-alpha/image.png \"image alt text\")", - "

\"My

\n" - ), - // Ensure spoiler plugin is added - ( - "basic spoiler", - "::: spoiler click to see more\nhow spicy!\n:::\n", - "
click to see more

how spicy!\n

\n" - ), - ( - "escape html special chars", - " hello &\"", - "

<script>alert(‘xss’);</script> hello &"

\n" - ) - ]; + ( + "headings", + "# h1\n## h2\n### h3\n#### h4\n##### h5\n###### h6", + "

h1

\n

h2

\n

h3

\n

h4

\n
h5
\n
h6
\n" + ), + ( + "line breaks", + "First\rSecond", + "

First\nSecond

\n"), + ( + "emphasis", + "__bold__ **bold** *italic* ***bold+italic***", + "

bold bold italic bold+italic

\n" + ), + ( + "blockquotes", + "> #### Hello\n > \n > - Hola\n > - 안영 \n>> Goodbye\n", + "
\n

Hello

\n
    \n
  • Hola
  • \n
  • 안영
  • \n
\n
\n

Goodbye

\n
\n
\n" + ), + ( + "lists (ordered, unordered)", + "1. pen\n2. apple\n3. apple pen\n- pen\n- pineapple\n- pineapple pen", + "
    \n
  1. pen
  2. \n
  3. apple
  4. \n
  5. apple pen
  6. \n
\n
    \n
  • pen
  • \n
  • pineapple
  • \n
  • pineapple pen
  • \n
\n" + ), + ( + "code and code blocks", + "this is my amazing `code snippet` and my amazing ```code block```", + "

this is my amazing code snippet and my amazing code block

\n" + ), + // Links with added nofollow attribute + ( + "links", + "[Lemmy](https://join-lemmy.org/ \"Join Lemmy!\")", + "

Lemmy

\n" + ), + // Remote images with proxy + ( + "images", + "![My linked image](https://example.com/image.png \"image alt text\")", + "

\"My

\n" + ), + // Local images without proxy + ( + "images", + "![My linked image](https://lemmy-alpha/image.png \"image alt text\")", + "

\"My

\n" + ), + // Ensure spoiler plugin is added + ( + "basic spoiler", + "::: spoiler click to see more\nhow spicy!\n:::\n", + "
click to see more

how spicy!\n

\n" + ), + ( + "escape html special chars", + " hello &\"", + "

<script>alert(‘xss’);</script> hello &"

\n" + ) + ]; tests.iter().for_each(|&(msg, input, expected)| { let result = markdown_to_html(input); @@ -184,46 +192,46 @@ mod tests { fn test_markdown_proxy_images() { let tests: Vec<_> = vec![ - ( - "remote image proxied", - "![link](http://example.com/image.jpg)", - "![link](https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage.jpg)", - ), - ( - "local image unproxied", - "![link](http://lemmy-alpha/image.jpg)", - "![link](http://lemmy-alpha/image.jpg)", - ), - ( - "multiple image links", - "![link](http://example.com/image1.jpg) ![link](http://example.com/image2.jpg)", - "![link](https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage1.jpg) ![link](https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage2.jpg)", - ), - ( - "empty link handled", - "![image]()", - "![image]()" - ), - ( - "empty label handled", - "![](http://example.com/image.jpg)", - "![](https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage.jpg)" - ), - ( - "invalid image link removed", - "![image](http-not-a-link)", - "![image]()" - ), - ( - "label with nested markdown handled", - "![a *b* c](http://example.com/image.jpg)", - "![a *b* c](https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage.jpg)" - ), - ( - "custom emoji support", - r#"![party-blob](https://www.hexbear.net/pictrs/image/83405746-0620-4728-9358-5f51b040ffee.gif "emoji party-blob")"#, - r#"![party-blob](https://lemmy-alpha/api/v3/image_proxy?url=https%3A%2F%2Fwww.hexbear.net%2Fpictrs%2Fimage%2F83405746-0620-4728-9358-5f51b040ffee.gif "emoji party-blob")"# - ) + ( + "remote image proxied", + "![link](http://example.com/image.jpg)", + "![link](https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage.jpg)", + ), + ( + "local image unproxied", + "![link](http://lemmy-alpha/image.jpg)", + "![link](http://lemmy-alpha/image.jpg)", + ), + ( + "multiple image links", + "![link](http://example.com/image1.jpg) ![link](http://example.com/image2.jpg)", + "![link](https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage1.jpg) ![link](https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage2.jpg)", + ), + ( + "empty link handled", + "![image]()", + "![image]()" + ), + ( + "empty label handled", + "![](http://example.com/image.jpg)", + "![](https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage.jpg)" + ), + ( + "invalid image link removed", + "![image](http-not-a-link)", + "![image]()" + ), + ( + "label with nested markdown handled", + "![a *b* c](http://example.com/image.jpg)", + "![a *b* c](https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage.jpg)" + ), + ( + "custom emoji support", + r#"![party-blob](https://www.hexbear.net/pictrs/image/83405746-0620-4728-9358-5f51b040ffee.gif "emoji party-blob")"#, + r#"![party-blob](https://lemmy-alpha/api/v3/image_proxy?url=https%3A%2F%2Fwww.hexbear.net%2Fpictrs%2Fimage%2F83405746-0620-4728-9358-5f51b040ffee.gif "emoji party-blob")"# + ) ]; tests.iter().for_each(|&(msg, input, expected)| { @@ -237,6 +245,69 @@ mod tests { }); } + #[test] + fn test_url_blocking() { + let set = RegexSet::new(vec![r"(https://)?example\.com/?"]).unwrap(); + + assert!( + markdown_check_for_blocked_urls(&String::from("[](https://example.com)"), &set).is_err() + ); + + assert!(markdown_check_for_blocked_urls( + &String::from("Go to https://example.com to get free Robux"), + &set + ) + .is_err()); + + assert!( + markdown_check_for_blocked_urls(&String::from("[](https://example.blog)"), &set).is_ok() + ); + + assert!(markdown_check_for_blocked_urls(&String::from("example.com"), &set).is_err()); + + assert!(markdown_check_for_blocked_urls( + "Odio exercitationem culpa sed sunt + et. Sit et similique tempora deserunt doloremque. Cupiditate iusto + repellat et quis qui. Cum veritatis facere quasi repellendus sunt + eveniet nemo sint. Cumque sit unde est. https://example.com Alias + repellendus at quos.", + &set + ) + .is_err()); + + let set = RegexSet::new(vec![r"(https://)?example\.com/spam\.jpg"]).unwrap(); + assert!(markdown_check_for_blocked_urls( + &String::from("![](https://example.com/spam.jpg)"), + &set + ) + .is_err()); + + let set = RegexSet::new(vec![ + r"(https://)?quo\.example\.com/?", + r"(https://)?foo\.example\.com/?", + r"(https://)?bar\.example\.com/?", + ]) + .unwrap(); + + assert!( + markdown_check_for_blocked_urls(&String::from("https://baz.example.com"), &set).is_ok() + ); + + assert!( + markdown_check_for_blocked_urls(&String::from("https://bar.example.com"), &set).is_err() + ); + + let set = RegexSet::new(vec![r"(https://)?example\.com/banned_page"]).unwrap(); + + assert!( + markdown_check_for_blocked_urls(&String::from("https://example.com/page"), &set).is_ok() + ); + + let set = RegexSet::new(vec![r"(https://)?ex\.mple\.com/?"]).unwrap(); + + assert!(markdown_check_for_blocked_urls("example.com", &set).is_ok()); + } + #[test] fn test_sanitize_html() { let sanitized = sanitize_html(" hello &\"'"); diff --git a/crates/utils/src/utils/validation.rs b/crates/utils/src/utils/validation.rs index 23ef9744a..f9b2a87e5 100644 --- a/crates/utils/src/utils/validation.rs +++ b/crates/utils/src/utils/validation.rs @@ -1,8 +1,8 @@ use crate::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; use itertools::Itertools; use once_cell::sync::Lazy; -use regex::{Regex, RegexBuilder}; -use url::Url; +use regex::{Regex, RegexBuilder, RegexSet}; +use url::{ParseError, Url}; // From here: https://github.com/vector-im/element-android/blob/develop/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/MatrixPatterns.kt#L35 static VALID_MATRIX_ID_REGEX: Lazy = Lazy::new(|| { @@ -299,6 +299,33 @@ pub fn check_url_scheme(url: &Option) -> LemmyResult<()> { } } +pub fn is_url_blocked(url: &Option, blocklist: &RegexSet) -> LemmyResult<()> { + if let Some(url) = url { + if blocklist.is_match(url.as_str()) { + Err(LemmyErrorType::BlockedUrl)? + } + } + + Ok(()) +} + +pub fn check_urls_are_valid(urls: &Vec) -> LemmyResult> { + let mut parsed_urls = vec![]; + for url in urls { + let url = Url::parse(url).or_else(|e| { + if e == ParseError::RelativeUrlWithoutBase { + Url::parse(&format!("https://{url}")) + } else { + Err(e) + } + })?; + + parsed_urls.push(url.to_string()); + } + + Ok(parsed_urls) +} + #[cfg(test)] mod tests { #![allow(clippy::unwrap_used)] @@ -310,7 +337,9 @@ mod tests { build_and_check_regex, check_site_visibility_valid, check_url_scheme, + check_urls_are_valid, clean_url_params, + is_url_blocked, is_valid_actor_name, is_valid_bio_field, is_valid_display_name, @@ -550,4 +579,38 @@ mod tests { let magnet_link="magnet:?xt=urn:btih:4b390af3891e323778959d5abfff4b726510f14c&dn=Ravel%20Complete%20Piano%20Sheet%20Music%20-%20Public%20Domain&tr=udp%3A%2F%2Fopen.tracker.cl%3A1337%2Fannounce"; assert!(check_url_scheme(&Some(Url::parse(magnet_link).unwrap())).is_ok()); } + + #[test] + fn test_url_block() { + let set = regex::RegexSet::new(vec![ + r"(https://)?example\.org/page/to/article", + r"(https://)?example\.net/?", + r"(https://)?example\.com/?", + ]) + .unwrap(); + + assert!(is_url_blocked(&Some(Url::parse("https://example.blog").unwrap()), &set).is_ok()); + + assert!(is_url_blocked(&Some(Url::parse("https://example.org").unwrap()), &set).is_ok()); + + assert!(is_url_blocked(&None, &set).is_ok()); + + assert!(is_url_blocked(&Some(Url::parse("https://example.com").unwrap()), &set).is_err()); + } + + #[test] + fn test_url_parsed() { + assert_eq!( + vec![String::from("https://example.com/")], + check_urls_are_valid(&vec![String::from("example.com")]).unwrap() + ); + + assert!(check_urls_are_valid(&vec![ + String::from("example.com"), + String::from("https://example.blog") + ]) + .is_ok()); + + assert!(check_urls_are_valid(&vec![String::from("https://example .com"),]).is_err()); + } } diff --git a/migrations/2024-03-06-201637_url_blocklist/down.sql b/migrations/2024-03-06-201637_url_blocklist/down.sql new file mode 100644 index 000000000..442f3c922 --- /dev/null +++ b/migrations/2024-03-06-201637_url_blocklist/down.sql @@ -0,0 +1,3 @@ +-- This file should undo anything in `up.sql` +DROP TABLE local_site_url_blocklist; + diff --git a/migrations/2024-03-06-201637_url_blocklist/up.sql b/migrations/2024-03-06-201637_url_blocklist/up.sql new file mode 100644 index 000000000..bb9b704b4 --- /dev/null +++ b/migrations/2024-03-06-201637_url_blocklist/up.sql @@ -0,0 +1,7 @@ +CREATE TABLE local_site_url_blocklist ( + id serial NOT NULL PRIMARY KEY, + url text NOT NULL UNIQUE, + published timestamp with time zone NOT NULL DEFAULT now(), + updated timestamp with time zone +); + From 43378c5bb3149f3e8c71eacfb48b93ac9250d09a Mon Sep 17 00:00:00 2001 From: Nutomic Date: Fri, 15 Mar 2024 13:41:16 +0100 Subject: [PATCH 16/31] Fix video thumbnail generation (fixes #3484) (#4539) * Fix video thumbnail generation (fixes #3484) * fix test --- crates/api_common/src/request.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/crates/api_common/src/request.rs b/crates/api_common/src/request.rs index aaae7f866..c17d96a61 100644 --- a/crates/api_common/src/request.rs +++ b/crates/api_common/src/request.rs @@ -59,14 +59,8 @@ pub async fn fetch_link_metadata( let opengraph_data = extract_opengraph_data(&html_bytes, url) .map_err(|e| info!("{e}")) .unwrap_or_default(); - let thumbnail = extract_thumbnail_from_opengraph_data( - url, - &opengraph_data, - &content_type, - generate_thumbnail, - context, - ) - .await; + let thumbnail = + extract_thumbnail_from_opengraph_data(url, &opengraph_data, generate_thumbnail, context).await; Ok(LinkMetadata { opengraph_data, @@ -158,23 +152,21 @@ fn extract_opengraph_data(html_bytes: &[u8], url: &Url) -> Result, generate_thumbnail: bool, context: &LemmyContext, ) -> Option { - let is_image = content_type.as_ref().unwrap_or(&mime::TEXT_PLAIN).type_() == mime::IMAGE; - if generate_thumbnail && is_image { + if generate_thumbnail { let image_url = opengraph_data .image .as_ref() - .map(lemmy_db_schema::newtypes::DbUrl::inner) + .map(DbUrl::inner) .unwrap_or(url); generate_pictrs_thumbnail(image_url, context) .await .ok() .map(Into::into) } else { - None + opengraph_data.image.clone() } } @@ -363,7 +355,7 @@ mod tests { Some(mime::TEXT_HTML_UTF_8.to_string()), sample_res.content_type ); - assert_eq!(None, sample_res.thumbnail); + assert!(sample_res.thumbnail.is_some()); } // #[test] From 9d4299aaac16b92b8c9180506535d733ef8e3df8 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Fri, 15 Mar 2024 13:42:09 +0100 Subject: [PATCH 17/31] Dont require leading ! or @ for webfinger resolve (#4513) * Dont require leading ! or @ for webfinger resolve * fmt * clippy --- api_tests/src/user.spec.ts | 6 +-- crates/apub/src/api/resolve_object.rs | 27 +++++------ crates/apub/src/fetcher/search.rs | 65 ++++++++++++--------------- 3 files changed, 46 insertions(+), 52 deletions(-) diff --git a/api_tests/src/user.spec.ts b/api_tests/src/user.spec.ts index ccfc5e1fe..4846d60f7 100644 --- a/api_tests/src/user.spec.ts +++ b/api_tests/src/user.spec.ts @@ -45,7 +45,7 @@ test("Create user", async () => { if (!site.my_user) { throw "Missing site user"; } - apShortname = `@${site.my_user.local_user_view.person.name}@lemmy-alpha:8541`; + apShortname = `${site.my_user.local_user_view.person.name}@lemmy-alpha:8541`; }); test("Set some user settings, check that they are federated", async () => { @@ -68,7 +68,7 @@ test("Delete user", async () => { let user = await registerUser(alpha, alphaUrl); // make a local post and comment - let alphaCommunity = (await resolveCommunity(user, "!main@lemmy-alpha:8541")) + let alphaCommunity = (await resolveCommunity(user, "main@lemmy-alpha:8541")) .community; if (!alphaCommunity) { throw "Missing alpha community"; @@ -134,7 +134,7 @@ test("Create user with Arabic name", async () => { if (!site.my_user) { throw "Missing site user"; } - apShortname = `@${site.my_user.local_user_view.person.name}@lemmy-alpha:8541`; + apShortname = `${site.my_user.local_user_view.person.name}@lemmy-alpha:8541`; let alphaPerson = (await resolvePerson(alpha, apShortname)).person; expect(alphaPerson).toBeDefined(); diff --git a/crates/apub/src/api/resolve_object.rs b/crates/apub/src/api/resolve_object.rs index e081377f6..6d672a8cd 100644 --- a/crates/apub/src/api/resolve_object.rs +++ b/crates/apub/src/api/resolve_object.rs @@ -1,7 +1,6 @@ -use crate::fetcher::search::{ - search_query_to_object_id, - search_query_to_object_id_local, - SearchableObjects, +use crate::fetcher::{ + search::{search_query_to_object_id, search_query_to_object_id_local, SearchableObjects}, + user_or_community::UserOrCommunity, }; use activitypub_federation::config::Data; use actix_web::web::{Json, Query}; @@ -31,7 +30,7 @@ pub async fn resolve_object( let res = if is_authenticated { // user is fully authenticated; allow remote lookups as well. - search_query_to_object_id(&data.q, &context).await + search_query_to_object_id(data.q.clone(), &context).await } else { // user isn't authenticated only allow a local search. search_query_to_object_id_local(&data.q, &context).await @@ -52,14 +51,6 @@ async fn convert_response( let removed_or_deleted; let mut res = ResolveObjectResponse::default(); match object { - Person(p) => { - removed_or_deleted = p.deleted; - res.person = Some(PersonView::read(pool, p.id).await?) - } - Community(c) => { - removed_or_deleted = c.deleted || c.removed; - res.community = Some(CommunityView::read(pool, c.id, user_id, false).await?) - } Post(p) => { removed_or_deleted = p.deleted || p.removed; res.post = Some(PostView::read(pool, p.id, user_id, false).await?) @@ -68,6 +59,16 @@ async fn convert_response( removed_or_deleted = c.deleted || c.removed; res.comment = Some(CommentView::read(pool, c.id, user_id).await?) } + PersonOrCommunity(p) => match *p { + UserOrCommunity::User(u) => { + removed_or_deleted = u.deleted; + res.person = Some(PersonView::read(pool, u.id).await?) + } + UserOrCommunity::Community(c) => { + removed_or_deleted = c.deleted || c.removed; + res.community = Some(CommunityView::read(pool, c.id, user_id, false).await?) + } + }, }; // if the object was deleted from database, dont return it if removed_or_deleted { diff --git a/crates/apub/src/fetcher/search.rs b/crates/apub/src/fetcher/search.rs index 54951edd9..74d755da0 100644 --- a/crates/apub/src/fetcher/search.rs +++ b/crates/apub/src/fetcher/search.rs @@ -1,6 +1,7 @@ use crate::{ + fetcher::user_or_community::{PersonOrGroup, UserOrCommunity}, objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson, post::ApubPost}, - protocol::objects::{group::Group, note::Note, page::Page, person::Person}, + protocol::objects::{note::Note, page::Page}, }; use activitypub_federation::{ config::Data, @@ -9,7 +10,7 @@ use activitypub_federation::{ }; use chrono::{DateTime, Utc}; use lemmy_api_common::context::LemmyContext; -use lemmy_utils::error::{LemmyError, LemmyErrorType}; +use lemmy_utils::error::LemmyError; use serde::Deserialize; use url::Url; @@ -18,28 +19,22 @@ use url::Url; /// which gets resolved to an URL. #[tracing::instrument(skip_all)] pub(crate) async fn search_query_to_object_id( - query: &str, + mut query: String, context: &Data, ) -> Result { - Ok(match Url::parse(query) { + Ok(match Url::parse(&query) { Ok(url) => { // its already an url, just go with it ObjectId::from(url).dereference(context).await? } Err(_) => { // not an url, try to resolve via webfinger - let mut chars = query.chars(); - let kind = chars.next(); - let identifier = chars.as_str(); - match kind { - Some('@') => SearchableObjects::Person( - webfinger_resolve_actor::(identifier, context).await?, - ), - Some('!') => SearchableObjects::Community( - webfinger_resolve_actor::(identifier, context).await?, - ), - _ => return Err(LemmyErrorType::InvalidQuery)?, + if query.starts_with('!') || query.starts_with('@') { + query.remove(0); } + SearchableObjects::PersonOrCommunity(Box::new( + webfinger_resolve_actor::(&query, context).await?, + )) } }) } @@ -59,19 +54,17 @@ pub(crate) async fn search_query_to_object_id_local( /// The types of ActivityPub objects that can be fetched directly by searching for their ID. #[derive(Debug)] pub(crate) enum SearchableObjects { - Person(ApubPerson), - Community(ApubCommunity), Post(ApubPost), Comment(ApubComment), + PersonOrCommunity(Box), } #[derive(Deserialize)] #[serde(untagged)] pub(crate) enum SearchableKinds { - Group(Group), - Person(Person), - Page(Page), + Page(Box), Note(Note), + PersonOrGroup(Box), } #[async_trait::async_trait] @@ -82,10 +75,9 @@ impl Object for SearchableObjects { fn last_refreshed_at(&self) -> Option> { match self { - SearchableObjects::Person(p) => p.last_refreshed_at(), - SearchableObjects::Community(c) => c.last_refreshed_at(), SearchableObjects::Post(p) => p.last_refreshed_at(), SearchableObjects::Comment(c) => c.last_refreshed_at(), + SearchableObjects::PersonOrCommunity(p) => p.last_refreshed_at(), } } @@ -99,13 +91,9 @@ impl Object for SearchableObjects { object_id: Url, context: &Data, ) -> Result, LemmyError> { - let c = ApubCommunity::read_from_id(object_id.clone(), context).await?; - if let Some(c) = c { - return Ok(Some(SearchableObjects::Community(c))); - } - let p = ApubPerson::read_from_id(object_id.clone(), context).await?; - if let Some(p) = p { - return Ok(Some(SearchableObjects::Person(p))); + let uc = UserOrCommunity::read_from_id(object_id.clone(), context).await?; + if let Some(uc) = uc { + return Ok(Some(SearchableObjects::PersonOrCommunity(Box::new(uc)))); } let p = ApubPost::read_from_id(object_id.clone(), context).await?; if let Some(p) = p { @@ -121,10 +109,12 @@ impl Object for SearchableObjects { #[tracing::instrument(skip_all)] async fn delete(self, data: &Data) -> Result<(), LemmyError> { match self { - SearchableObjects::Person(p) => p.delete(data).await, - SearchableObjects::Community(c) => c.delete(data).await, SearchableObjects::Post(p) => p.delete(data).await, SearchableObjects::Comment(c) => c.delete(data).await, + SearchableObjects::PersonOrCommunity(pc) => match *pc { + UserOrCommunity::User(p) => p.delete(data).await, + UserOrCommunity::Community(c) => c.delete(data).await, + }, } } @@ -139,10 +129,12 @@ impl Object for SearchableObjects { data: &Data, ) -> Result<(), LemmyError> { match apub { - SearchableKinds::Group(a) => ApubCommunity::verify(a, expected_domain, data).await, - SearchableKinds::Person(a) => ApubPerson::verify(a, expected_domain, data).await, SearchableKinds::Page(a) => ApubPost::verify(a, expected_domain, data).await, SearchableKinds::Note(a) => ApubComment::verify(a, expected_domain, data).await, + SearchableKinds::PersonOrGroup(pg) => match pg.as_ref() { + PersonOrGroup::Person(a) => ApubPerson::verify(a, expected_domain, data).await, + PersonOrGroup::Group(a) => ApubCommunity::verify(a, expected_domain, data).await, + }, } } @@ -151,10 +143,11 @@ impl Object for SearchableObjects { use SearchableKinds as SAT; use SearchableObjects as SO; Ok(match apub { - SAT::Group(g) => SO::Community(ApubCommunity::from_json(g, context).await?), - SAT::Person(p) => SO::Person(ApubPerson::from_json(p, context).await?), - SAT::Page(p) => SO::Post(ApubPost::from_json(p, context).await?), + SAT::Page(p) => SO::Post(ApubPost::from_json(*p, context).await?), SAT::Note(n) => SO::Comment(ApubComment::from_json(n, context).await?), + SAT::PersonOrGroup(pg) => { + SO::PersonOrCommunity(Box::new(UserOrCommunity::from_json(*pg, context).await?)) + } }) } } From 0f77951e05d3b95e6c0cf41a8eaa515481753fc5 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 18 Mar 2024 05:36:49 -0400 Subject: [PATCH 18/31] Upgrading deps. (#4537) * Upgrading deps. * Addressing PR comments --- Cargo.lock | 880 ++++++++++++++++++----------- Cargo.toml | 28 +- api_tests/package.json | 10 +- api_tests/pnpm-lock.yaml | 178 +++--- crates/api/Cargo.toml | 2 +- crates/db_schema/src/impls/post.rs | 6 +- crates/db_schema/src/utils.rs | 4 +- crates/federate/src/worker.rs | 13 +- crates/utils/Cargo.toml | 4 +- 9 files changed, 686 insertions(+), 439 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b9ebfa540..5ef691e26 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -64,11 +64,11 @@ dependencies = [ [[package]] name = "actix-codec" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "617a8268e3537fe1d8c9ead925fca49ef6400927ee7bc26750e90ecee14ce4b8" +checksum = "5f7b0a21988c1bf877cf4759ef5ddaac04c1c9fe808c9142ecb78ba97d97a28a" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.2", "bytes", "futures-core", "futures-sink", @@ -157,7 +157,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb" dependencies = [ "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -246,8 +246,10 @@ dependencies = [ "futures-core", "impl-more", "pin-project-lite", + "rustls-pki-types", "tokio", "tokio-rustls 0.23.4", + "tokio-rustls 0.25.0", "tokio-util", "tracing", "webpki-roots 0.22.6", @@ -313,7 +315,7 @@ dependencies = [ "actix-router", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -361,9 +363,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "ahash" -version = "0.8.7" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", "getrandom", @@ -419,9 +421,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.11" +version = "0.6.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5" +checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" dependencies = [ "anstyle", "anstyle-parse", @@ -433,9 +435,9 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.4" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" [[package]] name = "anstyle-parse" @@ -467,9 +469,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.79" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" +checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" dependencies = [ "backtrace", ] @@ -531,7 +533,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -542,7 +544,7 @@ checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -654,6 +656,35 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bb8" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df7c2093d15d6a1d33b1f972e1c5ea3177748742b97a5f392aa83a65262c6780" +dependencies = [ + "async-trait", + "futures-channel", + "futures-util", + "parking_lot 0.12.1", + "tokio", +] + +[[package]] +name = "bcder" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c627747a6774aab38beb35990d88309481378558875a41da1a4b2e373c906ef0" +dependencies = [ + "bytes", + "smallvec", +] + [[package]] name = "bcrypt" version = "0.15.0" @@ -702,6 +733,9 @@ name = "bitflags" version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +dependencies = [ + "serde", +] [[package]] name = "block-buffer" @@ -722,6 +756,12 @@ dependencies = [ "cipher", ] +[[package]] +name = "blurhash-update" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfb5ea45aeb912f2dd334834e64ecf674a6673d57c73e9d12de0298b9bf98ee8" + [[package]] name = "brotli" version = "3.4.0" @@ -745,9 +785,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.14.0" +version = "3.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" +checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" [[package]] name = "bytecount" @@ -757,9 +797,9 @@ checksum = "e1e5f035d16fc623ae5f74981db80a439803888314e3a555fd6f04acd51a3205" [[package]] name = "bytemuck" -version = "1.14.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "374d28ec25809ee0e23827c2ab573d729e293f281dfe393500e7ad618baa61c6" +checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" [[package]] name = "byteorder" @@ -807,9 +847,9 @@ dependencies = [ [[package]] name = "cargo-platform" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ceed8ef69d8518a5dda55c07425450b58a4e1946f4951eab6d7191ee86c2443d" +checksum = "694c8807f2ae16faecc43dc17d74b3eb042482789fd0eb64b39a2e04e087053f" dependencies = [ "serde", ] @@ -829,9 +869,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.83" +version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" dependencies = [ "jobserver", "libc", @@ -851,9 +891,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.34" +version = "0.4.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" +checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" dependencies = [ "android-tzdata", "iana-time-zone", @@ -861,7 +901,7 @@ dependencies = [ "num-traits", "serde", "wasm-bindgen", - "windows-targets 0.52.0", + "windows-targets 0.52.4", ] [[package]] @@ -886,9 +926,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.18" +version = "4.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e578d6ec4194633722ccf9544794b71b1385c3c027efe0c55db226fc880865c" +checksum = "b230ab84b0ffdf890d5a10abdbc8b83ae1c4918275daea1ab8801f71536b2651" dependencies = [ "clap_builder", "clap_derive", @@ -896,33 +936,33 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.18" +version = "4.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4df4df40ec50c46000231c914968278b1eb05098cf8f1b3a518a95030e71d1c7" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" dependencies = [ "anstream", "anstyle", "clap_lex", - "strsim", + "strsim 0.11.0", ] [[package]] name = "clap_derive" -version = "4.4.7" +version = "4.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" +checksum = "307bc0538d5f0f83b8248db3087aa92fe504e4691294d0c96c0eabc33f47ba47" dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] name = "clap_lex" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" [[package]] name = "clokwerk" @@ -984,18 +1024,17 @@ dependencies = [ [[package]] name = "config" -version = "0.13.4" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23738e11972c7643e4ec947840fc463b6a571afcd3e735bdfce7d03c7a784aca" +checksum = "7328b20597b53c2454f0b1919720c25c7339051c02b72b7e05409e00b14132be" dependencies = [ - "async-trait", "lazy_static", "nom", "pathdiff", "ron", "serde", "serde_json", - "toml 0.5.11", + "toml 0.8.11", "yaml-rust", ] @@ -1072,6 +1111,12 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + [[package]] name = "const_format" version = "0.2.32" @@ -1142,18 +1187,18 @@ dependencies = [ [[package]] name = "crc32fast" -version = "1.3.2" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" dependencies = [ "cfg-if", ] [[package]] name = "crossbeam-channel" -version = "0.5.11" +version = "0.5.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "176dc175b78f56c0f321911d9c8eb2b77a78a4860b9c19db83835fea1a46649b" +checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95" dependencies = [ "crossbeam-utils", ] @@ -1205,12 +1250,12 @@ dependencies = [ [[package]] name = "darling" -version = "0.20.3" +version = "0.20.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" +checksum = "54e36fcd13ed84ffdfda6f5be89b31287cbb80c439841fe69e04841435464391" dependencies = [ - "darling_core 0.20.3", - "darling_macro 0.20.3", + "darling_core 0.20.8", + "darling_macro 0.20.8", ] [[package]] @@ -1223,7 +1268,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim", + "strsim 0.10.0", "syn 1.0.109", ] @@ -1237,22 +1282,22 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim", + "strsim 0.10.0", "syn 1.0.109", ] [[package]] name = "darling_core" -version = "0.20.3" +version = "0.20.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621" +checksum = "9c2cf1c23a687a1feeb728783b993c4e1ad83d99f351801977dd809b48d0a70f" dependencies = [ "fnv", "ident_case", "proc-macro2", "quote", - "strsim", - "syn 2.0.48", + "strsim 0.10.0", + "syn 2.0.52", ] [[package]] @@ -1279,13 +1324,13 @@ dependencies = [ [[package]] name = "darling_macro" -version = "0.20.3" +version = "0.20.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" +checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" dependencies = [ - "darling_core 0.20.3", + "darling_core 0.20.8", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -1335,6 +1380,16 @@ dependencies = [ "tokio", ] +[[package]] +name = "der" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" +dependencies = [ + "const-oid", + "zeroize", +] + [[package]] name = "deranged" version = "0.3.11" @@ -1433,6 +1488,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acada1517534c92d3f382217b485db8a8638f111b0e3f2a2a8e26165050f77be" dependencies = [ "async-trait", + "bb8", "deadpool 0.9.5", "diesel", "futures-util", @@ -1450,7 +1506,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -1461,7 +1517,7 @@ checksum = "c7267437d5b12df60ae29bd97f8d120f1c3a6272d6f213551afa56bbb2ecfbb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -1473,7 +1529,7 @@ dependencies = [ "diesel_table_macro_syntax", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -1503,7 +1559,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc5557efc453706fed5e4fa85006fe9817c224c3f480a34c7e5959fd700921c5" dependencies = [ - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -1570,9 +1626,9 @@ checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" [[package]] name = "either" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" [[package]] name = "elementtree" @@ -1695,7 +1751,7 @@ checksum = "f282cfdfe92516eb26c2af8589c274c7c17681f5ecc03c18255fe741c6aa64eb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -1755,9 +1811,9 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" [[package]] name = "eyre" -version = "0.6.11" +version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6267a1fa6f59179ea4afc8e50fd8612a3cc60bc858f786ff877a4a8cb042799" +checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" dependencies = [ "indenter", "once_cell", @@ -1775,7 +1831,7 @@ version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a88c69768c0a15262df21899142bc6df9b9b823546d4b4b9a7bc2d6c448ec6fd" dependencies = [ - "hashbrown 0.13.1", + "hashbrown 0.13.2", ] [[package]] @@ -1937,7 +1993,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -2041,9 +2097,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.13.1" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ff8ae62cd3a9102e5637afc8452c55acf3844001bd5374e0b0bd7b6616c038" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" dependencies = [ "ahash", ] @@ -2079,9 +2135,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.3.4" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d3d0e0f38255e7fa3cf31335b3a56f05febd18025f4db5ef7a0cfb4f8da651f" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "hex" @@ -2167,9 +2223,9 @@ dependencies = [ [[package]] name = "http" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" dependencies = [ "bytes", "fnv", @@ -2311,14 +2367,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8215279f83f9b829403812f845aa2d0dd5966332aa2fd0334a375256f3dd0322" dependencies = [ "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] name = "iana-time-zone" -version = "0.1.59" +version = "0.1.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6a67363e2aa4443928ce15e57ebae94fd8949958fd1223c4cfc0cd473ad7539" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -2365,9 +2421,9 @@ dependencies = [ [[package]] name = "image" -version = "0.24.8" +version = "0.24.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "034bbe799d1909622a74d1193aa50147769440040ff36cb2baa947609b0a4e23" +checksum = "5690139d2f55868e080017335e4b94cb7414274c74f1669c84fb5feba2c9f69d" dependencies = [ "bytemuck", "byteorder", @@ -2500,18 +2556,18 @@ checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" [[package]] name = "jobserver" -version = "0.1.27" +version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d" +checksum = "ab46a6e9526ddef3ae7f787c06f0f2600639ba80ea3eade3d8e670a2230f51d6" dependencies = [ "libc", ] [[package]] name = "js-sys" -version = "0.3.67" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" dependencies = [ "wasm-bindgen", ] @@ -2523,7 +2579,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6971da4d9c3aa03c3d8f3ff0f4155b534aad021292003895a469716b2a230378" dependencies = [ "base64 0.21.7", - "pem", + "pem 1.1.1", "ring 0.16.20", "serde", "serde_json", @@ -2714,7 +2770,7 @@ dependencies = [ "strum_macros", "tokio", "tokio-postgres", - "tokio-postgres-rustls", + "tokio-postgres-rustls 0.10.0", "tracing", "ts-rs", "typed-builder", @@ -2908,9 +2964,9 @@ dependencies = [ [[package]] name = "lettre" -version = "0.11.3" +version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5aaf628956b6b0852e12ac3505d20d7a12ecc1e32d5ea921f002af4a74036a5" +checksum = "357ff5edb6d8326473a64c82cf41ddf78ab116f89668c50c4fac1b321e5e80f4" dependencies = [ "async-trait", "base64 0.21.7", @@ -2926,6 +2982,7 @@ dependencies = [ "mime", "native-tls", "nom", + "percent-encoding", "quoted_printable", "socket2", "tokio", @@ -2935,9 +2992,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.152" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "line-wrap" @@ -3017,9 +3074,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.20" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "mac" @@ -3136,13 +3193,13 @@ dependencies = [ [[package]] name = "metrics-exporter-prometheus" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83a4c4718a371ddfb7806378f23617876eea8b82e5ff1324516bcd283249d9ea" +checksum = "9bf4e7146e30ad172c42c39b3246864bd2d3c6396780711a1baf749cfe423e21" dependencies = [ "base64 0.21.7", "hyper", - "indexmap 1.9.3", + "indexmap 2.2.5", "ipnet", "metrics", "metrics-util", @@ -3153,13 +3210,13 @@ dependencies = [ [[package]] name = "metrics-util" -version = "0.16.0" +version = "0.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2670b8badcc285d486261e2e9f1615b506baff91427b61bd336a472b65bbf5ed" +checksum = "ece71ab046dcf45604e573329966ec1db5ff4b81cfa170a924ff4c959ab5451a" dependencies = [ "crossbeam-epoch", "crossbeam-utils", - "hashbrown 0.13.1", + "hashbrown 0.14.3", "metrics", "num_cpus", "quanta", @@ -3211,9 +3268,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" dependencies = [ "adler", "simd-adler32", @@ -3221,9 +3278,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.10" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" dependencies = [ "libc", "log", @@ -3332,20 +3389,25 @@ dependencies = [ ] [[package]] -name = "num-integer" -version = "0.1.45" +name = "num-conv" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" dependencies = [ - "autocfg", "num-traits", ] [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" dependencies = [ "autocfg", ] @@ -3398,7 +3460,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -3448,13 +3510,12 @@ dependencies = [ [[package]] name = "opentelemetry" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e32339a5dc40459130b3bd269e9892439f55b33e772d2a9d402a789baaf4e8a" +checksum = "900d57987be3f2aeb70d385fff9b27fb74c5723cc9a52d904d4f9c807a0667bf" dependencies = [ "futures-core", "futures-sink", - "indexmap 2.2.5", "js-sys", "once_cell", "pin-project-lite", @@ -3482,21 +3543,21 @@ dependencies = [ [[package]] name = "opentelemetry-otlp" -version = "0.14.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f24cda83b20ed2433c68241f918d0f6fdec8b1d43b7a9590ab4420c5095ca930" +checksum = "1a016b8d9495c639af2145ac22387dcb88e44118e45320d9238fbf4e7889abcb" dependencies = [ "async-trait", "futures-core", "http", - "opentelemetry 0.21.0", - "opentelemetry-proto 0.4.0", + "opentelemetry 0.22.0", + "opentelemetry-proto 0.5.0", "opentelemetry-semantic-conventions", - "opentelemetry_sdk 0.21.2", - "prost 0.11.9", + "opentelemetry_sdk 0.22.1", + "prost 0.12.3", "thiserror", "tokio", - "tonic 0.9.2", + "tonic 0.11.0", ] [[package]] @@ -3514,24 +3575,21 @@ dependencies = [ [[package]] name = "opentelemetry-proto" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2e155ce5cc812ea3d1dffbd1539aed653de4bf4882d60e6e04dcf0901d674e1" +checksum = "3a8fddc9b68f5b80dae9d6f510b88e02396f006ad48cac349411fbecc80caae4" dependencies = [ - "opentelemetry 0.21.0", - "opentelemetry_sdk 0.21.2", - "prost 0.11.9", - "tonic 0.9.2", + "opentelemetry 0.22.0", + "opentelemetry_sdk 0.22.1", + "prost 0.12.3", + "tonic 0.11.0", ] [[package]] name = "opentelemetry-semantic-conventions" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5774f1ef1f982ef2a447f6ee04ec383981a3ab99c8e77a1a7b30182e65bbc84" -dependencies = [ - "opentelemetry 0.21.0", -] +checksum = "f9ab5bd6c42fb9349dcf28af2ba9a0667f697f9bdcca045d39f2cec5543e2910" [[package]] name = "opentelemetry_api" @@ -3573,9 +3631,9 @@ dependencies = [ [[package]] name = "opentelemetry_sdk" -version = "0.21.2" +version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f16aec8a98a457a52664d69e0091bac3a0abd18ead9b641cb00202ba4e0efe4" +checksum = "9e90c7113be649e31e9a0f8b5ee24ed7a16923b322c3c5ab6367469c049d6b7e" dependencies = [ "async-trait", "crossbeam-channel", @@ -3584,7 +3642,7 @@ dependencies = [ "futures-util", "glob", "once_cell", - "opentelemetry 0.21.0", + "opentelemetry 0.22.0", "ordered-float", "percent-encoding", "rand", @@ -3683,6 +3741,16 @@ dependencies = [ "base64 0.13.1", ] +[[package]] +name = "pem" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b8fcc794035347fb64beda2d3b462595dd2753e3f268d89c5aae77e8cf2c310" +dependencies = [ + "base64 0.21.7", + "serde", +] + [[package]] name = "percent-encoding" version = "2.3.1" @@ -3747,21 +3815,22 @@ dependencies = [ [[package]] name = "pict-rs" -version = "0.5.1" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca72ffda2e229b6be6aeda550b7069aa8dc72589711da63c59914df89bf91b02" +checksum = "e709cefc614ddbe5685b30298790a2fe8637523190c182c0215c18053ce7cfdf" dependencies = [ "actix-form-data", "actix-web", "async-trait", "barrel", "base64 0.21.7", + "bb8", + "blurhash-update", "clap", "color-eyre", "config", "console-subscriber 0.2.0", "dashmap", - "deadpool 0.9.5", "diesel", "diesel-async", "diesel-derive-enum", @@ -3772,14 +3841,17 @@ dependencies = [ "metrics", "metrics-exporter-prometheus", "mime", - "opentelemetry 0.21.0", - "opentelemetry-otlp 0.14.0", - "opentelemetry_sdk 0.21.2", + "opentelemetry 0.22.0", + "opentelemetry-otlp 0.15.0", + "opentelemetry_sdk 0.22.1", "pin-project-lite", "refinery", "reqwest", "reqwest-middleware", "reqwest-tracing", + "rustls 0.22.2", + "rustls-channel-resolver", + "rustls-pemfile 2.1.1", "rusty-s3", "serde", "serde-tuple-vec-map", @@ -3787,43 +3859,44 @@ dependencies = [ "serde_urlencoded", "sha2", "sled", - "storage-path-generator", "streem", "subtle", "thiserror", "time", "tokio", "tokio-postgres", + "tokio-postgres-rustls 0.11.1", "tokio-util", - "toml 0.8.8", + "toml 0.8.11", "tracing", "tracing-actix-web", "tracing-error", "tracing-log 0.2.0", - "tracing-opentelemetry 0.22.0", + "tracing-opentelemetry 0.23.0", "tracing-subscriber", "url", "uuid", + "webpki-roots 0.26.1", ] [[package]] name = "pin-project" -version = "1.1.3" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fda4ed1c6c173e3fc7a83629421152e01d7b1f9b7f65fb301e490e8cfc656422" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.3" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -3840,9 +3913,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[package]] name = "plist" @@ -3860,9 +3933,9 @@ dependencies = [ [[package]] name = "png" -version = "0.17.11" +version = "0.17.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f6c3c3e617595665b8ea2ff95a86066be38fb121ff920a9c0eb282abcd1da5a" +checksum = "06e4b0d3d1312775e782c86c91a111aa1f910cbb65e1337f9975b5f9a554b5e1" dependencies = [ "bitflags 1.3.2", "crc32fast", @@ -3963,9 +4036,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" dependencies = [ "unicode-ident", ] @@ -4043,7 +4116,7 @@ dependencies = [ "itertools 0.11.0", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -4081,11 +4154,11 @@ dependencies = [ [[package]] name = "pulldown-cmark" -version = "0.9.3" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a1a2f1f0a7ecff9c31abbe177637be0e97a0aef46cf8738ece09327985d998" +checksum = "57206b407293d2bcd3af849ce869d52068623f19e1b5ff8e8778e3309439682b" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.2", "memchr", "unicase", ] @@ -4187,7 +4260,7 @@ checksum = "a25d631e41bfb5fdcde1d4e2215f62f7f0afa3ff11e26563765bd6ea1d229aeb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -4235,7 +4308,7 @@ dependencies = [ "time", "tokio", "tokio-postgres", - "toml 0.8.8", + "toml 0.8.11", "url", "walkdir", ] @@ -4250,7 +4323,7 @@ dependencies = [ "quote", "refinery-core", "regex", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -4261,7 +4334,7 @@ checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.4", + "regex-automata 0.4.6", "regex-syntax 0.8.2", ] @@ -4276,9 +4349,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.4" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b7fa1134405e2ec9353fd416b17f8dacd46c473d7d3fd1cf202706a14eb792a" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" dependencies = [ "aho-corasick", "memchr", @@ -4291,12 +4364,6 @@ version = "0.6.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" -[[package]] -name = "regex-syntax" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" - [[package]] name = "regex-syntax" version = "0.8.2" @@ -4305,9 +4372,9 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "reqwest" -version = "0.11.24" +version = "0.11.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6920094eb85afde5e4a138be3f2de8bbdf28000f0029e72c45025a56b042251" +checksum = "78bf93c4af7a8bb7d879d51cebe797356ff10ae8516ace542b5182d9dcac10b2" dependencies = [ "async-compression", "base64 0.21.7", @@ -4331,7 +4398,7 @@ dependencies = [ "percent-encoding", "pin-project-lite", "rustls 0.21.10", - "rustls-pemfile", + "rustls-pemfile 1.0.4", "serde", "serde_json", "serde_urlencoded", @@ -4347,7 +4414,7 @@ dependencies = [ "wasm-bindgen-futures", "wasm-streams", "web-sys", - "webpki-roots 0.25.3", + "webpki-roots 0.25.4", "winreg", ] @@ -4422,27 +4489,29 @@ dependencies = [ [[package]] name = "ring" -version = "0.17.7" +version = "0.17.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "688c63d65483050968b2a8937f7995f443e27041a0f7700aa59b0822aedebb74" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" dependencies = [ "cc", + "cfg-if", "getrandom", "libc", "spin 0.9.8", "untrusted 0.9.0", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "ron" -version = "0.7.1" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88073939a61e5b7680558e6be56b419e208420c2adb92be54921fa6b72283f1a" +checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94" dependencies = [ - "base64 0.13.1", - "bitflags 1.3.2", + "base64 0.21.7", + "bitflags 2.4.2", "serde", + "serde_derive", ] [[package]] @@ -4508,9 +4577,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.30" +version = "0.38.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322394588aaf33c24007e8bb3238ee3e4c5c09c084ab32bc73890b99ff326bca" +checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" dependencies = [ "bitflags 2.4.2", "errno", @@ -4538,11 +4607,35 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" dependencies = [ "log", - "ring 0.17.7", - "rustls-webpki", + "ring 0.17.8", + "rustls-webpki 0.101.7", "sct", ] +[[package]] +name = "rustls" +version = "0.22.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e87c9956bd9807afa1f77e0f7594af32566e830e088a5576d27c5b6f30f49d41" +dependencies = [ + "log", + "ring 0.17.8", + "rustls-pki-types", + "rustls-webpki 0.102.2", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-channel-resolver" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffbd1941204442f051576a9a7ea8e8db074ad7fd43db1eb3378c3633f9f9e166" +dependencies = [ + "nanorand", + "rustls 0.22.2", +] + [[package]] name = "rustls-pemfile" version = "1.0.4" @@ -4552,13 +4645,40 @@ dependencies = [ "base64 0.21.7", ] +[[package]] +name = "rustls-pemfile" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f48172685e6ff52a556baa527774f61fcaa884f59daf3375c62a3f1cd2549dab" +dependencies = [ + "base64 0.21.7", + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ede67b28608b4c60685c7d54122d4400d90f62b40caee7700e700380a390fa8" + [[package]] name = "rustls-webpki" version = "0.101.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" dependencies = [ - "ring 0.17.7", + "ring 0.17.8", + "untrusted 0.9.0", +] + +[[package]] +name = "rustls-webpki" +version = "0.102.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "faaa0a62740bedb9b2ef5afa303da42764c012f743917351dc9a237ea1663610" +dependencies = [ + "ring 0.17.8", + "rustls-pki-types", "untrusted 0.9.0", ] @@ -4589,9 +4709,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.16" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" [[package]] name = "safemem" @@ -4639,7 +4759,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ - "ring 0.17.7", + "ring 0.17.8", "untrusted 0.9.0", ] @@ -4679,9 +4799,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.21" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" +checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" dependencies = [ "serde", ] @@ -4712,7 +4832,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -4759,9 +4879,9 @@ dependencies = [ [[package]] name = "serde_with" -version = "3.5.1" +version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5c9fdb6b00a489875b22efd4b78fe2b363b72265cc5f6eb2e2b9ee270e6140c" +checksum = "ee80b0e361bbf88fd2f6e242ccd19cfda072cb0faa6ae694ecee08199938569a" dependencies = [ "base64 0.21.7", "chrono", @@ -4769,6 +4889,7 @@ dependencies = [ "indexmap 1.9.3", "indexmap 2.2.5", "serde", + "serde_derive", "serde_json", "serde_with_macros", "time", @@ -4776,14 +4897,14 @@ dependencies = [ [[package]] name = "serde_with_macros" -version = "3.5.1" +version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbff351eb4b33600a2e138dfa0b10b65a238ea8ff8fb2387c422c5022a3e8298" +checksum = "6561dc161a9224638a31d876ccdfefbc1df91d3f3a8342eddb35f055d48c7655" dependencies = [ - "darling 0.20.3", + "darling 0.20.8", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -4808,7 +4929,7 @@ checksum = "91d129178576168c589c9ec973feedf7d3126c01ac2bf08795109aa35b69fb8f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -4851,6 +4972,15 @@ dependencies = [ "libc", ] +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "rand_core", +] + [[package]] name = "simd-adler32" version = "0.3.7" @@ -4883,9 +5013,9 @@ checksum = "54ac45299ccbd390721be55b412d41931911f654fa99e2cb8bfb57184b2061fe" [[package]] name = "sitemap-rs" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95b58125f0ab4317b5ba3cdc1f60696e47958760e356874c759334fa56ae1596" +checksum = "88cc73a9aac975541c9054e74ceae8d8ee85edc89a322404c275c1d100fffa51" dependencies = [ "chrono", "xml-builder", @@ -4908,9 +5038,9 @@ dependencies = [ [[package]] name = "sketches-ddsketch" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a406c1882ed7f29cd5e248c9848a80e7cb6ae0fea82346d2746f2f941c07e1" +checksum = "85636c14b73d81f541e525f585c0a2109e6744e1565b5c1668e31c70c10ed65c" [[package]] name = "slab" @@ -4951,17 +5081,17 @@ checksum = "0eb01866308440fc64d6c44d9e86c5cc17adfe33c4d6eed55da9145044d0ffc1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] name = "socket2" -version = "0.5.5" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" +checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" dependencies = [ "libc", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -4979,6 +5109,16 @@ dependencies = [ "lock_api", ] +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + [[package]] name = "stacker" version = "0.1.15" @@ -4992,12 +5132,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "storage-path-generator" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f11d35dae9818c4313649da4a97c8329e29357a7fe584526c1d78f5b63ef836" - [[package]] name = "streem" version = "0.2.0" @@ -5057,6 +5191,12 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strsim" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" + [[package]] name = "strum" version = "0.25.0" @@ -5073,7 +5213,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -5095,9 +5235,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.48" +version = "2.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" dependencies = [ "proc-macro2", "quote", @@ -5112,9 +5252,9 @@ checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" [[package]] name = "syntect" -version = "5.1.0" +version = "5.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e02b4b303bf8d08bfeb0445cba5068a3d306b6baece1d5582171a9bf49188f91" +checksum = "874dcfa363995604333cf947ae9f751ca3af4522c60886774c4963943b4746b1" dependencies = [ "bincode", "bitflags 1.3.2", @@ -5123,8 +5263,9 @@ dependencies = [ "fnv", "once_cell", "plist", - "regex-syntax 0.7.5", + "regex-syntax 0.8.2", "serde", + "serde_derive", "serde_json", "thiserror", "walkdir", @@ -5169,14 +5310,13 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.9.0" +version = "3.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01ce4141aa927a6d1bd34a041795abd0db1cccba5d5f24b009f694bdf3a1f3fa" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" dependencies = [ "cfg-if", "fastrand", - "redox_syscall 0.4.1", - "rustix 0.38.30", + "rustix 0.38.31", "windows-sys 0.52.0", ] @@ -5202,29 +5342,29 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.57" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.57" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] name = "thread_local" -version = "1.1.7" +version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" dependencies = [ "cfg-if", "once_cell", @@ -5232,12 +5372,13 @@ dependencies = [ [[package]] name = "time" -version = "0.3.31" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e" +checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" dependencies = [ "deranged", "itoa", + "num-conv", "powerfmt", "serde", "time-core", @@ -5252,10 +5393,11 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26197e33420244aeb70c3e8c78376ca46571bc4e701e4791c2cd9f57dcb3a43f" +checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774" dependencies = [ + "num-conv", "time-core", ] @@ -5318,7 +5460,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -5371,6 +5513,21 @@ dependencies = [ "tokio-rustls 0.24.1", ] +[[package]] +name = "tokio-postgres-rustls" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ea13f22eda7127c827983bdaf0d7fff9df21c8817bab02815ac277a21143677" +dependencies = [ + "futures", + "ring 0.17.8", + "rustls 0.22.2", + "tokio", + "tokio-postgres", + "tokio-rustls 0.25.0", + "x509-certificate", +] + [[package]] name = "tokio-rustls" version = "0.23.4" @@ -5392,6 +5549,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-rustls" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f" +dependencies = [ + "rustls 0.22.2", + "rustls-pki-types", + "tokio", +] + [[package]] name = "tokio-stream" version = "0.1.14" @@ -5417,15 +5585,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "toml" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" -dependencies = [ - "serde", -] - [[package]] name = "toml" version = "0.7.8" @@ -5440,14 +5599,14 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.8" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1a195ec8c9da26928f773888e0742ca3ca1040c6cd859c919c9f59c1954ab35" +checksum = "af06656561d28735e9c1cd63dfd57132c8155426aa6af24f36a00a351f88c48e" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.21.0", + "toml_edit 0.22.7", ] [[package]] @@ -5469,20 +5628,20 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow", + "winnow 0.5.40", ] [[package]] name = "toml_edit" -version = "0.21.0" +version = "0.22.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34d383cd00a163b4a5b85053df514d45bc330f6de7737edfe0a93311d1eaa03" +checksum = "18769cd1cec395d70860ceb4d932812a0b4d06b1a4bb336745a4d21b9496e992" dependencies = [ "indexmap 2.2.5", "serde", "serde_spanned", "toml_datetime", - "winnow", + "winnow 0.6.5", ] [[package]] @@ -5572,6 +5731,33 @@ dependencies = [ "tracing", ] +[[package]] +name = "tonic" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76c4eb7a4e9ef9d4763600161f12f5070b92a578e1b634db88a6887844c91a13" +dependencies = [ + "async-stream", + "async-trait", + "axum", + "base64 0.21.7", + "bytes", + "h2", + "http", + "http-body", + "hyper", + "hyper-timeout", + "percent-encoding", + "pin-project", + "prost 0.12.3", + "tokio", + "tokio-stream", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "totp-rs" version = "5.5.1" @@ -5634,16 +5820,16 @@ dependencies = [ [[package]] name = "tracing-actix-web" -version = "0.7.9" +version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fe0d5feac3f4ca21ba33496bcb1ccab58cca6412b1405ae80f0581541e0ca78" +checksum = "fa069bd1503dd526ee793bb3fce408895136c95fc86d2edb2acf1c646d7f0684" dependencies = [ "actix-web", "mutually_exclusive_features", - "opentelemetry 0.21.0", + "opentelemetry 0.22.0", "pin-project", "tracing", - "tracing-opentelemetry 0.22.0", + "tracing-opentelemetry 0.23.0", "uuid", ] @@ -5655,7 +5841,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -5739,14 +5925,14 @@ dependencies = [ [[package]] name = "tracing-opentelemetry" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c67ac25c5407e7b961fafc6f7e9aa5958fd297aada2d20fa2ae1737357e55596" +checksum = "a9be14ba1bbe4ab79e9229f7f89fab8d120b865859f10527f31c033e599d2284" dependencies = [ "js-sys", "once_cell", - "opentelemetry 0.21.0", - "opentelemetry_sdk 0.21.2", + "opentelemetry 0.22.0", + "opentelemetry_sdk 0.22.1", "smallvec", "tracing", "tracing-core", @@ -5818,7 +6004,7 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", "termcolor", ] @@ -5839,7 +6025,7 @@ checksum = "563b3b88238ec95680aef36bdece66896eaa7ce3c0f1b4f39d38fb2435261352" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -5877,9 +6063,9 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-normalization" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" dependencies = [ "tinyvec", ] @@ -5975,9 +6161,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "walkdir" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" dependencies = [ "same-file", "winapi-util", @@ -5999,10 +6185,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] -name = "wasm-bindgen" -version = "0.2.90" +name = "wasite" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406" +checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" + +[[package]] +name = "wasm-bindgen" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -6010,24 +6202,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.90" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.40" +version = "0.4.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bde2032aeb86bdfaecc8b261eef3cba735cc426c1f3a3416d1e0791be95fc461" +checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" dependencies = [ "cfg-if", "js-sys", @@ -6037,9 +6229,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.90" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -6047,22 +6239,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.90" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.90" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "wasm-streams" @@ -6088,9 +6280,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.67" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58cd2333b6e0be7a39605f0e255892fd7418a682d8da8fe042fe25128794d2ed" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" dependencies = [ "js-sys", "wasm-bindgen", @@ -6098,9 +6290,9 @@ dependencies = [ [[package]] name = "web-time" -version = "0.2.4" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa30049b1c872b72c89866d458eae9f20380ab280ffd1b1e18df2d3e2d98cfe0" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" dependencies = [ "js-sys", "wasm-bindgen", @@ -6139,7 +6331,7 @@ version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed63aea5ce73d0ff405984102c42de94fc55a6b75765d621c65262469b3c9b53" dependencies = [ - "ring 0.17.7", + "ring 0.17.8", "untrusted 0.9.0", ] @@ -6154,17 +6346,27 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.25.3" +version = "0.25.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1778a42e8b3b90bff8d0f5032bf22250792889a5cdc752aa0020c84abe3aaf10" +checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" + +[[package]] +name = "webpki-roots" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3de34ae270483955a94f4b21bdaaeb83d508bb84a01435f393818edb0012009" +dependencies = [ + "rustls-pki-types", +] [[package]] name = "whoami" -version = "1.4.1" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22fc3756b8a9133049b26c7f61ab35416c130e8c09b660f5b3958b446f52cc50" +checksum = "a44ab49fad634e88f55bf8f9bb3abd2f27d7204172a112c7c9987e01c1c94ea9" dependencies = [ - "wasm-bindgen", + "redox_syscall 0.4.1", + "wasite", "web-sys", ] @@ -6205,7 +6407,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.0", + "windows-targets 0.52.4", ] [[package]] @@ -6232,7 +6434,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.0", + "windows-targets 0.52.4", ] [[package]] @@ -6267,17 +6469,17 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" dependencies = [ - "windows_aarch64_gnullvm 0.52.0", - "windows_aarch64_msvc 0.52.0", - "windows_i686_gnu 0.52.0", - "windows_i686_msvc 0.52.0", - "windows_x86_64_gnu 0.52.0", - "windows_x86_64_gnullvm 0.52.0", - "windows_x86_64_msvc 0.52.0", + "windows_aarch64_gnullvm 0.52.4", + "windows_aarch64_msvc 0.52.4", + "windows_i686_gnu 0.52.4", + "windows_i686_msvc 0.52.4", + "windows_x86_64_gnu 0.52.4", + "windows_x86_64_gnullvm 0.52.4", + "windows_x86_64_msvc 0.52.4", ] [[package]] @@ -6294,9 +6496,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" [[package]] name = "windows_aarch64_msvc" @@ -6312,9 +6514,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" [[package]] name = "windows_i686_gnu" @@ -6330,9 +6532,9 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" [[package]] name = "windows_i686_msvc" @@ -6348,9 +6550,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" [[package]] name = "windows_x86_64_gnu" @@ -6366,9 +6568,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" [[package]] name = "windows_x86_64_gnullvm" @@ -6384,9 +6586,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" [[package]] name = "windows_x86_64_msvc" @@ -6402,15 +6604,24 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" [[package]] name = "winnow" -version = "0.5.34" +version = "0.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7cf47b659b318dccbd69cc4797a39ae128f533dce7902a1096044d1967b9c16" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +dependencies = [ + "memchr", +] + +[[package]] +name = "winnow" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8" dependencies = [ "memchr", ] @@ -6425,6 +6636,25 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "x509-certificate" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66534846dec7a11d7c50a74b7cdb208b9a581cad890b7866430d438455847c85" +dependencies = [ + "bcder", + "bytes", + "chrono", + "der", + "hex", + "pem 3.0.3", + "ring 0.17.8", + "signature", + "spki", + "thiserror", + "zeroize", +] + [[package]] name = "xml-builder" version = "0.5.2" @@ -6474,7 +6704,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -6482,6 +6712,20 @@ name = "zeroize" version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", +] [[package]] name = "zstd" diff --git a/Cargo.toml b/Cargo.toml index 5e0cdb16e..66c3f9d47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -102,9 +102,9 @@ activitypub_federation = { version = "0.5.2", default-features = false, features diesel = "2.1.4" diesel_migrations = "2.1.0" diesel-async = "0.4.1" -serde = { version = "1.0.195", features = ["derive"] } -serde_with = "3.5.1" -actix-web = { version = "4.4.1", default-features = false, features = [ +serde = { version = "1.0.197", features = ["derive"] } +serde_with = "3.7.0" +actix-web = { version = "4.5.1", default-features = false, features = [ "macros", "rustls", "compress-brotli", @@ -113,39 +113,39 @@ actix-web = { version = "4.4.1", default-features = false, features = [ "cookies", ] } tracing = "0.1.40" -tracing-actix-web = { version = "0.7.9", default-features = false } +tracing-actix-web = { version = "0.7.10", default-features = false } tracing-error = "0.2.0" tracing-log = "0.2.0" tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } url = { version = "2.5.0", features = ["serde"] } -reqwest = { version = "0.11.23", features = ["json", "blocking", "gzip"] } +reqwest = { version = "0.11.26", features = ["json", "blocking", "gzip"] } reqwest-middleware = "0.2.4" reqwest-tracing = "0.4.7" clokwerk = "0.4.0" doku = { version = "0.21.1", features = ["url-2"] } bcrypt = "0.15.0" -chrono = { version = "0.4.32", features = ["serde"], default-features = false } -serde_json = { version = "1.0.111", features = ["preserve_order"] } +chrono = { version = "0.4.35", features = ["serde"], default-features = false } +serde_json = { version = "1.0.114", features = ["preserve_order"] } base64 = "0.21.7" uuid = { version = "1.7.0", features = ["serde", "v4"] } async-trait = "0.1.77" captcha = "0.0.9" -anyhow = { version = "1.0.79", features = [ +anyhow = { version = "1.0.81", features = [ "backtrace", ] } # backtrace is on by default on nightly, but not stable rust diesel_ltree = "0.3.1" typed-builder = "0.18.1" serial_test = "2.0.0" -tokio = { version = "1.35.1", features = ["full"] } +tokio = { version = "1.36.0", features = ["full"] } regex = "1.10.3" once_cell = "1.19.0" diesel-derive-newtype = "2.1.0" diesel-derive-enum = { version = "2.1.0", features = ["postgres"] } strum = "0.25.0" strum_macros = "0.25.3" -itertools = "0.12.0" +itertools = "0.12.1" futures = "0.3.30" -http = "0.2.11" +http = "0.2.12" rosetta-i18n = "0.1.3" opentelemetry = { version = "0.19.0", features = ["rt-tokio"] } tracing-opentelemetry = { version = "0.19.0" } @@ -160,9 +160,9 @@ tokio-postgres = "0.7.10" tokio-postgres-rustls = "0.10.0" urlencoding = "2.1.3" enum-map = "2.7" -moka = { version = "0.12.4", features = ["future"] } +moka = { version = "0.12.5", features = ["future"] } i-love-jesus = { version = "0.1.0" } -clap = { version = "4.4.18", features = ["derive"] } +clap = { version = "4.5.2", features = ["derive"] } pretty_assertions = "1.4.0" [dependencies] @@ -193,7 +193,7 @@ tracing-opentelemetry = { workspace = true, optional = true } opentelemetry = { workspace = true, optional = true } console-subscriber = { version = "0.1.10", optional = true } opentelemetry-otlp = { version = "0.12.0", optional = true } -pict-rs = { version = "0.5.1", optional = true } +pict-rs = { version = "0.5.9", optional = true } tokio.workspace = true actix-cors = "0.6.5" futures-util = { workspace = true } diff --git a/api_tests/package.json b/api_tests/package.json index f6c436312..07f9fa776 100644 --- a/api_tests/package.json +++ b/api_tests/package.json @@ -20,16 +20,16 @@ }, "devDependencies": { "@types/jest": "^29.5.12", - "@types/node": "^20.11.22", - "@typescript-eslint/eslint-plugin": "^7.1.0", - "@typescript-eslint/parser": "^7.1.0", + "@types/node": "^20.11.27", + "@typescript-eslint/eslint-plugin": "^7.2.0", + "@typescript-eslint/parser": "^7.2.0", "download-file-sync": "^1.0.4", "eslint": "^8.57.0", - "eslint-plugin-prettier": "^5.0.1", + "eslint-plugin-prettier": "^5.1.3", "jest": "^29.5.0", "lemmy-js-client": "0.19.4-alpha.8", "prettier": "^3.2.5", "ts-jest": "^29.1.0", - "typescript": "^5.3.3" + "typescript": "^5.4.2" } } diff --git a/api_tests/pnpm-lock.yaml b/api_tests/pnpm-lock.yaml index 321fffc8b..39bba75a1 100644 --- a/api_tests/pnpm-lock.yaml +++ b/api_tests/pnpm-lock.yaml @@ -9,14 +9,14 @@ devDependencies: specifier: ^29.5.12 version: 29.5.12 '@types/node': - specifier: ^20.11.22 - version: 20.11.22 + specifier: ^20.11.27 + version: 20.11.27 '@typescript-eslint/eslint-plugin': - specifier: ^7.1.0 - version: 7.1.0(@typescript-eslint/parser@7.1.0)(eslint@8.57.0)(typescript@5.3.3) + specifier: ^7.2.0 + version: 7.2.0(@typescript-eslint/parser@7.2.0)(eslint@8.57.0)(typescript@5.4.2) '@typescript-eslint/parser': - specifier: ^7.1.0 - version: 7.1.0(eslint@8.57.0)(typescript@5.3.3) + specifier: ^7.2.0 + version: 7.2.0(eslint@8.57.0)(typescript@5.4.2) download-file-sync: specifier: ^1.0.4 version: 1.0.4 @@ -24,11 +24,11 @@ devDependencies: specifier: ^8.57.0 version: 8.57.0 eslint-plugin-prettier: - specifier: ^5.0.1 + specifier: ^5.1.3 version: 5.1.3(eslint@8.57.0)(prettier@3.2.5) jest: specifier: ^29.5.0 - version: 29.7.0(@types/node@20.11.22) + version: 29.7.0(@types/node@20.11.27) lemmy-js-client: specifier: 0.19.4-alpha.8 version: 0.19.4-alpha.8 @@ -37,10 +37,10 @@ devDependencies: version: 3.2.5 ts-jest: specifier: ^29.1.0 - version: 29.1.2(@babel/core@7.23.9)(jest@29.7.0)(typescript@5.3.3) + version: 29.1.2(@babel/core@7.23.9)(jest@29.7.0)(typescript@5.4.2) typescript: - specifier: ^5.3.3 - version: 5.3.3 + specifier: ^5.4.2 + version: 5.4.2 packages: @@ -464,7 +464,7 @@ packages: engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dependencies: '@jest/types': 29.6.3 - '@types/node': 20.11.22 + '@types/node': 20.11.27 chalk: 4.1.2 jest-message-util: 29.7.0 jest-util: 29.7.0 @@ -485,14 +485,14 @@ packages: '@jest/test-result': 29.7.0 '@jest/transform': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 20.11.22 + '@types/node': 20.11.27 ansi-escapes: 4.3.2 chalk: 4.1.2 ci-info: 3.9.0 exit: 0.1.2 graceful-fs: 4.2.11 jest-changed-files: 29.7.0 - jest-config: 29.7.0(@types/node@20.11.22) + jest-config: 29.7.0(@types/node@20.11.27) jest-haste-map: 29.7.0 jest-message-util: 29.7.0 jest-regex-util: 29.6.3 @@ -520,7 +520,7 @@ packages: dependencies: '@jest/fake-timers': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 20.11.22 + '@types/node': 20.11.27 jest-mock: 29.7.0 dev: true @@ -547,7 +547,7 @@ packages: dependencies: '@jest/types': 29.6.3 '@sinonjs/fake-timers': 10.3.0 - '@types/node': 20.11.22 + '@types/node': 20.11.27 jest-message-util: 29.7.0 jest-mock: 29.7.0 jest-util: 29.7.0 @@ -580,7 +580,7 @@ packages: '@jest/transform': 29.7.0 '@jest/types': 29.6.3 '@jridgewell/trace-mapping': 0.3.22 - '@types/node': 20.11.22 + '@types/node': 20.11.27 chalk: 4.1.2 collect-v8-coverage: 1.0.2 exit: 0.1.2 @@ -668,7 +668,7 @@ packages: '@jest/schemas': 29.6.3 '@types/istanbul-lib-coverage': 2.0.6 '@types/istanbul-reports': 3.0.4 - '@types/node': 20.11.22 + '@types/node': 20.11.27 '@types/yargs': 17.0.32 chalk: 4.1.2 dev: true @@ -777,7 +777,7 @@ packages: /@types/graceful-fs@4.1.9: resolution: {integrity: sha512-olP3sd1qOEe5dXTSaFvQG+02VdRXcdytWLAZsAq1PecU8uqQAhkrnbli7DagjtXKW/Bl7YJbUsa8MPcuc8LHEQ==} dependencies: - '@types/node': 20.11.22 + '@types/node': 20.11.27 dev: true /@types/istanbul-lib-coverage@2.0.6: @@ -807,8 +807,8 @@ packages: resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==} dev: true - /@types/node@20.11.22: - resolution: {integrity: sha512-/G+IxWxma6V3E+pqK1tSl2Fo1kl41pK1yeCyDsgkF9WlVAme4j5ISYM2zR11bgLFJGLN5sVK40T4RJNuiZbEjA==} + /@types/node@20.11.27: + resolution: {integrity: sha512-qyUZfMnCg1KEz57r7pzFtSGt49f6RPkPBis3Vo4PbS7roQEDn22hiHzl/Lo1q4i4hDEgBJmBF/NTNg2XR0HbFg==} dependencies: undici-types: 5.26.5 dev: true @@ -831,8 +831,8 @@ packages: '@types/yargs-parser': 21.0.3 dev: true - /@typescript-eslint/eslint-plugin@7.1.0(@typescript-eslint/parser@7.1.0)(eslint@8.57.0)(typescript@5.3.3): - resolution: {integrity: sha512-j6vT/kCulhG5wBmGtstKeiVr1rdXE4nk+DT1k6trYkwlrvW9eOF5ZbgKnd/YR6PcM4uTEXa0h6Fcvf6X7Dxl0w==} + /@typescript-eslint/eslint-plugin@7.2.0(@typescript-eslint/parser@7.2.0)(eslint@8.57.0)(typescript@5.4.2): + resolution: {integrity: sha512-mdekAHOqS9UjlmyF/LSs6AIEvfceV749GFxoBAjwAv0nkevfKHWQFDMcBZWUiIC5ft6ePWivXoS36aKQ0Cy3sw==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: '@typescript-eslint/parser': ^7.0.0 @@ -843,25 +843,25 @@ packages: optional: true dependencies: '@eslint-community/regexpp': 4.10.0 - '@typescript-eslint/parser': 7.1.0(eslint@8.57.0)(typescript@5.3.3) - '@typescript-eslint/scope-manager': 7.1.0 - '@typescript-eslint/type-utils': 7.1.0(eslint@8.57.0)(typescript@5.3.3) - '@typescript-eslint/utils': 7.1.0(eslint@8.57.0)(typescript@5.3.3) - '@typescript-eslint/visitor-keys': 7.1.0 + '@typescript-eslint/parser': 7.2.0(eslint@8.57.0)(typescript@5.4.2) + '@typescript-eslint/scope-manager': 7.2.0 + '@typescript-eslint/type-utils': 7.2.0(eslint@8.57.0)(typescript@5.4.2) + '@typescript-eslint/utils': 7.2.0(eslint@8.57.0)(typescript@5.4.2) + '@typescript-eslint/visitor-keys': 7.2.0 debug: 4.3.4 eslint: 8.57.0 graphemer: 1.4.0 ignore: 5.3.1 natural-compare: 1.4.0 semver: 7.6.0 - ts-api-utils: 1.2.1(typescript@5.3.3) - typescript: 5.3.3 + ts-api-utils: 1.3.0(typescript@5.4.2) + typescript: 5.4.2 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/parser@7.1.0(eslint@8.57.0)(typescript@5.3.3): - resolution: {integrity: sha512-V1EknKUubZ1gWFjiOZhDSNToOjs63/9O0puCgGS8aDOgpZY326fzFu15QAUjwaXzRZjf/qdsdBrckYdv9YxB8w==} + /@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.4.2): + resolution: {integrity: sha512-5FKsVcHTk6TafQKQbuIVkXq58Fnbkd2wDL4LB7AURN7RUOu1utVP+G8+6u3ZhEroW3DF6hyo3ZEXxgKgp4KeCg==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: eslint: ^8.56.0 @@ -870,27 +870,27 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/scope-manager': 7.1.0 - '@typescript-eslint/types': 7.1.0 - '@typescript-eslint/typescript-estree': 7.1.0(typescript@5.3.3) - '@typescript-eslint/visitor-keys': 7.1.0 + '@typescript-eslint/scope-manager': 7.2.0 + '@typescript-eslint/types': 7.2.0 + '@typescript-eslint/typescript-estree': 7.2.0(typescript@5.4.2) + '@typescript-eslint/visitor-keys': 7.2.0 debug: 4.3.4 eslint: 8.57.0 - typescript: 5.3.3 + typescript: 5.4.2 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/scope-manager@7.1.0: - resolution: {integrity: sha512-6TmN4OJiohHfoOdGZ3huuLhpiUgOGTpgXNUPJgeZOZR3DnIpdSgtt83RS35OYNNXxM4TScVlpVKC9jyQSETR1A==} + /@typescript-eslint/scope-manager@7.2.0: + resolution: {integrity: sha512-Qh976RbQM/fYtjx9hs4XkayYujB/aPwglw2choHmf3zBjB4qOywWSdt9+KLRdHubGcoSwBnXUH2sR3hkyaERRg==} engines: {node: ^16.0.0 || >=18.0.0} dependencies: - '@typescript-eslint/types': 7.1.0 - '@typescript-eslint/visitor-keys': 7.1.0 + '@typescript-eslint/types': 7.2.0 + '@typescript-eslint/visitor-keys': 7.2.0 dev: true - /@typescript-eslint/type-utils@7.1.0(eslint@8.57.0)(typescript@5.3.3): - resolution: {integrity: sha512-UZIhv8G+5b5skkcuhgvxYWHjk7FW7/JP5lPASMEUoliAPwIH/rxoUSQPia2cuOj9AmDZmwUl1usKm85t5VUMew==} + /@typescript-eslint/type-utils@7.2.0(eslint@8.57.0)(typescript@5.4.2): + resolution: {integrity: sha512-xHi51adBHo9O9330J8GQYQwrKBqbIPJGZZVQTHHmy200hvkLZFWJIFtAG/7IYTWUyun6DE6w5InDReePJYJlJA==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: eslint: ^8.56.0 @@ -899,23 +899,23 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/typescript-estree': 7.1.0(typescript@5.3.3) - '@typescript-eslint/utils': 7.1.0(eslint@8.57.0)(typescript@5.3.3) + '@typescript-eslint/typescript-estree': 7.2.0(typescript@5.4.2) + '@typescript-eslint/utils': 7.2.0(eslint@8.57.0)(typescript@5.4.2) debug: 4.3.4 eslint: 8.57.0 - ts-api-utils: 1.2.1(typescript@5.3.3) - typescript: 5.3.3 + ts-api-utils: 1.3.0(typescript@5.4.2) + typescript: 5.4.2 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/types@7.1.0: - resolution: {integrity: sha512-qTWjWieJ1tRJkxgZYXx6WUYtWlBc48YRxgY2JN1aGeVpkhmnopq+SUC8UEVGNXIvWH7XyuTjwALfG6bFEgCkQA==} + /@typescript-eslint/types@7.2.0: + resolution: {integrity: sha512-XFtUHPI/abFhm4cbCDc5Ykc8npOKBSJePY3a3s+lwumt7XWJuzP5cZcfZ610MIPHjQjNsOLlYK8ASPaNG8UiyA==} engines: {node: ^16.0.0 || >=18.0.0} dev: true - /@typescript-eslint/typescript-estree@7.1.0(typescript@5.3.3): - resolution: {integrity: sha512-k7MyrbD6E463CBbSpcOnwa8oXRdHzH1WiVzOipK3L5KSML92ZKgUBrTlehdi7PEIMT8k0bQixHUGXggPAlKnOQ==} + /@typescript-eslint/typescript-estree@7.2.0(typescript@5.4.2): + resolution: {integrity: sha512-cyxS5WQQCoBwSakpMrvMXuMDEbhOo9bNHHrNcEWis6XHx6KF518tkF1wBvKIn/tpq5ZpUYK7Bdklu8qY0MsFIA==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: typescript: '*' @@ -923,21 +923,21 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/types': 7.1.0 - '@typescript-eslint/visitor-keys': 7.1.0 + '@typescript-eslint/types': 7.2.0 + '@typescript-eslint/visitor-keys': 7.2.0 debug: 4.3.4 globby: 11.1.0 is-glob: 4.0.3 minimatch: 9.0.3 semver: 7.6.0 - ts-api-utils: 1.2.1(typescript@5.3.3) - typescript: 5.3.3 + ts-api-utils: 1.3.0(typescript@5.4.2) + typescript: 5.4.2 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/utils@7.1.0(eslint@8.57.0)(typescript@5.3.3): - resolution: {integrity: sha512-WUFba6PZC5OCGEmbweGpnNJytJiLG7ZvDBJJoUcX4qZYf1mGZ97mO2Mps6O2efxJcJdRNpqweCistDbZMwIVHw==} + /@typescript-eslint/utils@7.2.0(eslint@8.57.0)(typescript@5.4.2): + resolution: {integrity: sha512-YfHpnMAGb1Eekpm3XRK8hcMwGLGsnT6L+7b2XyRv6ouDuJU1tZir1GS2i0+VXRatMwSI1/UfcyPe53ADkU+IuA==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: eslint: ^8.56.0 @@ -945,9 +945,9 @@ packages: '@eslint-community/eslint-utils': 4.4.0(eslint@8.57.0) '@types/json-schema': 7.0.15 '@types/semver': 7.5.8 - '@typescript-eslint/scope-manager': 7.1.0 - '@typescript-eslint/types': 7.1.0 - '@typescript-eslint/typescript-estree': 7.1.0(typescript@5.3.3) + '@typescript-eslint/scope-manager': 7.2.0 + '@typescript-eslint/types': 7.2.0 + '@typescript-eslint/typescript-estree': 7.2.0(typescript@5.4.2) eslint: 8.57.0 semver: 7.6.0 transitivePeerDependencies: @@ -955,11 +955,11 @@ packages: - typescript dev: true - /@typescript-eslint/visitor-keys@7.1.0: - resolution: {integrity: sha512-FhUqNWluiGNzlvnDZiXad4mZRhtghdoKW6e98GoEOYSu5cND+E39rG5KwJMUzeENwm1ztYBRqof8wMLP+wNPIA==} + /@typescript-eslint/visitor-keys@7.2.0: + resolution: {integrity: sha512-c6EIQRHhcpl6+tO8EMR+kjkkV+ugUNXOmeASA1rlzkd8EPIriavpWoiEz1HR/VLhbVIdhqnV6E7JZm00cBDx2A==} engines: {node: ^16.0.0 || >=18.0.0} dependencies: - '@typescript-eslint/types': 7.1.0 + '@typescript-eslint/types': 7.2.0 eslint-visitor-keys: 3.4.3 dev: true @@ -1276,7 +1276,7 @@ packages: resolution: {integrity: sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==} dev: true - /create-jest@29.7.0(@types/node@20.11.22): + /create-jest@29.7.0(@types/node@20.11.27): resolution: {integrity: sha512-Adz2bdH0Vq3F53KEMJOoftQFutWCukm6J24wbPWRO4k1kMY7gS7ds/uoJkNuV8wDCtWWnuwGcJwpWcih+zEW1Q==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} hasBin: true @@ -1285,7 +1285,7 @@ packages: chalk: 4.1.2 exit: 0.1.2 graceful-fs: 4.2.11 - jest-config: 29.7.0(@types/node@20.11.22) + jest-config: 29.7.0(@types/node@20.11.27) jest-util: 29.7.0 prompts: 2.4.2 transitivePeerDependencies: @@ -1939,7 +1939,7 @@ packages: '@jest/expect': 29.7.0 '@jest/test-result': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 20.11.22 + '@types/node': 20.11.27 chalk: 4.1.2 co: 4.6.0 dedent: 1.5.1 @@ -1960,7 +1960,7 @@ packages: - supports-color dev: true - /jest-cli@29.7.0(@types/node@20.11.22): + /jest-cli@29.7.0(@types/node@20.11.27): resolution: {integrity: sha512-OVVobw2IubN/GSYsxETi+gOe7Ka59EFMR/twOU3Jb2GnKKeMGJB5SGUUrEz3SFVmJASUdZUzy83sLNNQ2gZslg==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} hasBin: true @@ -1974,10 +1974,10 @@ packages: '@jest/test-result': 29.7.0 '@jest/types': 29.6.3 chalk: 4.1.2 - create-jest: 29.7.0(@types/node@20.11.22) + create-jest: 29.7.0(@types/node@20.11.27) exit: 0.1.2 import-local: 3.1.0 - jest-config: 29.7.0(@types/node@20.11.22) + jest-config: 29.7.0(@types/node@20.11.27) jest-util: 29.7.0 jest-validate: 29.7.0 yargs: 17.7.2 @@ -1988,7 +1988,7 @@ packages: - ts-node dev: true - /jest-config@29.7.0(@types/node@20.11.22): + /jest-config@29.7.0(@types/node@20.11.27): resolution: {integrity: sha512-uXbpfeQ7R6TZBqI3/TxCU4q4ttk3u0PJeC+E0zbfSoSjq6bJ7buBPxzQPL0ifrkY4DNu4JUdk0ImlBUYi840eQ==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} peerDependencies: @@ -2003,7 +2003,7 @@ packages: '@babel/core': 7.23.9 '@jest/test-sequencer': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 20.11.22 + '@types/node': 20.11.27 babel-jest: 29.7.0(@babel/core@7.23.9) chalk: 4.1.2 ci-info: 3.9.0 @@ -2063,7 +2063,7 @@ packages: '@jest/environment': 29.7.0 '@jest/fake-timers': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 20.11.22 + '@types/node': 20.11.27 jest-mock: 29.7.0 jest-util: 29.7.0 dev: true @@ -2079,7 +2079,7 @@ packages: dependencies: '@jest/types': 29.6.3 '@types/graceful-fs': 4.1.9 - '@types/node': 20.11.22 + '@types/node': 20.11.27 anymatch: 3.1.3 fb-watchman: 2.0.2 graceful-fs: 4.2.11 @@ -2130,7 +2130,7 @@ packages: engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dependencies: '@jest/types': 29.6.3 - '@types/node': 20.11.22 + '@types/node': 20.11.27 jest-util: 29.7.0 dev: true @@ -2185,7 +2185,7 @@ packages: '@jest/test-result': 29.7.0 '@jest/transform': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 20.11.22 + '@types/node': 20.11.27 chalk: 4.1.2 emittery: 0.13.1 graceful-fs: 4.2.11 @@ -2216,7 +2216,7 @@ packages: '@jest/test-result': 29.7.0 '@jest/transform': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 20.11.22 + '@types/node': 20.11.27 chalk: 4.1.2 cjs-module-lexer: 1.2.3 collect-v8-coverage: 1.0.2 @@ -2268,7 +2268,7 @@ packages: engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dependencies: '@jest/types': 29.6.3 - '@types/node': 20.11.22 + '@types/node': 20.11.27 chalk: 4.1.2 ci-info: 3.9.0 graceful-fs: 4.2.11 @@ -2293,7 +2293,7 @@ packages: dependencies: '@jest/test-result': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 20.11.22 + '@types/node': 20.11.27 ansi-escapes: 4.3.2 chalk: 4.1.2 emittery: 0.13.1 @@ -2305,13 +2305,13 @@ packages: resolution: {integrity: sha512-eIz2msL/EzL9UFTFFx7jBTkeZfku0yUAyZZZmJ93H2TYEiroIx2PQjEXcwYtYl8zXCxb+PAmA2hLIt/6ZEkPHw==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dependencies: - '@types/node': 20.11.22 + '@types/node': 20.11.27 jest-util: 29.7.0 merge-stream: 2.0.0 supports-color: 8.1.1 dev: true - /jest@29.7.0(@types/node@20.11.22): + /jest@29.7.0(@types/node@20.11.27): resolution: {integrity: sha512-NIy3oAFp9shda19hy4HK0HRTWKtPJmGdnvywu01nOqNC2vZg+Z+fvJDxpMQA88eb2I9EcafcdjYgsDthnYTvGw==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} hasBin: true @@ -2324,7 +2324,7 @@ packages: '@jest/core': 29.7.0 '@jest/types': 29.6.3 import-local: 3.1.0 - jest-cli: 29.7.0(@types/node@20.11.22) + jest-cli: 29.7.0(@types/node@20.11.27) transitivePeerDependencies: - '@types/node' - babel-plugin-macros @@ -2956,16 +2956,16 @@ packages: resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==} dev: true - /ts-api-utils@1.2.1(typescript@5.3.3): - resolution: {integrity: sha512-RIYA36cJn2WiH9Hy77hdF9r7oEwxAtB/TS9/S4Qd90Ap4z5FSiin5zEiTL44OII1Y3IIlEvxwxFUVgrHSZ/UpA==} + /ts-api-utils@1.3.0(typescript@5.4.2): + resolution: {integrity: sha512-UQMIo7pb8WRomKR1/+MFVLTroIvDVtMX3K6OUir8ynLyzB8Jeriont2bTAtmNPa1ekAgN7YPDyf6V+ygrdU+eQ==} engines: {node: '>=16'} peerDependencies: typescript: '>=4.2.0' dependencies: - typescript: 5.3.3 + typescript: 5.4.2 dev: true - /ts-jest@29.1.2(@babel/core@7.23.9)(jest@29.7.0)(typescript@5.3.3): + /ts-jest@29.1.2(@babel/core@7.23.9)(jest@29.7.0)(typescript@5.4.2): resolution: {integrity: sha512-br6GJoH/WUX4pu7FbZXuWGKGNDuU7b8Uj77g/Sp7puZV6EXzuByl6JrECvm0MzVzSTkSHWTihsXt+5XYER5b+g==} engines: {node: ^16.10.0 || ^18.0.0 || >=20.0.0} hasBin: true @@ -2989,13 +2989,13 @@ packages: '@babel/core': 7.23.9 bs-logger: 0.2.6 fast-json-stable-stringify: 2.1.0 - jest: 29.7.0(@types/node@20.11.22) + jest: 29.7.0(@types/node@20.11.27) jest-util: 29.7.0 json5: 2.2.3 lodash.memoize: 4.1.2 make-error: 1.3.6 semver: 7.5.4 - typescript: 5.3.3 + typescript: 5.4.2 yargs-parser: 21.1.1 dev: true @@ -3025,8 +3025,8 @@ packages: engines: {node: '>=10'} dev: true - /typescript@5.3.3: - resolution: {integrity: sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==} + /typescript@5.4.2: + resolution: {integrity: sha512-+2/g0Fds1ERlP6JsakQQDXjZdZMM+rqpamFZJEKh4kwTIn3iDkgKtby0CeNd5ATNZ4Ry1ax15TMx0W2V+miizQ==} engines: {node: '>=14.17'} hasBin: true dev: true diff --git a/crates/api/Cargo.toml b/crates/api/Cargo.toml index 66dcea19b..fcbea1e5d 100644 --- a/crates/api/Cargo.toml +++ b/crates/api/Cargo.toml @@ -34,7 +34,7 @@ tracing = { workspace = true } chrono = { workspace = true } url = { workspace = true } wav = "1.0.0" -sitemap-rs = "0.2.0" +sitemap-rs = "0.2.1" totp-rs = { version = "5.5.1", features = ["gen_secret", "otpauth"] } actix-web-httpauth = "0.8.1" diff --git a/crates/db_schema/src/impls/post.rs b/crates/db_schema/src/impls/post.rs index a75fa4349..3425a795d 100644 --- a/crates/db_schema/src/impls/post.rs +++ b/crates/db_schema/src/impls/post.rs @@ -27,7 +27,7 @@ use crate::{ }, }; use ::url::Url; -use chrono::{Duration, Utc}; +use chrono::Utc; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl, TextExpressionMethods}; use diesel_async::RunQueryDsl; use std::collections::HashSet; @@ -104,7 +104,9 @@ impl Post { .filter(post::local.eq(true)) .filter(post::deleted.eq(false)) .filter(post::removed.eq(false)) - .filter(post::published.ge(Utc::now().naive_utc() - Duration::days(SITEMAP_DAYS))) + .filter( + post::published.ge(Utc::now().naive_utc() - SITEMAP_DAYS.expect("TimeDelta out of bounds")), + ) .order(post::published.desc()) .limit(SITEMAP_LIMIT) .load::<(DbUrl, chrono::DateTime)>(conn) diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index 038ab129a..9a89902e7 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -6,7 +6,7 @@ use crate::{ SortType, }; use anyhow::Context; -use chrono::{DateTime, Utc}; +use chrono::{DateTime, TimeDelta, Utc}; use deadpool::Runtime; use diesel::{ helper_types::AsExprOf, @@ -51,7 +51,7 @@ use url::Url; const FETCH_LIMIT_DEFAULT: i64 = 10; pub const FETCH_LIMIT_MAX: i64 = 50; pub const SITEMAP_LIMIT: i64 = 50000; -pub const SITEMAP_DAYS: i64 = 31; +pub const SITEMAP_DAYS: Option = TimeDelta::try_days(31); pub const RANK_DEFAULT: f64 = 0.0001; pub type ActualDbPool = Pool; diff --git a/crates/federate/src/worker.rs b/crates/federate/src/worker.rs index eb209fd50..ff2a68e3c 100644 --- a/crates/federate/src/worker.rs +++ b/crates/federate/src/worker.rs @@ -46,17 +46,17 @@ static SAVE_STATE_EVERY_TIME: Duration = Duration::from_secs(60); /// this delay limits the maximum time until the follow actually results in activities from that community id being sent to that inbox url. /// This delay currently needs to not be too small because the DB load is currently fairly high because of the current structure of storing inboxes for every person, not having a separate list of shared_inboxes, and the architecture of having every instance queue be fully separate. /// (see https://github.com/LemmyNet/lemmy/issues/3958) -static FOLLOW_ADDITIONS_RECHECK_DELAY: Lazy = Lazy::new(|| { +static FOLLOW_ADDITIONS_RECHECK_DELAY: Lazy = Lazy::new(|| { if *LEMMY_TEST_FAST_FEDERATION { - chrono::Duration::seconds(1) + chrono::TimeDelta::try_seconds(1).expect("TimeDelta out of bounds") } else { - chrono::Duration::minutes(2) + chrono::TimeDelta::try_minutes(2).expect("TimeDelta out of bounds") } }); /// The same as FOLLOW_ADDITIONS_RECHECK_DELAY, but triggering when the last person on an instance unfollows a specific remote community. /// This is expected to happen pretty rarely and updating it in a timely manner is not too important. -static FOLLOW_REMOVALS_RECHECK_DELAY: Lazy = - Lazy::new(|| chrono::Duration::hours(1)); +static FOLLOW_REMOVALS_RECHECK_DELAY: Lazy = + Lazy::new(|| chrono::TimeDelta::try_hours(1).expect("TimeDelta out of bounds")); pub(crate) struct InstanceWorker { instance: Instance, // load site lazily because if an instance is first seen due to being on allowlist, @@ -332,7 +332,8 @@ impl InstanceWorker { instance_id: InstanceId, last_fetch: DateTime, ) -> Result<(HashMap>, DateTime)> { - let new_last_fetch = Utc::now() - chrono::Duration::seconds(10); // update to time before fetch to ensure overlap. subtract 10s to ensure overlap even if published date is not exact + let new_last_fetch = + Utc::now() - chrono::TimeDelta::try_seconds(10).expect("TimeDelta out of bounds"); // update to time before fetch to ensure overlap. subtract 10s to ensure overlap even if published date is not exact Ok(( CommunityFollowerView::get_instance_followed_community_inboxes(pool, instance_id, last_fetch) .await? diff --git a/crates/utils/Cargo.toml b/crates/utils/Cargo.toml index 2a832bec0..0a1b22c32 100644 --- a/crates/utils/Cargo.toml +++ b/crates/utils/Cargo.toml @@ -74,11 +74,11 @@ uuid = { workspace = true, features = ["serde", "v4"], optional = true } rosetta-i18n = { workspace = true, optional = true } tokio = { workspace = true, optional = true } urlencoding = { workspace = true, optional = true } -openssl = { version = "0.10.63", optional = true } +openssl = { version = "0.10.64", optional = true } html2text = { version = "0.6.0", optional = true } deser-hjson = { version = "2.2.4", optional = true } smart-default = { version = "0.7.1", optional = true } -lettre = { version = "0.11.3", features = [ +lettre = { version = "0.11.4", features = [ "tokio1", "tokio1-native-tls", ], optional = true } From 2fd81067c7130a23cabfff8bfa76b349b87e8426 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 18 Mar 2024 07:54:45 -0400 Subject: [PATCH 19/31] Temporarily comment sticky test. (#4538) --- api_tests/src/post.spec.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api_tests/src/post.spec.ts b/api_tests/src/post.spec.ts index 59a0557bf..bd8b0051f 100644 --- a/api_tests/src/post.spec.ts +++ b/api_tests/src/post.spec.ts @@ -220,9 +220,10 @@ test("Sticky a post", async () => { if (!gammaPost) { throw "Missing gamma post"; } - let gammaTrySticky = await featurePost(gamma, true, gammaPost.post); + // This has been failing occasionally + await featurePost(gamma, true, gammaPost.post); let betaPost3 = (await resolvePost(beta, postRes.post_view.post)).post; - expect(gammaTrySticky.post_view.post.featured_community).toBe(true); + // expect(gammaTrySticky.post_view.post.featured_community).toBe(true); expect(betaPost3?.post.featured_community).toBe(false); }); From 78581bd6963a072563da76e9e149a0e65c7f528c Mon Sep 17 00:00:00 2001 From: Tomas <8504482+wereii@users.noreply.github.com> Date: Thu, 21 Mar 2024 15:42:30 +0000 Subject: [PATCH 20/31] Add ARG RUSTFLAGS into Dockerfile (#4556) * Add ARG RUSTFLAGS into Dockerfile Allows passing RUSTFLAGS through --build-arg * Remove invalid ARG syntax --- docker/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker/Dockerfile b/docker/Dockerfile index 0630b6e50..39804ee82 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -19,6 +19,7 @@ FROM --platform=${BUILDPLATFORM} ${AMD_BUILDER_IMAGE} AS build-amd64 ARG CARGO_BUILD_FEATURES ARG RUST_RELEASE_MODE +ARG RUSTFLAGS WORKDIR /lemmy @@ -48,6 +49,7 @@ FROM --platform=linux/amd64 ${ARM_BUILDER_IMAGE} AS build-arm64 ARG RUST_RELEASE_MODE ARG CARGO_BUILD_FEATURES +ARG RUSTFLAGS WORKDIR /home/lemmy/src USER 10001:10001 From 38c22d9453e60612aebcc9551bf0397b8734065a Mon Sep 17 00:00:00 2001 From: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com> Date: Fri, 22 Mar 2024 18:31:08 -0400 Subject: [PATCH 21/31] Add banned_from_community to PostView and CommentView (#4552) * Add banned_from_community to PostView and CommentView * Add post view test * Add tests for CommentView * Add tests for case where local user is not banned from community --------- Co-authored-by: SleeplessOne1917 --- Cargo.lock | 182 +++++++++-------- crates/db_views/src/comment_view.rs | 248 +++++++++++++---------- crates/db_views/src/custom_emoji_view.rs | 2 +- crates/db_views/src/post_view.rs | 87 +++++++- crates/db_views/src/structs.rs | 2 + 5 files changed, 331 insertions(+), 190 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5ef691e26..0ce7859e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -157,7 +157,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb" dependencies = [ "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -315,7 +315,7 @@ dependencies = [ "actix-router", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -533,18 +533,18 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] name = "async-trait" -version = "0.1.77" +version = "0.1.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" +checksum = "461abc97219de0eaaf81fe3ef974a540158f3d079c2ab200f891f1a2ef201e85" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -656,6 +656,12 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "base64" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" + [[package]] name = "base64ct" version = "1.6.0" @@ -687,11 +693,11 @@ dependencies = [ [[package]] name = "bcrypt" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d1c9c15093eb224f0baa400f38fcd713fc1391a6f1c389d886beef146d60a3" +checksum = "e65938ed058ef47d92cf8b346cc76ef48984572ade631927e9937b5ffc7662c7" dependencies = [ - "base64 0.21.7", + "base64 0.22.0", "blowfish", "getrandom", "subtle", @@ -764,9 +770,9 @@ checksum = "bfb5ea45aeb912f2dd334834e64ecf674a6673d57c73e9d12de0298b9bf98ee8" [[package]] name = "brotli" -version = "3.4.0" +version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "516074a47ef4bce09577a3b379392300159ce5b1ba2e501ff1c819950066100f" +checksum = "d640d25bc63c50fb1f0b545ffd80207d2e10a4c965530809b40ba3386825c391" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", @@ -926,9 +932,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.2" +version = "4.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b230ab84b0ffdf890d5a10abdbc8b83ae1c4918275daea1ab8801f71536b2651" +checksum = "949626d00e063efc93b6dca932419ceb5432f99769911c0b995f7e884c778813" dependencies = [ "clap_builder", "clap_derive", @@ -948,14 +954,14 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.0" +version = "4.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "307bc0538d5f0f83b8248db3087aa92fe504e4691294d0c96c0eabc33f47ba47" +checksum = "90239a040c80f5e14809ca132ddc4176ab33d5e17e49691793296e3fcb34d72f" dependencies = [ - "heck", + "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -975,9 +981,9 @@ dependencies = [ [[package]] name = "color-eyre" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204" +checksum = "55146f5e46f237f7423d74111267d4597b59b0dad0ffaf7303bce9945d843ad5" dependencies = [ "backtrace", "color-spantrace", @@ -1034,7 +1040,7 @@ dependencies = [ "ron", "serde", "serde_json", - "toml 0.8.11", + "toml 0.8.12", "yaml-rust", ] @@ -1297,7 +1303,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.10.0", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -1330,7 +1336,7 @@ checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" dependencies = [ "darling_core 0.20.8", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -1466,9 +1472,9 @@ dependencies = [ [[package]] name = "diesel" -version = "2.1.4" +version = "2.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62c6fcf842f17f8c78ecf7c81d75c5ce84436b41ee07e03f490fbb5f5a8731d8" +checksum = "03fc05c17098f21b89bc7d98fe1dd3cce2c11c2ad8e145f2a44fe08ed28eb559" dependencies = [ "bitflags 2.4.2", "byteorder", @@ -1503,33 +1509,33 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81c5131a2895ef64741dad1d483f358c2a229a3a2d1b256778cdc5e146db64d4" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] name = "diesel-derive-newtype" -version = "2.1.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7267437d5b12df60ae29bd97f8d120f1c3a6272d6f213551afa56bbb2ecfbb7" +checksum = "f4ed4d69628c8de8eb4c3f50cddb0678cba3c5b4cbe3cb1067d4d6c62ca47e4e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] name = "diesel_derives" -version = "2.1.2" +version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef8337737574f55a468005a83499da720f20c65586241ffea339db9ecdfd2b44" +checksum = "5d02eecb814ae714ffe61ddc2db2dd03e6c49a42e269b5001355500d431cce0c" dependencies = [ "diesel_table_macro_syntax", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -1559,7 +1565,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc5557efc453706fed5e4fa85006fe9817c224c3f480a34c7e5959fd700921c5" dependencies = [ - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -1751,7 +1757,7 @@ checksum = "f282cfdfe92516eb26c2af8589c274c7c17681f5ecc03c18255fe741c6aa64eb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -1993,7 +1999,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -2072,9 +2078,9 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "h2" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb2c4422095b67ee78da96fbb51a4cc413b3b25883c7717ff7ca1ab31022c9c9" +checksum = "4fbd2820c5e49886948654ab546d0688ff24530286bdcf8fca3cefb16d4618eb" dependencies = [ "bytes", "fnv", @@ -2133,6 +2139,12 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.3.9" @@ -2367,7 +2379,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8215279f83f9b829403812f845aa2d0dd5966332aa2fd0334a375256f3dd0322" dependencies = [ "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -2633,6 +2645,7 @@ version = "0.19.3" dependencies = [ "activitypub_federation", "actix-web", + "anyhow", "chrono", "encoding", "enum-map", @@ -2645,6 +2658,7 @@ dependencies = [ "lemmy_db_views_moderator", "lemmy_utils", "mime", + "moka", "once_cell", "pretty_assertions", "regex", @@ -3183,9 +3197,9 @@ checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "metrics" -version = "0.22.0" +version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77b9e10a211c839210fd7f99954bda26e5f8e26ec686ad68da6a32df7c80e782" +checksum = "2be3cbd384d4e955b231c895ce10685e3d8260c5ccffae898c96c723b0772835" dependencies = [ "ahash", "portable-atomic", @@ -3210,9 +3224,9 @@ dependencies = [ [[package]] name = "metrics-util" -version = "0.16.2" +version = "0.16.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ece71ab046dcf45604e573329966ec1db5ff4b81cfa170a924ff4c959ab5451a" +checksum = "8b07a5eb561b8cbc16be2d216faf7757f9baf3bfb94dbb0fae3df8387a5bb47f" dependencies = [ "crossbeam-epoch", "crossbeam-utils", @@ -3353,9 +3367,9 @@ checksum = "c96aba5aa877601bb3f6dd6a63a969e1f82e60646e81e71b14496995e9853c91" [[package]] name = "new_debug_unreachable" -version = "1.0.4" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" [[package]] name = "nom" @@ -3460,7 +3474,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -3867,7 +3881,7 @@ dependencies = [ "tokio-postgres", "tokio-postgres-rustls 0.11.1", "tokio-util", - "toml 0.8.11", + "toml 0.8.12", "tracing", "tracing-actix-web", "tracing-error", @@ -3896,7 +3910,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -4116,7 +4130,7 @@ dependencies = [ "itertools 0.11.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -4260,7 +4274,7 @@ checksum = "a25d631e41bfb5fdcde1d4e2215f62f7f0afa3ff11e26563765bd6ea1d229aeb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -4303,12 +4317,12 @@ dependencies = [ "postgres", "regex", "serde", - "siphasher 1.0.0", + "siphasher 1.0.1", "thiserror", "time", "tokio", "tokio-postgres", - "toml 0.8.11", + "toml 0.8.12", "url", "walkdir", ] @@ -4323,7 +4337,7 @@ dependencies = [ "quote", "refinery-core", "regex", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -4420,9 +4434,9 @@ dependencies = [ [[package]] name = "reqwest-middleware" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88a3e86aa6053e59030e7ce2d2a3b258dd08fc2d337d52f73f6cb480f5858690" +checksum = "5a735987236a8e238bf0296c7e351b999c188ccc11477f311b82b55c93984216" dependencies = [ "anyhow", "async-trait", @@ -4435,9 +4449,9 @@ dependencies = [ [[package]] name = "reqwest-tracing" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a0152176687dd5cfe7f507ac1cb1a491c679cfe483afd133a7db7aaea818bb3" +checksum = "190838e54153d7a7e2ea98851304b3ce92daeabf14c54d32b01b84a3e636f683" dependencies = [ "anyhow", "async-trait", @@ -4832,7 +4846,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -4904,7 +4918,7 @@ dependencies = [ "darling 0.20.8", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -4929,7 +4943,7 @@ checksum = "91d129178576168c589c9ec973feedf7d3126c01ac2bf08795109aa35b69fb8f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -5007,9 +5021,9 @@ checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" [[package]] name = "siphasher" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54ac45299ccbd390721be55b412d41931911f654fa99e2cb8bfb57184b2061fe" +checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" [[package]] name = "sitemap-rs" @@ -5081,7 +5095,7 @@ checksum = "0eb01866308440fc64d6c44d9e86c5cc17adfe33c4d6eed55da9145044d0ffc1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -5209,11 +5223,11 @@ version = "0.25.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro2", "quote", "rustversion", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -5235,9 +5249,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.52" +version = "2.0.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" +checksum = "7383cd0e49fff4b6b90ca5670bfd3e9d6a733b3f90c686605aa7eec8c4996032" dependencies = [ "proc-macro2", "quote", @@ -5357,7 +5371,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -5460,7 +5474,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -5562,9 +5576,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" dependencies = [ "futures-core", "pin-project-lite", @@ -5599,14 +5613,14 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.11" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af06656561d28735e9c1cd63dfd57132c8155426aa6af24f36a00a351f88c48e" +checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.22.7", + "toml_edit 0.22.8", ] [[package]] @@ -5633,9 +5647,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.7" +version = "0.22.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18769cd1cec395d70860ceb4d932812a0b4d06b1a4bb336745a4d21b9496e992" +checksum = "c12219811e0c1ba077867254e5ad62ee2c9c190b0d957110750ac0cda1ae96cd" dependencies = [ "indexmap 2.2.5", "serde", @@ -5841,7 +5855,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -6004,7 +6018,7 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", "termcolor", ] @@ -6025,7 +6039,7 @@ checksum = "563b3b88238ec95680aef36bdece66896eaa7ce3c0f1b4f39d38fb2435261352" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -6132,9 +6146,9 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] name = "uuid" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f00cc9702ca12d3c81455259621e676d0f7251cec66a21e98fe2e9a37db93b2a" +checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" dependencies = [ "atomic", "getrandom", @@ -6211,7 +6225,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", "wasm-bindgen-shared", ] @@ -6245,7 +6259,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -6704,7 +6718,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -6724,7 +6738,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index 40065672c..5f811cb0d 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -53,6 +53,16 @@ fn queries<'a>() -> Queries< ), ); + let is_local_user_banned_from_community = |person_id| { + exists( + community_person_ban::table.filter( + community::id + .eq(community_person_ban::community_id) + .and(community_person_ban::person_id.eq(person_id)), + ), + ) + }; + let is_saved = |person_id| { comment_saved::table .filter( @@ -113,6 +123,14 @@ fn queries<'a>() -> Queries< ); let all_joins = move |query: comment::BoxedQuery<'a, Pg>, my_person_id: Option| { + let is_local_user_banned_from_community_selection: Box< + dyn BoxableExpression<_, Pg, SqlType = sql_types::Bool>, + > = if let Some(person_id) = my_person_id { + Box::new(is_local_user_banned_from_community(person_id)) + } else { + Box::new(false.into_sql::()) + }; + let score_selection: Box< dyn BoxableExpression<_, Pg, SqlType = sql_types::Nullable>, > = if let Some(person_id) = my_person_id { @@ -156,6 +174,7 @@ fn queries<'a>() -> Queries< community::all_columns, comment_aggregates::all_columns, is_creator_banned_from_community, + is_local_user_banned_from_community_selection, creator_is_moderator, creator_is_admin, subscribed_type_selection, @@ -436,6 +455,8 @@ mod tests { CommunityInsertForm, CommunityModerator, CommunityModeratorForm, + CommunityPersonBan, + CommunityPersonBanForm, CommunityUpdateForm, }, instance::Instance, @@ -446,11 +467,12 @@ mod tests { person_block::{PersonBlock, PersonBlockForm}, post::{Post, PostInsertForm}, }, - traits::{Blockable, Crud, Joinable, Likeable, Saveable}, + traits::{Bannable, Blockable, Crud, Joinable, Likeable, Saveable}, utils::{build_db_pool_for_tests, RANK_DEFAULT}, CommunityVisibility, SubscribedType, }; + use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; use serial_test::serial; @@ -633,12 +655,12 @@ mod tests { #[tokio::test] #[serial] - async fn test_crud() { + async fn test_crud() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await; - let expected_comment_view_no_person = expected_comment_view(&data, pool).await; + let expected_comment_view_no_person = expected_comment_view(&data, pool).await?; let mut expected_comment_view_with_person = expected_comment_view_no_person.clone(); expected_comment_view_with_person.my_vote = Some(1); @@ -649,8 +671,7 @@ mod tests { ..Default::default() } .list(pool) - .await - .unwrap(); + .await?; assert_eq!( expected_comment_view_no_person, @@ -664,8 +685,7 @@ mod tests { ..Default::default() } .list(pool) - .await - .unwrap(); + .await?; assert_eq!( expected_comment_view_with_person, @@ -680,8 +700,7 @@ mod tests { data.inserted_comment_1.id, Some(data.timmy_local_user_view.person.id), ) - .await - .unwrap(); + .await?; // Make sure block set the creator blocked assert!(read_comment_from_blocked_person.creator_blocked); @@ -692,8 +711,7 @@ mod tests { ..Default::default() } .list(pool) - .await - .unwrap(); + .await?; assert_eq!( expected_comment_view_with_person, @@ -708,17 +726,16 @@ mod tests { ..Default::default() } .list(pool) - .await - .unwrap(); + .await?; assert!(read_disliked_comment_views.is_empty()); - cleanup(data, pool).await; + cleanup(data, pool).await } #[tokio::test] #[serial] - async fn test_comment_tree() { + async fn test_comment_tree() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await; @@ -730,8 +747,7 @@ mod tests { ..Default::default() } .list(pool) - .await - .unwrap(); + .await?; let child_path = data.inserted_comment_1.path.clone(); let read_comment_views_child_path = CommentQuery { @@ -740,8 +756,7 @@ mod tests { ..Default::default() } .list(pool) - .await - .unwrap(); + .await?; // Make sure the comment parent-limited fetch is correct assert_length!(6, read_comment_views_top_path); @@ -761,12 +776,11 @@ mod tests { ..Default::default() } .list(pool) - .await - .unwrap(); + .await?; // Make sure a depth limited one only has the top comment assert_eq!( - expected_comment_view(&data, pool).await, + expected_comment_view(&data, pool).await?, read_comment_views_top_max_depth[0] ); assert_length!(1, read_comment_views_top_max_depth); @@ -780,8 +794,7 @@ mod tests { ..Default::default() } .list(pool) - .await - .unwrap(); + .await?; // Make sure a depth limited one, and given child comment 1, has 3 assert!(read_comment_views_parent_max_depth[2] @@ -790,12 +803,12 @@ mod tests { .eq("Comment 3")); assert_length!(3, read_comment_views_parent_max_depth); - cleanup(data, pool).await; + cleanup(data, pool).await } #[tokio::test] #[serial] - async fn test_languages() { + async fn test_languages() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await; @@ -807,29 +820,25 @@ mod tests { ..Default::default() } .list(pool) - .await - .unwrap(); + .await?; assert_length!(5, all_languages); // change user lang to finnish, should only show one post in finnish and one undetermined let finnish_id = Language::read_id_from_code(pool, Some("fi")) - .await - .unwrap() + .await? .unwrap(); LocalUserLanguage::update( pool, vec![finnish_id], data.timmy_local_user_view.local_user.id, ) - .await - .unwrap(); + .await?; let finnish_comments = CommentQuery { local_user: (Some(&data.timmy_local_user_view)), ..Default::default() } .list(pool) - .await - .unwrap(); + .await?; assert_length!(2, finnish_comments); let finnish_comment = finnish_comments .iter() @@ -846,23 +855,21 @@ mod tests { vec![UNDETERMINED_ID], data.timmy_local_user_view.local_user.id, ) - .await - .unwrap(); + .await?; let undetermined_comment = CommentQuery { local_user: (Some(&data.timmy_local_user_view)), ..Default::default() } .list(pool) - .await - .unwrap(); + .await?; assert_length!(1, undetermined_comment); - cleanup(data, pool).await; + cleanup(data, pool).await } #[tokio::test] #[serial] - async fn test_distinguished_first() { + async fn test_distinguished_first() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await; @@ -871,26 +878,23 @@ mod tests { distinguished: Some(true), ..Default::default() }; - Comment::update(pool, data.inserted_comment_2.id, &form) - .await - .unwrap(); + Comment::update(pool, data.inserted_comment_2.id, &form).await?; let comments = CommentQuery { post_id: Some(data.inserted_comment_2.post_id), ..Default::default() } .list(pool) - .await - .unwrap(); + .await?; assert_eq!(comments[0].comment.id, data.inserted_comment_2.id); assert!(comments[0].comment.distinguished); - cleanup(data, pool).await; + cleanup(data, pool).await } #[tokio::test] #[serial] - async fn test_creator_is_moderator() { + async fn test_creator_is_moderator() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await; @@ -902,7 +906,7 @@ mod tests { community_id, person_id, }; - CommunityModerator::join(pool, &form).await.unwrap(); + CommunityModerator::join(pool, &form).await?; // Make sure that they come back as a mod in the list let comments = CommentQuery { @@ -910,19 +914,18 @@ mod tests { ..Default::default() } .list(pool) - .await - .unwrap(); + .await?; assert_eq!(comments[1].creator.name, "sara"); assert!(comments[1].creator_is_moderator); assert!(!comments[0].creator_is_moderator); - cleanup(data, pool).await; + cleanup(data, pool).await } #[tokio::test] #[serial] - async fn test_creator_is_admin() { + async fn test_creator_is_admin() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await; @@ -932,8 +935,7 @@ mod tests { ..Default::default() } .list(pool) - .await - .unwrap(); + .await?; // Timmy is an admin, and make sure that field is true assert_eq!(comments[0].creator.name, "timmy"); @@ -943,12 +945,12 @@ mod tests { assert_eq!(comments[1].creator.name, "sara"); assert!(!comments[1].creator_is_admin); - cleanup(data, pool).await; + cleanup(data, pool).await } #[tokio::test] #[serial] - async fn test_saved_order() { + async fn test_saved_order() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await; @@ -958,17 +960,13 @@ mod tests { person_id: data.timmy_local_user_view.person.id, comment_id: data.inserted_comment_0.id, }; - CommentSaved::save(pool, &save_comment_0_form) - .await - .unwrap(); + CommentSaved::save(pool, &save_comment_0_form).await?; let save_comment_2_form = CommentSavedForm { person_id: data.timmy_local_user_view.person.id, comment_id: data.inserted_comment_2.id, }; - CommentSaved::save(pool, &save_comment_2_form) - .await - .unwrap(); + CommentSaved::save(pool, &save_comment_2_form).await?; // Fetch the saved comments let comments = CommentQuery { @@ -977,8 +975,7 @@ mod tests { ..Default::default() } .list(pool) - .await - .unwrap(); + .await?; // There should only be two comments assert_eq!(2, comments.len()); @@ -989,47 +986,33 @@ mod tests { // The second comment, should be the first one saved assert_eq!(comments[1].comment.id, data.inserted_comment_0.id); - cleanup(data, pool).await; + cleanup(data, pool).await } - async fn cleanup(data: Data, pool: &mut DbPool<'_>) { + async fn cleanup(data: Data, pool: &mut DbPool<'_>) -> LemmyResult<()> { CommentLike::remove( pool, data.timmy_local_user_view.person.id, data.inserted_comment_0.id, ) - .await - .unwrap(); - Comment::delete(pool, data.inserted_comment_0.id) - .await - .unwrap(); - Comment::delete(pool, data.inserted_comment_1.id) - .await - .unwrap(); - Post::delete(pool, data.inserted_post.id).await.unwrap(); - Community::delete(pool, data.inserted_community.id) - .await - .unwrap(); - Person::delete(pool, data.timmy_local_user_view.person.id) - .await - .unwrap(); - LocalUser::delete(pool, data.timmy_local_user_view.local_user.id) - .await - .unwrap(); - Person::delete(pool, data.inserted_sara_person.id) - .await - .unwrap(); - Instance::delete(pool, data.inserted_instance.id) - .await - .unwrap(); + .await?; + Comment::delete(pool, data.inserted_comment_0.id).await?; + Comment::delete(pool, data.inserted_comment_1.id).await?; + Post::delete(pool, data.inserted_post.id).await?; + Community::delete(pool, data.inserted_community.id).await?; + Person::delete(pool, data.timmy_local_user_view.person.id).await?; + LocalUser::delete(pool, data.timmy_local_user_view.local_user.id).await?; + Person::delete(pool, data.inserted_sara_person.id).await?; + Instance::delete(pool, data.inserted_instance.id).await?; + + Ok(()) } - async fn expected_comment_view(data: &Data, pool: &mut DbPool<'_>) -> CommentView { - let agg = CommentAggregates::read(pool, data.inserted_comment_0.id) - .await - .unwrap(); - CommentView { + async fn expected_comment_view(data: &Data, pool: &mut DbPool<'_>) -> LemmyResult { + let agg = CommentAggregates::read(pool, data.inserted_comment_0.id).await?; + Ok(CommentView { creator_banned_from_community: false, + banned_from_community: false, creator_is_moderator: false, creator_is_admin: true, my_vote: None, @@ -1136,12 +1119,12 @@ mod tests { hot_rank: RANK_DEFAULT, controversy_rank: 0.0, }, - } + }) } #[tokio::test] #[serial] - async fn local_only_instance() { + async fn local_only_instance() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await; @@ -1154,15 +1137,13 @@ mod tests { ..Default::default() }, ) - .await - .unwrap(); + .await?; let unauthenticated_query = CommentQuery { ..Default::default() } .list(pool) - .await - .unwrap(); + .await?; assert_eq!(0, unauthenticated_query.len()); let authenticated_query = CommentQuery { @@ -1170,8 +1151,7 @@ mod tests { ..Default::default() } .list(pool) - .await - .unwrap(); + .await?; assert_eq!(5, authenticated_query.len()); let unauthenticated_comment = CommentView::read(pool, data.inserted_comment_0.id, None).await; @@ -1185,6 +1165,66 @@ mod tests { .await; assert!(authenticated_comment.is_ok()); - cleanup(data, pool).await; + cleanup(data, pool).await + } + + #[tokio::test] + #[serial] + async fn comment_listing_local_user_banned_from_community() -> LemmyResult<()> { + let pool = &build_db_pool_for_tests().await; + let pool = &mut pool.into(); + let data = init_data(pool).await; + + // Test that comment view shows if local user is blocked from community + let banned_from_comm_person = PersonInsertForm::test_form(data.inserted_instance.id, "jill"); + + let inserted_banned_from_comm_person = Person::create(pool, &banned_from_comm_person).await?; + + let inserted_banned_from_comm_local_user = LocalUser::create( + pool, + &LocalUserInsertForm::test_form(inserted_banned_from_comm_person.id), + ) + .await?; + + CommunityPersonBan::ban( + pool, + &CommunityPersonBanForm { + community_id: data.inserted_community.id, + person_id: inserted_banned_from_comm_person.id, + expires: None, + }, + ) + .await?; + + let comment_view = CommentView::read( + pool, + data.inserted_comment_0.id, + Some(inserted_banned_from_comm_local_user.person_id), + ) + .await?; + + assert!(comment_view.banned_from_community); + + Person::delete(pool, inserted_banned_from_comm_person.id).await?; + cleanup(data, pool).await + } + + #[tokio::test] + #[serial] + async fn comment_listing_local_user_not_banned_from_community() -> LemmyResult<()> { + let pool = &build_db_pool_for_tests().await; + let pool = &mut pool.into(); + let data = init_data(pool).await; + + let comment_view = CommentView::read( + pool, + data.inserted_comment_0.id, + Some(data.timmy_local_user_view.person.id), + ) + .await?; + + assert!(!comment_view.banned_from_community); + + cleanup(data, pool).await } } diff --git a/crates/db_views/src/custom_emoji_view.rs b/crates/db_views/src/custom_emoji_view.rs index d83fa9912..4d2f1fd85 100644 --- a/crates/db_views/src/custom_emoji_view.rs +++ b/crates/db_views/src/custom_emoji_view.rs @@ -77,7 +77,7 @@ impl CustomEmojiView { } for emoji in &mut result { if let Some(keywords) = hash.get_mut(&emoji.custom_emoji.id) { - emoji.keywords = keywords.clone(); + emoji.keywords.clone_from(keywords); } } result diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index b9522d47b..ae5ec383a 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -73,6 +73,17 @@ fn queries<'a>() -> Queries< .and(community_person_ban::person_id.eq(post_aggregates::creator_id)), ), ); + + let is_local_user_banned_from_community = |person_id| { + exists( + community_person_ban::table.filter( + post_aggregates::community_id + .eq(community_person_ban::community_id) + .and(community_person_ban::person_id.eq(person_id)), + ), + ) + }; + let creator_is_moderator = exists( community_moderator::table.filter( post_aggregates::community_id @@ -143,6 +154,14 @@ fn queries<'a>() -> Queries< let all_joins = move |query: post_aggregates::BoxedQuery<'a, Pg>, my_person_id: Option| { + let is_local_user_banned_from_community_selection: Box< + dyn BoxableExpression<_, Pg, SqlType = sql_types::Bool>, + > = if let Some(person_id) = my_person_id { + Box::new(is_local_user_banned_from_community(person_id)) + } else { + Box::new(false.into_sql::()) + }; + let is_saved_selection: Box< dyn BoxableExpression<_, Pg, SqlType = sql_types::Nullable>, > = if let Some(person_id) = my_person_id { @@ -223,6 +242,7 @@ fn queries<'a>() -> Queries< person::all_columns, community::all_columns, is_creator_banned_from_community, + is_local_user_banned_from_community_selection, creator_is_moderator, creator_is_admin, post_aggregates::all_columns, @@ -742,6 +762,8 @@ mod tests { CommunityInsertForm, CommunityModerator, CommunityModeratorForm, + CommunityPersonBan, + CommunityPersonBanForm, CommunityUpdateForm, }, community_block::{CommunityBlock, CommunityBlockForm}, @@ -755,7 +777,7 @@ mod tests { post::{Post, PostHide, PostInsertForm, PostLike, PostLikeForm, PostRead, PostUpdateForm}, site::Site, }, - traits::{Blockable, Crud, Joinable, Likeable}, + traits::{Bannable, Blockable, Crud, Joinable, Likeable}, utils::{build_db_pool, build_db_pool_for_tests, DbPool, RANK_DEFAULT}, CommunityVisibility, SortType, @@ -1604,6 +1626,7 @@ mod tests { last_refreshed_at: inserted_person.last_refreshed_at, }, creator_banned_from_community: false, + banned_from_community: false, creator_is_moderator: false, creator_is_admin: true, community: Community { @@ -1707,4 +1730,66 @@ mod tests { cleanup(data, pool).await?; Ok(()) } + + #[tokio::test] + #[serial] + async fn post_listing_local_user_banned_from_community() -> LemmyResult<()> { + let pool = &build_db_pool().await?; + let pool = &mut pool.into(); + let data = init_data(pool).await?; + + // Test that post view shows if local user is blocked from community + let banned_from_comm_person = PersonInsertForm::test_form(data.inserted_instance.id, "jill"); + + let inserted_banned_from_comm_person = Person::create(pool, &banned_from_comm_person).await?; + + let inserted_banned_from_comm_local_user = LocalUser::create( + pool, + &LocalUserInsertForm::test_form(inserted_banned_from_comm_person.id), + ) + .await?; + + CommunityPersonBan::ban( + pool, + &CommunityPersonBanForm { + community_id: data.inserted_community.id, + person_id: inserted_banned_from_comm_person.id, + expires: None, + }, + ) + .await?; + + let post_view = PostView::read( + pool, + data.inserted_post.id, + Some(inserted_banned_from_comm_local_user.person_id), + false, + ) + .await?; + + assert!(post_view.banned_from_community); + + Person::delete(pool, inserted_banned_from_comm_person.id).await?; + cleanup(data, pool).await + } + + #[tokio::test] + #[serial] + async fn post_listing_local_user_not_banned_from_community() -> LemmyResult<()> { + let pool = &build_db_pool().await?; + let pool = &mut pool.into(); + let data = init_data(pool).await?; + + let post_view = PostView::read( + pool, + data.inserted_post.id, + Some(data.local_user_view.person.id), + false, + ) + .await?; + + assert!(!post_view.banned_from_community); + + cleanup(data, pool).await + } } diff --git a/crates/db_views/src/structs.rs b/crates/db_views/src/structs.rs index 18fa7efa9..cfaee591d 100644 --- a/crates/db_views/src/structs.rs +++ b/crates/db_views/src/structs.rs @@ -64,6 +64,7 @@ pub struct CommentView { pub community: Community, pub counts: CommentAggregates, pub creator_banned_from_community: bool, + pub banned_from_community: bool, pub creator_is_moderator: bool, pub creator_is_admin: bool, pub subscribed: SubscribedType, @@ -129,6 +130,7 @@ pub struct PostView { pub creator: Person, pub community: Community, pub creator_banned_from_community: bool, + pub banned_from_community: bool, pub creator_is_moderator: bool, pub creator_is_admin: bool, pub counts: PostAggregates, From 6679b2559fdfa1d1d73cdccfbdb381a6204cb571 Mon Sep 17 00:00:00 2001 From: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com> Date: Fri, 22 Mar 2024 18:31:45 -0400 Subject: [PATCH 22/31] Add SleeplessOne1917 to CODEOWNERS (#4558) Co-authored-by: SleeplessOne1917 --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index cdf891126..06a92b09b 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,3 +1,3 @@ -* @Nutomic @dessalines @phiresky @dullbananas +* @Nutomic @dessalines @phiresky @dullbananas @SleeplessOne1917 crates/apub/ @Nutomic migrations/ @dessalines @phiresky @dullbananas From baf5921d2cc0aad43f9e96caf38aa50e1db78706 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Fri, 22 Mar 2024 23:40:08 +0100 Subject: [PATCH 23/31] Add comment about console feature requiring tokio_unstable (fixes #4553) (#4555) --- Cargo.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 66c3f9d47..366bdc353 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,6 +37,8 @@ debug = 0 [features] embed-pictrs = ["pict-rs"] +# This feature requires building with `tokio_unstable` flag, see documentation: +# https://docs.rs/tokio/latest/tokio/#unstable-features console = [ "console-subscriber", "opentelemetry", From 21547dedf768dca86bb864efcd884f62a337c6d3 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Fri, 22 Mar 2024 23:41:09 +0100 Subject: [PATCH 24/31] Fix handling of apub downvote (fixes #4545) (#4551) * Fix handling of apub downvote (fixes #4545) * fmt --------- Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com> --- crates/apub/src/activities/voting/vote.rs | 32 +++++++++++++---------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/crates/apub/src/activities/voting/vote.rs b/crates/apub/src/activities/voting/vote.rs index e15c3882b..5625ea6ba 100644 --- a/crates/apub/src/activities/voting/vote.rs +++ b/crates/apub/src/activities/voting/vote.rs @@ -2,7 +2,7 @@ use crate::{ activities::{ generate_activity_id, verify_person_in_community, - voting::{vote_comment, vote_post}, + voting::{undo_vote_comment, undo_vote_post, vote_comment, vote_post}, }, insert_received_activity, objects::{community::ApubCommunity, person::ApubPerson}, @@ -17,7 +17,6 @@ use activitypub_federation::{ fetch::object_id::ObjectId, traits::{ActivityHandler, Actor}, }; -use anyhow::anyhow; use lemmy_api_common::{context::LemmyContext, utils::check_bot_account}; use lemmy_db_schema::source::local_site::LocalSite; use lemmy_utils::error::LemmyError; @@ -58,15 +57,7 @@ impl ActivityHandler for Vote { async fn verify(&self, context: &Data) -> Result<(), LemmyError> { let community = self.community(context).await?; verify_person_in_community(&self.actor, &community, context).await?; - let enable_downvotes = LocalSite::read(&mut context.pool()) - .await - .map(|l| l.enable_downvotes) - .unwrap_or(true); - if self.kind == VoteType::Dislike && !enable_downvotes { - Err(anyhow!("Downvotes disabled").into()) - } else { - Ok(()) - } + Ok(()) } #[tracing::instrument(skip_all)] @@ -77,9 +68,22 @@ impl ActivityHandler for Vote { check_bot_account(&actor.0)?; - match object { - PostOrComment::Post(p) => vote_post(&self.kind, actor, &p, context).await, - PostOrComment::Comment(c) => vote_comment(&self.kind, actor, &c, context).await, + let enable_downvotes = LocalSite::read(&mut context.pool()) + .await + .map(|l| l.enable_downvotes) + .unwrap_or(true); + if self.kind == VoteType::Dislike && !enable_downvotes { + // If this is a downvote but downvotes are ignored, only undo any existing vote + match object { + PostOrComment::Post(p) => undo_vote_post(actor, &p, context).await, + PostOrComment::Comment(c) => undo_vote_comment(actor, &c, context).await, + } + } else { + // Otherwise apply the vote normally + match object { + PostOrComment::Post(p) => vote_post(&self.kind, actor, &p, context).await, + PostOrComment::Comment(c) => vote_comment(&self.kind, actor, &c, context).await, + } } } } From ef4bb3cc4032ea25e38f4c1972e39c8dc0ba4ca5 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Fri, 22 Mar 2024 23:41:59 +0100 Subject: [PATCH 25/31] Add delete user field `removeData` to apub assets (fixes #4544) (#4549) --- crates/apub/assets/lemmy/activities/deletion/delete_user.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/apub/assets/lemmy/activities/deletion/delete_user.json b/crates/apub/assets/lemmy/activities/deletion/delete_user.json index 7ef54c756..7a59b4694 100644 --- a/crates/apub/assets/lemmy/activities/deletion/delete_user.json +++ b/crates/apub/assets/lemmy/activities/deletion/delete_user.json @@ -3,5 +3,6 @@ "to": ["https://www.w3.org/ns/activitystreams#Public"], "object": "http://ds9.lemmy.ml/u/lemmy_alpha", "type": "Delete", - "id": "http://ds9.lemmy.ml/activities/delete/f2abee48-c7bb-41d5-9e27-8775ff32db12" + "id": "http://ds9.lemmy.ml/activities/delete/f2abee48-c7bb-41d5-9e27-8775ff32db12", + "removeData": true } From 99d01e186ada2bb3f5cf3fdc447e0cbc5dfae089 Mon Sep 17 00:00:00 2001 From: Sander Saarend Date: Mon, 25 Mar 2024 13:56:03 +0200 Subject: [PATCH 26/31] Fix rate limiter (#4560) --- crates/utils/src/rate_limit/rate_limiter.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/utils/src/rate_limit/rate_limiter.rs b/crates/utils/src/rate_limit/rate_limiter.rs index d452fcbb3..66d830c7e 100644 --- a/crates/utils/src/rate_limit/rate_limiter.rs +++ b/crates/utils/src/rate_limit/rate_limiter.rs @@ -158,7 +158,7 @@ impl MapLevel for Map { // Evaluated if `some_children_remaining` is false let total_has_refill_in_future = || { - group.total.into_iter().all(|(action_type, bucket)| { + group.total.into_iter().any(|(action_type, bucket)| { #[allow(clippy::indexing_slicing)] let config = configs[action_type]; bucket.update(now, config).tokens != config.capacity @@ -416,5 +416,23 @@ mod tests { rate_limiter.remove_full_buckets(now); assert!(rate_limiter.ipv4_buckets.is_empty()); assert!(rate_limiter.ipv6_buckets.is_empty()); + + // `remove full buckets` should not remove empty buckets + let ip = "1.1.1.1".parse().unwrap(); + // empty the bucket with 2 requests + assert!(rate_limiter.check(ActionType::Post, ip, now)); + assert!(rate_limiter.check(ActionType::Post, ip, now)); + + rate_limiter.remove_full_buckets(now); + assert!(!rate_limiter.ipv4_buckets.is_empty()); + + // `remove full buckets` should not remove partial buckets + now.secs += 2; + let ip = "1.1.1.1".parse().unwrap(); + // Only make one request, so bucket still has 1 token + assert!(rate_limiter.check(ActionType::Post, ip, now)); + + rate_limiter.remove_full_buckets(now); + assert!(!rate_limiter.ipv4_buckets.is_empty()); } } From d06ef2c47e9b596fa4bce6b2d1576d76bfee6fef Mon Sep 17 00:00:00 2001 From: Nutomic Date: Mon, 25 Mar 2024 13:10:09 +0100 Subject: [PATCH 27/31] Migrate apub block activity to standard `endTime` property and deprecate `expires` (fixes #2316) (#4541) * Migrate apub block activity to standard `endTime` property (fixes #2316) * add todo --- crates/apub/src/activities/block/block_user.rs | 3 ++- crates/apub/src/activities/block/undo_block_user.rs | 2 +- crates/apub/src/protocol/activities/block/block_user.rs | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/apub/src/activities/block/block_user.rs b/crates/apub/src/activities/block/block_user.rs index 177df2ca5..a2a1f25bf 100644 --- a/crates/apub/src/activities/block/block_user.rs +++ b/crates/apub/src/activities/block/block_user.rs @@ -72,6 +72,7 @@ impl BlockUser { )?, audience, expires, + end_time: expires, }) } @@ -149,7 +150,7 @@ impl ActivityHandler for BlockUser { #[tracing::instrument(skip_all)] async fn receive(self, context: &Data) -> Result<(), LemmyError> { insert_received_activity(&self.id, context).await?; - let expires = self.expires.map(Into::into); + let expires = self.expires.or(self.end_time).map(Into::into); let mod_person = self.actor.dereference(context).await?; let blocked_person = self.object.dereference(context).await?; let target = self.target.dereference(context).await?; diff --git a/crates/apub/src/activities/block/undo_block_user.rs b/crates/apub/src/activities/block/undo_block_user.rs index da25a4af0..756d0a149 100644 --- a/crates/apub/src/activities/block/undo_block_user.rs +++ b/crates/apub/src/activities/block/undo_block_user.rs @@ -98,7 +98,7 @@ impl ActivityHandler for UndoBlockUser { #[tracing::instrument(skip_all)] async fn receive(self, context: &Data) -> Result<(), LemmyError> { insert_received_activity(&self.id, context).await?; - let expires = self.object.expires.map(Into::into); + let expires = self.object.expires.or(self.object.end_time).map(Into::into); let mod_person = self.actor.dereference(context).await?; let blocked_person = self.object.object.dereference(context).await?; match self.object.target.dereference(context).await? { diff --git a/crates/apub/src/protocol/activities/block/block_user.rs b/crates/apub/src/protocol/activities/block/block_user.rs index b958b58e1..c5cb4306c 100644 --- a/crates/apub/src/protocol/activities/block/block_user.rs +++ b/crates/apub/src/protocol/activities/block/block_user.rs @@ -38,7 +38,9 @@ pub struct BlockUser { pub(crate) remove_data: Option, /// block reason, written to mod log pub(crate) summary: Option, + /// TODO: deprecated pub(crate) expires: Option>, + pub(crate) end_time: Option>, } #[async_trait::async_trait] From 846848c4f6a5ab0ebce9c513f62ff0074b27f50c Mon Sep 17 00:00:00 2001 From: Nutomic Date: Mon, 25 Mar 2024 21:02:12 +0100 Subject: [PATCH 28/31] On registration, automatically set content languages from `accept-language` header (#4550) * On registration, automatically set content languages from accept header * no need to set site language or default language for new user anymore * fix test * fix langs * avoid duplicate writing of new user languages --- api_tests/src/user.spec.ts | 20 ++++ .../src/local_user/generate_totp_secret.rs | 5 +- crates/api/src/local_user/update_totp.rs | 5 +- crates/api_common/src/claims.rs | 4 +- crates/api_crud/src/user/create.rs | 32 ++++-- crates/apub/src/api/user_settings_backup.rs | 2 +- crates/db_schema/src/impls/actor_language.rs | 19 ++-- crates/db_schema/src/impls/local_user.rs | 100 +++++++++--------- .../src/impls/password_reset_request.rs | 4 +- crates/db_views/src/comment_report_view.rs | 4 +- crates/db_views/src/comment_view.rs | 2 +- crates/db_views/src/post_report_view.rs | 4 +- crates/db_views/src/post_view.rs | 3 +- .../src/registration_application_view.rs | 6 +- crates/db_views_actor/src/community_view.rs | 4 +- crates/db_views_actor/src/person_view.rs | 4 +- src/code_migrations.rs | 2 +- src/session_middleware.rs | 4 +- 18 files changed, 130 insertions(+), 94 deletions(-) diff --git a/api_tests/src/user.spec.ts b/api_tests/src/user.spec.ts index 4846d60f7..73f3f3942 100644 --- a/api_tests/src/user.spec.ts +++ b/api_tests/src/user.spec.ts @@ -139,3 +139,23 @@ test("Create user with Arabic name", async () => { let alphaPerson = (await resolvePerson(alpha, apShortname)).person; expect(alphaPerson).toBeDefined(); }); + +test("Create user with accept-language", async () => { + let lemmy_http = new LemmyHttp(alphaUrl, { + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language#syntax + headers: { "Accept-Language": "fr-CH, en;q=0.8, de;q=0.7, *;q=0.5" }, + }); + let user = await registerUser(lemmy_http, alphaUrl); + + let site = await getSite(user); + expect(site.my_user).toBeDefined(); + expect(site.my_user?.local_user_view.local_user.interface_language).toBe( + "fr", + ); + let langs = site.all_languages + .filter(a => site.my_user?.discussion_languages.includes(a.id)) + .map(l => l.code); + // should have languages from accept header, as well as "undetermined" + // which is automatically enabled by backend + expect(langs).toStrictEqual(["und", "de", "en", "fr"]); +}); diff --git a/crates/api/src/local_user/generate_totp_secret.rs b/crates/api/src/local_user/generate_totp_secret.rs index a983beaaa..342a90a78 100644 --- a/crates/api/src/local_user/generate_totp_secret.rs +++ b/crates/api/src/local_user/generate_totp_secret.rs @@ -6,10 +6,7 @@ use lemmy_api_common::{ person::GenerateTotpSecretResponse, sensitive::Sensitive, }; -use lemmy_db_schema::{ - source::local_user::{LocalUser, LocalUserUpdateForm}, - traits::Crud, -}; +use lemmy_db_schema::source::local_user::{LocalUser, LocalUserUpdateForm}; use lemmy_db_views::structs::{LocalUserView, SiteView}; use lemmy_utils::error::{LemmyError, LemmyErrorType}; diff --git a/crates/api/src/local_user/update_totp.rs b/crates/api/src/local_user/update_totp.rs index 8f37213e2..c8ca9f64e 100644 --- a/crates/api/src/local_user/update_totp.rs +++ b/crates/api/src/local_user/update_totp.rs @@ -4,10 +4,7 @@ use lemmy_api_common::{ context::LemmyContext, person::{UpdateTotp, UpdateTotpResponse}, }; -use lemmy_db_schema::{ - source::local_user::{LocalUser, LocalUserUpdateForm}, - traits::Crud, -}; +use lemmy_db_schema::source::local_user::{LocalUser, LocalUserUpdateForm}; use lemmy_db_views::structs::LocalUserView; use lemmy_utils::error::LemmyError; diff --git a/crates/api_common/src/claims.rs b/crates/api_common/src/claims.rs index 0a96f7455..0e6968742 100644 --- a/crates/api_common/src/claims.rs +++ b/crates/api_common/src/claims.rs @@ -124,7 +124,9 @@ mod tests { .password_encrypted("123456".to_string()) .build(); - let inserted_local_user = LocalUser::create(pool, &local_user_form).await.unwrap(); + let inserted_local_user = LocalUser::create(pool, &local_user_form, vec![]) + .await + .unwrap(); let req = TestRequest::default().to_http_request(); let jwt = Claims::generate(inserted_local_user.id, req, &context) diff --git a/crates/api_crud/src/user/create.rs b/crates/api_crud/src/user/create.rs index 29e16cb20..d24a287db 100644 --- a/crates/api_crud/src/user/create.rs +++ b/crates/api_crud/src/user/create.rs @@ -20,6 +20,7 @@ use lemmy_db_schema::{ aggregates::structs::PersonAggregates, source::{ captcha_answer::{CaptchaAnswer, CheckCaptchaAnswer}, + language::Language, local_user::{LocalUser, LocalUserInsertForm}, local_user_vote_display_mode::LocalUserVoteDisplayMode, person::{Person, PersonInsertForm}, @@ -36,6 +37,7 @@ use lemmy_utils::{ validation::is_valid_actor_name, }, }; +use std::collections::HashSet; #[tracing::instrument(skip(context))] pub async fn register( @@ -128,12 +130,15 @@ pub async fn register( let accepted_application = Some(!require_registration_application); // Get the user's preferred language using the Accept-Language header - let language_tag = req.headers().get("Accept-Language").and_then(|hdr| { - accept_language::parse(hdr.to_str().unwrap_or_default()) - .first() - // Remove the optional region code - .map(|lang_str| lang_str.split('-').next().unwrap_or_default().to_string()) - }); + let language_tags: Vec = req + .headers() + .get("Accept-Language") + .map(|hdr| accept_language::parse(hdr.to_str().unwrap_or_default())) + .iter() + .flatten() + // Remove the optional region code + .map(|lang_str| lang_str.split('-').next().unwrap_or_default().to_string()) + .collect(); // Create the local user let local_user_form = LocalUserInsertForm::builder() @@ -144,12 +149,23 @@ pub async fn register( .accepted_application(accepted_application) .default_listing_type(Some(local_site.default_post_listing_type)) .post_listing_mode(Some(local_site.default_post_listing_mode)) - .interface_language(language_tag) + .interface_language(language_tags.first().cloned()) // If its the initial site setup, they are an admin .admin(Some(!local_site.site_setup)) .build(); - let inserted_local_user = LocalUser::create(&mut context.pool(), &local_user_form).await?; + let all_languages = Language::read_all(&mut context.pool()).await?; + // use hashset to avoid duplicates + let mut language_ids = HashSet::new(); + for l in language_tags { + if let Some(found) = all_languages.iter().find(|all| all.code == l) { + language_ids.insert(found.id); + } + } + let language_ids = language_ids.into_iter().collect(); + + let inserted_local_user = + LocalUser::create(&mut context.pool(), &local_user_form, language_ids).await?; if local_site.site_setup && require_registration_application { // Create the registration application diff --git a/crates/apub/src/api/user_settings_backup.rs b/crates/apub/src/api/user_settings_backup.rs index a2e6c55ac..d46e415b0 100644 --- a/crates/apub/src/api/user_settings_backup.rs +++ b/crates/apub/src/api/user_settings_backup.rs @@ -361,7 +361,7 @@ mod tests { .person_id(person.id) .password_encrypted("pass".to_string()) .build(); - let local_user = LocalUser::create(&mut context.pool(), &user_form).await?; + let local_user = LocalUser::create(&mut context.pool(), &user_form, vec![]).await?; Ok(LocalUserView::read(&mut context.pool(), local_user.id).await?) } diff --git a/crates/db_schema/src/impls/actor_language.rs b/crates/db_schema/src/impls/actor_language.rs index 1cb5f4c77..29d99b2d8 100644 --- a/crates/db_schema/src/impls/actor_language.rs +++ b/crates/db_schema/src/impls/actor_language.rs @@ -523,10 +523,6 @@ mod tests { let pool = &mut pool.into(); let (site, instance) = create_test_site(pool).await; - let mut test_langs = test_langs1(pool).await; - SiteLanguage::update(pool, test_langs.clone(), &site) - .await - .unwrap(); let person_form = PersonInsertForm::builder() .name("my test person".to_string()) @@ -539,14 +535,13 @@ mod tests { .password_encrypted("my_pw".to_string()) .build(); - let local_user = LocalUser::create(pool, &local_user_form).await.unwrap(); + let local_user = LocalUser::create(pool, &local_user_form, vec![]) + .await + .unwrap(); let local_user_langs1 = LocalUserLanguage::read(pool, local_user.id).await.unwrap(); - // new user should be initialized with site languages and undetermined - //test_langs.push(UNDETERMINED_ID); - //test_langs.sort(); - test_langs.insert(0, UNDETERMINED_ID); - assert_eq!(test_langs, local_user_langs1); + // new user should be initialized with all languages + assert_eq!(0, local_user_langs1.len()); // update user languages let test_langs2 = test_langs2(pool).await; @@ -655,7 +650,9 @@ mod tests { .person_id(person.id) .password_encrypted("my_pw".to_string()) .build(); - let local_user = LocalUser::create(pool, &local_user_form).await.unwrap(); + let local_user = LocalUser::create(pool, &local_user_form, vec![]) + .await + .unwrap(); LocalUserLanguage::update(pool, test_langs2, local_user.id) .await .unwrap(); diff --git a/crates/db_schema/src/impls/local_user.rs b/crates/db_schema/src/impls/local_user.rs index 14ae65469..d253afd8d 100644 --- a/crates/db_schema/src/impls/local_user.rs +++ b/crates/db_schema/src/impls/local_user.rs @@ -1,12 +1,11 @@ use crate::{ - newtypes::{DbUrl, LocalUserId, PersonId}, + newtypes::{DbUrl, LanguageId, LocalUserId, PersonId}, schema::{local_user, person, registration_application}, source::{ - actor_language::{LocalUserLanguage, SiteLanguage}, + actor_language::LocalUserLanguage, local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm}, local_user_vote_display_mode::{LocalUserVoteDisplayMode, LocalUserVoteDisplayModeInsertForm}, }, - traits::Crud, utils::{ functions::{coalesce, lower}, get_conn, @@ -25,6 +24,52 @@ use diesel::{ use diesel_async::RunQueryDsl; impl LocalUser { + pub async fn create( + pool: &mut DbPool<'_>, + form: &LocalUserInsertForm, + languages: Vec, + ) -> Result { + let conn = &mut get_conn(pool).await?; + let mut form_with_encrypted_password = form.clone(); + let password_hash = + hash(&form.password_encrypted, DEFAULT_COST).expect("Couldn't hash password"); + form_with_encrypted_password.password_encrypted = password_hash; + + let local_user_ = insert_into(local_user::table) + .values(form_with_encrypted_password) + .get_result::(conn) + .await?; + + LocalUserLanguage::update(pool, languages, local_user_.id).await?; + + // Create their vote_display_modes + let vote_display_mode_form = LocalUserVoteDisplayModeInsertForm::builder() + .local_user_id(local_user_.id) + .build(); + LocalUserVoteDisplayMode::create(pool, &vote_display_mode_form).await?; + + Ok(local_user_) + } + + pub async fn update( + pool: &mut DbPool<'_>, + local_user_id: LocalUserId, + form: &LocalUserUpdateForm, + ) -> Result { + let conn = &mut get_conn(pool).await?; + diesel::update(local_user::table.find(local_user_id)) + .set(form) + .get_result::(conn) + .await + } + + pub async fn delete(pool: &mut DbPool<'_>, id: LocalUserId) -> Result { + let conn = &mut *get_conn(pool).await?; + diesel::delete(local_user::table.find(id)) + .execute(conn) + .await + } + pub async fn update_password( pool: &mut DbPool<'_>, local_user_id: LocalUserId, @@ -183,52 +228,3 @@ pub struct UserBackupLists { pub blocked_users: Vec, pub blocked_instances: Vec, } - -#[async_trait] -impl Crud for LocalUser { - type InsertForm = LocalUserInsertForm; - type UpdateForm = LocalUserUpdateForm; - type IdType = LocalUserId; - - async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result { - let conn = &mut get_conn(pool).await?; - let mut form_with_encrypted_password = form.clone(); - let password_hash = - hash(&form.password_encrypted, DEFAULT_COST).expect("Couldn't hash password"); - form_with_encrypted_password.password_encrypted = password_hash; - - let local_user_ = insert_into(local_user::table) - .values(form_with_encrypted_password) - .get_result::(conn) - .await?; - - let site_languages = SiteLanguage::read_local_raw(pool).await; - if let Ok(langs) = site_languages { - // if site exists, init user with site languages - LocalUserLanguage::update(pool, langs, local_user_.id).await?; - } else { - // otherwise, init with all languages (this only happens during tests and - // for first admin user, which is created before site) - LocalUserLanguage::update(pool, vec![], local_user_.id).await?; - } - - // Create their vote_display_modes - let vote_display_mode_form = LocalUserVoteDisplayModeInsertForm::builder() - .local_user_id(local_user_.id) - .build(); - LocalUserVoteDisplayMode::create(pool, &vote_display_mode_form).await?; - - Ok(local_user_) - } - async fn update( - pool: &mut DbPool<'_>, - local_user_id: LocalUserId, - form: &Self::UpdateForm, - ) -> Result { - let conn = &mut get_conn(pool).await?; - diesel::update(local_user::table.find(local_user_id)) - .set(form) - .get_result::(conn) - .await - } -} diff --git a/crates/db_schema/src/impls/password_reset_request.rs b/crates/db_schema/src/impls/password_reset_request.rs index 6fcf86014..3b910b1d3 100644 --- a/crates/db_schema/src/impls/password_reset_request.rs +++ b/crates/db_schema/src/impls/password_reset_request.rs @@ -121,7 +121,9 @@ mod tests { .password_encrypted("pass".to_string()) .build(); - let inserted_local_user = LocalUser::create(pool, &new_local_user).await.unwrap(); + let inserted_local_user = LocalUser::create(pool, &new_local_user, vec![]) + .await + .unwrap(); let token = "nope"; diff --git a/crates/db_views/src/comment_report_view.rs b/crates/db_views/src/comment_report_view.rs index 1aa3bb6e7..317ebf29a 100644 --- a/crates/db_views/src/comment_report_view.rs +++ b/crates/db_views/src/comment_report_view.rs @@ -308,7 +308,9 @@ mod tests { .person_id(inserted_timmy.id) .password_encrypted("123".to_string()) .build(); - let timmy_local_user = LocalUser::create(pool, &new_local_user).await.unwrap(); + let timmy_local_user = LocalUser::create(pool, &new_local_user, vec![]) + .await + .unwrap(); let timmy_view = LocalUserView { local_user: timmy_local_user, local_user_vote_display_mode: LocalUserVoteDisplayMode::default(), diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index 5f811cb0d..d80cc2e58 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -503,7 +503,7 @@ mod tests { .admin(Some(true)) .password_encrypted(String::new()) .build(); - let inserted_timmy_local_user = LocalUser::create(pool, &timmy_local_user_form) + let inserted_timmy_local_user = LocalUser::create(pool, &timmy_local_user_form, vec![]) .await .unwrap(); diff --git a/crates/db_views/src/post_report_view.rs b/crates/db_views/src/post_report_view.rs index 0f1f3639c..20795c8c0 100644 --- a/crates/db_views/src/post_report_view.rs +++ b/crates/db_views/src/post_report_view.rs @@ -330,7 +330,9 @@ mod tests { .person_id(inserted_timmy.id) .password_encrypted("123".to_string()) .build(); - let timmy_local_user = LocalUser::create(pool, &new_local_user).await.unwrap(); + let timmy_local_user = LocalUser::create(pool, &new_local_user, vec![]) + .await + .unwrap(); let timmy_view = LocalUserView { local_user: timmy_local_user, local_user_vote_display_mode: LocalUserVoteDisplayMode::default(), diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index ae5ec383a..e1891b37a 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -829,7 +829,7 @@ mod tests { admin: Some(true), ..LocalUserInsertForm::test_form(inserted_person.id) }; - let inserted_local_user = LocalUser::create(pool, &local_user_form).await?; + let inserted_local_user = LocalUser::create(pool, &local_user_form, vec![]).await?; let new_bot = PersonInsertForm { bot_account: Some(true), @@ -855,6 +855,7 @@ mod tests { let inserted_blocked_local_user = LocalUser::create( pool, &LocalUserInsertForm::test_form(inserted_blocked_person.id), + vec![], ) .await?; diff --git a/crates/db_views/src/registration_application_view.rs b/crates/db_views/src/registration_application_view.rs index a59158318..c2f2e3120 100644 --- a/crates/db_views/src/registration_application_view.rs +++ b/crates/db_views/src/registration_application_view.rs @@ -176,7 +176,7 @@ mod tests { .admin(Some(true)) .build(); - let _inserted_timmy_local_user = LocalUser::create(pool, &timmy_local_user_form) + let _inserted_timmy_local_user = LocalUser::create(pool, &timmy_local_user_form, vec![]) .await .unwrap(); @@ -193,7 +193,7 @@ mod tests { .password_encrypted("nada".to_string()) .build(); - let inserted_sara_local_user = LocalUser::create(pool, &sara_local_user_form) + let inserted_sara_local_user = LocalUser::create(pool, &sara_local_user_form, vec![]) .await .unwrap(); @@ -224,7 +224,7 @@ mod tests { .password_encrypted("nada".to_string()) .build(); - let inserted_jess_local_user = LocalUser::create(pool, &jess_local_user_form) + let inserted_jess_local_user = LocalUser::create(pool, &jess_local_user_form, vec![]) .await .unwrap(); diff --git a/crates/db_views_actor/src/community_view.rs b/crates/db_views_actor/src/community_view.rs index c1cb6eee1..98a146c15 100644 --- a/crates/db_views_actor/src/community_view.rs +++ b/crates/db_views_actor/src/community_view.rs @@ -296,7 +296,9 @@ mod tests { .person_id(inserted_person.id) .password_encrypted(String::new()) .build(); - let local_user = LocalUser::create(pool, &local_user_form).await.unwrap(); + let local_user = LocalUser::create(pool, &local_user_form, vec![]) + .await + .unwrap(); let new_community = CommunityInsertForm::builder() .name("test_community_3".to_string()) diff --git a/crates/db_views_actor/src/person_view.rs b/crates/db_views_actor/src/person_view.rs index aee56748e..1ee51a819 100644 --- a/crates/db_views_actor/src/person_view.rs +++ b/crates/db_views_actor/src/person_view.rs @@ -204,7 +204,7 @@ mod tests { .person_id(alice.id) .password_encrypted(String::new()) .build(); - let alice_local_user = LocalUser::create(pool, &alice_local_user_form).await?; + let alice_local_user = LocalUser::create(pool, &alice_local_user_form, vec![]).await?; let bob_form = PersonInsertForm::builder() .name("bob".to_string()) @@ -218,7 +218,7 @@ mod tests { .person_id(bob.id) .password_encrypted(String::new()) .build(); - let bob_local_user = LocalUser::create(pool, &bob_local_user_form).await?; + let bob_local_user = LocalUser::create(pool, &bob_local_user_form, vec![]).await?; Ok(Data { alice, diff --git a/src/code_migrations.rs b/src/code_migrations.rs index 8e17b8a8c..cee02075c 100644 --- a/src/code_migrations.rs +++ b/src/code_migrations.rs @@ -475,7 +475,7 @@ async fn initialize_local_site_2022_10_10( .email(setup.admin_email.clone()) .admin(Some(true)) .build(); - LocalUser::create(pool, &local_user_form).await?; + LocalUser::create(pool, &local_user_form, vec![]).await?; }; // Add an entry for the site table diff --git a/src/session_middleware.rs b/src/session_middleware.rs index 2c4e36913..474709dbe 100644 --- a/src/session_middleware.rs +++ b/src/session_middleware.rs @@ -155,7 +155,9 @@ mod tests { .password_encrypted("123456".to_string()) .build(); - let inserted_local_user = LocalUser::create(pool, &local_user_form).await.unwrap(); + let inserted_local_user = LocalUser::create(pool, &local_user_form, vec![]) + .await + .unwrap(); let req = TestRequest::default().to_http_request(); let jwt = Claims::generate(inserted_local_user.id, req, &context) From e4356a770176dc856d8ab03330911d48de8cc3b3 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 25 Mar 2024 19:14:35 -0400 Subject: [PATCH 29/31] Fixing a few broken tests from the change in LocalUser::create (#4569) --- crates/db_views/src/comment_view.rs | 1 + crates/db_views/src/post_view.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index d80cc2e58..f8e91b501 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -1183,6 +1183,7 @@ mod tests { let inserted_banned_from_comm_local_user = LocalUser::create( pool, &LocalUserInsertForm::test_form(inserted_banned_from_comm_person.id), + vec![], ) .await?; diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index e1891b37a..b323437d5 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -1747,6 +1747,7 @@ mod tests { let inserted_banned_from_comm_local_user = LocalUser::create( pool, &LocalUserInsertForm::test_form(inserted_banned_from_comm_person.id), + vec![], ) .await?; From 95069d7648afd0cc0abd8990d9581c948536072c Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 26 Mar 2024 05:17:42 -0400 Subject: [PATCH 30/31] Fixing some clippy and woodpecker lints. (#4565) * Fixing some clippy and woodpecker lints. * Try fixing woodpecker 1. * Revert "Try fixing woodpecker 1." This reverts commit 7c2020a08d7b72b179b23cf7c56c1d9fcdcb2a6e. --- .woodpecker.yml | 44 ++++++++++--------- crates/api/src/lib.rs | 4 +- crates/api/src/sitemap.rs | 2 +- crates/api_common/src/claims.rs | 4 +- crates/api_common/src/request.rs | 4 +- crates/api_common/src/utils.rs | 4 +- crates/api_crud/src/site/create.rs | 4 +- crates/api_crud/src/site/mod.rs | 4 +- crates/api_crud/src/site/update.rs | 4 +- crates/apub/src/activity_lists.rs | 2 +- crates/apub/src/api/user_settings_backup.rs | 2 +- .../src/collections/community_moderators.rs | 2 +- crates/apub/src/http/community.rs | 4 +- .../src/aggregates/comment_aggregates.rs | 4 +- .../src/aggregates/community_aggregates.rs | 4 +- .../src/aggregates/person_aggregates.rs | 4 +- .../src/aggregates/post_aggregates.rs | 4 +- .../src/aggregates/site_aggregates.rs | 4 +- crates/db_schema/src/impls/activity.rs | 4 +- crates/db_schema/src/impls/actor_language.rs | 4 +- crates/db_schema/src/impls/captcha_answer.rs | 4 +- crates/db_schema/src/impls/comment.rs | 4 +- crates/db_schema/src/impls/comment_reply.rs | 4 +- crates/db_schema/src/impls/community.rs | 4 +- .../src/impls/federation_allowlist.rs | 4 +- crates/db_schema/src/impls/language.rs | 4 +- crates/db_schema/src/impls/moderator.rs | 4 +- .../src/impls/password_reset_request.rs | 4 +- crates/db_schema/src/impls/person.rs | 4 +- crates/db_schema/src/impls/person_mention.rs | 4 +- crates/db_schema/src/impls/post.rs | 4 +- crates/db_schema/src/impls/post_report.rs | 4 +- crates/db_schema/src/impls/private_message.rs | 4 +- crates/db_schema/src/utils.rs | 4 +- crates/db_views/src/comment_report_view.rs | 4 +- crates/db_views/src/comment_view.rs | 4 +- crates/db_views/src/post_report_view.rs | 4 +- .../src/private_message_report_view.rs | 4 +- crates/db_views/src/private_message_view.rs | 4 +- .../src/registration_application_view.rs | 4 +- crates/db_views/src/vote_view.rs | 4 +- crates/db_views_actor/src/community_view.rs | 4 +- crates/db_views_actor/src/person_view.rs | 4 +- crates/utils/src/rate_limit/mod.rs | 4 +- crates/utils/src/rate_limit/rate_limiter.rs | 4 +- crates/utils/src/utils/markdown/mod.rs | 4 +- .../utils/src/utils/markdown/spoiler_rule.rs | 4 +- crates/utils/src/utils/mention.rs | 4 +- crates/utils/src/utils/slurs.rs | 4 +- crates/utils/src/utils/validation.rs | 4 +- src/scheduled_tasks.rs | 4 +- src/session_middleware.rs | 4 +- 52 files changed, 121 insertions(+), 119 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index a1f008bd0..ab38db329 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -6,21 +6,23 @@ variables: - &install_pnpm "corepack enable pnpm" - &slow_check_paths - path: - # rust source code - - "crates/**" - - "src/**" - - "**/Cargo.toml" - - "Cargo.lock" - # database migrations - - "migrations/**" - # typescript tests - - "api_tests/**" - # config files and scripts used by ci - - ".woodpecker.yml" - - ".rustfmt.toml" - - "scripts/update_config_defaults.sh" - - "diesel.toml" - - ".gitmodules" + include: [ + # rust source code + "crates/**", + "src/**", + "**/Cargo.toml", + "Cargo.lock", + # database migrations + "migrations/**", + # typescript tests + "api_tests/**", + # config files and scripts used by ci + ".woodpecker.yml", + ".rustfmt.toml", + "scripts/update_config_defaults.sh", + "diesel.toml", + ".gitmodules", + ] # Broken for cron jobs currently, see # https://github.com/woodpecker-ci/woodpecker/issues/1716 @@ -198,7 +200,7 @@ steps: - cat target/log/lemmy_*.out || true - "# If you can't see all output, then use the download button" when: - status: [failure] + - status: [failure] publish_release_docker: image: woodpeckerci/plugin-docker-buildx @@ -211,7 +213,7 @@ steps: - RUST_RELEASE_MODE=release tag: ${CI_COMMIT_TAG} when: - event: tag + - event: tag nightly_build: image: woodpeckerci/plugin-docker-buildx @@ -224,7 +226,7 @@ steps: - RUST_RELEASE_MODE=release tag: dev when: - event: cron + - event: cron # using https://github.com/pksunkara/cargo-workspaces publish_to_crates_io: @@ -237,7 +239,7 @@ steps: - cargo workspaces publish --from-git --allow-dirty --no-verify --allow-branch "${CI_COMMIT_TAG}" --yes custom "${CI_COMMIT_TAG}" secrets: [cargo_api_token] when: - event: tag + - event: tag notify_on_failure: image: alpine:3 @@ -245,7 +247,7 @@ steps: - apk add curl - "curl -d'Lemmy CI build failed: ${CI_PIPELINE_URL}' ntfy.sh/lemmy_drone_ci" when: - status: [failure] + - status: [failure] notify_on_tag_deploy: image: alpine:3 @@ -253,7 +255,7 @@ steps: - apk add curl - "curl -d'lemmy:${CI_COMMIT_TAG} deployed' ntfy.sh/lemmy_drone_ci" when: - event: tag + - event: tag services: database: diff --git a/crates/api/src/lib.rs b/crates/api/src/lib.rs index 814dd67eb..d65ae0a28 100644 --- a/crates/api/src/lib.rs +++ b/crates/api/src/lib.rs @@ -259,9 +259,9 @@ pub async fn local_user_view_from_jwt( } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use super::*; diff --git a/crates/api/src/sitemap.rs b/crates/api/src/sitemap.rs index ec32f837f..bd0e0dad8 100644 --- a/crates/api/src/sitemap.rs +++ b/crates/api/src/sitemap.rs @@ -42,8 +42,8 @@ pub async fn get_sitemap(context: Data) -> LemmyResult Resu } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::{ context::LemmyContext, diff --git a/crates/api_common/src/utils.rs b/crates/api_common/src/utils.rs index b13d21f9f..e4ab91b08 100644 --- a/crates/api_common/src/utils.rs +++ b/crates/api_common/src/utils.rs @@ -1019,9 +1019,9 @@ pub async fn proxy_image_link_opt_apub( } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use super::*; use pretty_assertions::assert_eq; diff --git a/crates/api_crud/src/site/create.rs b/crates/api_crud/src/site/create.rs index 76aae405e..8542117e7 100644 --- a/crates/api_crud/src/site/create.rs +++ b/crates/api_crud/src/site/create.rs @@ -189,9 +189,9 @@ fn validate_create_payload(local_site: &LocalSite, create_site: &CreateSite) -> } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::site::create::validate_create_payload; use lemmy_api_common::site::CreateSite; diff --git a/crates/api_crud/src/site/mod.rs b/crates/api_crud/src/site/mod.rs index e4911ba48..0bf7cc279 100644 --- a/crates/api_crud/src/site/mod.rs +++ b/crates/api_crud/src/site/mod.rs @@ -41,9 +41,9 @@ pub fn application_question_check( } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::site::{application_question_check, site_default_post_listing_type_check}; use lemmy_db_schema::{ListingType, RegistrationMode}; diff --git a/crates/api_crud/src/site/update.rs b/crates/api_crud/src/site/update.rs index 809dbe498..6d419a6d8 100644 --- a/crates/api_crud/src/site/update.rs +++ b/crates/api_crud/src/site/update.rs @@ -231,9 +231,9 @@ fn validate_update_payload(local_site: &LocalSite, edit_site: &EditSite) -> Lemm } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::site::update::validate_update_payload; use lemmy_api_common::site::EditSite; diff --git a/crates/apub/src/activity_lists.rs b/crates/apub/src/activity_lists.rs index 206f0088b..7b33499c8 100644 --- a/crates/apub/src/activity_lists.rs +++ b/crates/apub/src/activity_lists.rs @@ -123,8 +123,8 @@ impl InCommunity for AnnouncableActivities { } #[cfg(test)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::indexing_slicing)] use crate::{ activity_lists::{GroupInboxActivities, PersonInboxActivities, SharedInboxActivities}, diff --git a/crates/apub/src/api/user_settings_backup.rs b/crates/apub/src/api/user_settings_backup.rs index d46e415b0..4c1edcbff 100644 --- a/crates/apub/src/api/user_settings_backup.rs +++ b/crates/apub/src/api/user_settings_backup.rs @@ -319,8 +319,8 @@ pub async fn import_settings( } #[cfg(test)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::indexing_slicing)] use crate::api::user_settings_backup::{export_settings, import_settings}; use activitypub_federation::config::Data; diff --git a/crates/apub/src/collections/community_moderators.rs b/crates/apub/src/collections/community_moderators.rs index 87d88d071..0532d0aef 100644 --- a/crates/apub/src/collections/community_moderators.rs +++ b/crates/apub/src/collections/community_moderators.rs @@ -101,8 +101,8 @@ impl Collection for ApubCommunityModerators { } #[cfg(test)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::indexing_slicing)] use super::*; use crate::{ diff --git a/crates/apub/src/http/community.rs b/crates/apub/src/http/community.rs index 83ccdacf9..cf0d1625d 100644 --- a/crates/apub/src/http/community.rs +++ b/crates/apub/src/http/community.rs @@ -115,9 +115,9 @@ pub(crate) async fn get_apub_community_featured( } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] pub(crate) mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use super::*; use crate::protocol::objects::{group::Group, tombstone::Tombstone}; diff --git a/crates/db_schema/src/aggregates/comment_aggregates.rs b/crates/db_schema/src/aggregates/comment_aggregates.rs index 78ceaa0c6..2120c7f38 100644 --- a/crates/db_schema/src/aggregates/comment_aggregates.rs +++ b/crates/db_schema/src/aggregates/comment_aggregates.rs @@ -33,9 +33,9 @@ impl CommentAggregates { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::{ aggregates::comment_aggregates::CommentAggregates, diff --git a/crates/db_schema/src/aggregates/community_aggregates.rs b/crates/db_schema/src/aggregates/community_aggregates.rs index 334688b97..f1f54663b 100644 --- a/crates/db_schema/src/aggregates/community_aggregates.rs +++ b/crates/db_schema/src/aggregates/community_aggregates.rs @@ -31,9 +31,9 @@ impl CommunityAggregates { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::{ aggregates::community_aggregates::CommunityAggregates, diff --git a/crates/db_schema/src/aggregates/person_aggregates.rs b/crates/db_schema/src/aggregates/person_aggregates.rs index b48b37641..520b45225 100644 --- a/crates/db_schema/src/aggregates/person_aggregates.rs +++ b/crates/db_schema/src/aggregates/person_aggregates.rs @@ -18,9 +18,9 @@ impl PersonAggregates { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::{ aggregates::person_aggregates::PersonAggregates, diff --git a/crates/db_schema/src/aggregates/post_aggregates.rs b/crates/db_schema/src/aggregates/post_aggregates.rs index 9415f8971..7f95dc05a 100644 --- a/crates/db_schema/src/aggregates/post_aggregates.rs +++ b/crates/db_schema/src/aggregates/post_aggregates.rs @@ -52,9 +52,9 @@ impl PostAggregates { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::{ aggregates::post_aggregates::PostAggregates, diff --git a/crates/db_schema/src/aggregates/site_aggregates.rs b/crates/db_schema/src/aggregates/site_aggregates.rs index 453430841..b179ff7c7 100644 --- a/crates/db_schema/src/aggregates/site_aggregates.rs +++ b/crates/db_schema/src/aggregates/site_aggregates.rs @@ -14,9 +14,9 @@ impl SiteAggregates { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::{ aggregates::site_aggregates::SiteAggregates, diff --git a/crates/db_schema/src/impls/activity.rs b/crates/db_schema/src/impls/activity.rs index bb17c83e7..e1802c7c5 100644 --- a/crates/db_schema/src/impls/activity.rs +++ b/crates/db_schema/src/impls/activity.rs @@ -61,9 +61,9 @@ impl ReceivedActivity { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use super::*; use crate::{source::activity::ActorType, utils::build_db_pool_for_tests}; diff --git a/crates/db_schema/src/impls/actor_language.rs b/crates/db_schema/src/impls/actor_language.rs index 29d99b2d8..0191dd872 100644 --- a/crates/db_schema/src/impls/actor_language.rs +++ b/crates/db_schema/src/impls/actor_language.rs @@ -385,9 +385,9 @@ async fn convert_read_languages( } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use super::*; use crate::{ diff --git a/crates/db_schema/src/impls/captcha_answer.rs b/crates/db_schema/src/impls/captcha_answer.rs index 72e2d1285..1d0604c0a 100644 --- a/crates/db_schema/src/impls/captcha_answer.rs +++ b/crates/db_schema/src/impls/captcha_answer.rs @@ -48,9 +48,9 @@ impl CaptchaAnswer { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::{ source::captcha_answer::{CaptchaAnswer, CaptchaAnswerForm, CheckCaptchaAnswer}, diff --git a/crates/db_schema/src/impls/comment.rs b/crates/db_schema/src/impls/comment.rs index 979c3b721..b27d44591 100644 --- a/crates/db_schema/src/impls/comment.rs +++ b/crates/db_schema/src/impls/comment.rs @@ -241,9 +241,9 @@ impl Saveable for CommentSaved { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::{ newtypes::LanguageId, diff --git a/crates/db_schema/src/impls/comment_reply.rs b/crates/db_schema/src/impls/comment_reply.rs index d76b46b8a..40c99e045 100644 --- a/crates/db_schema/src/impls/comment_reply.rs +++ b/crates/db_schema/src/impls/comment_reply.rs @@ -73,9 +73,9 @@ impl CommentReply { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::{ source::{ diff --git a/crates/db_schema/src/impls/community.rs b/crates/db_schema/src/impls/community.rs index 88b0ef46d..dbacbcb72 100644 --- a/crates/db_schema/src/impls/community.rs +++ b/crates/db_schema/src/impls/community.rs @@ -381,9 +381,9 @@ impl ApubActor for Community { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::{ source::{ diff --git a/crates/db_schema/src/impls/federation_allowlist.rs b/crates/db_schema/src/impls/federation_allowlist.rs index 0664a8a4f..80408a526 100644 --- a/crates/db_schema/src/impls/federation_allowlist.rs +++ b/crates/db_schema/src/impls/federation_allowlist.rs @@ -48,9 +48,9 @@ impl FederationAllowList { } } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::{ source::{federation_allowlist::FederationAllowList, instance::Instance}, diff --git a/crates/db_schema/src/impls/language.rs b/crates/db_schema/src/impls/language.rs index 66fc05729..905221402 100644 --- a/crates/db_schema/src/impls/language.rs +++ b/crates/db_schema/src/impls/language.rs @@ -41,9 +41,9 @@ impl Language { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::{source::language::Language, utils::build_db_pool_for_tests}; use pretty_assertions::assert_eq; diff --git a/crates/db_schema/src/impls/moderator.rs b/crates/db_schema/src/impls/moderator.rs index cfb64d883..99f117878 100644 --- a/crates/db_schema/src/impls/moderator.rs +++ b/crates/db_schema/src/impls/moderator.rs @@ -465,9 +465,9 @@ impl Crud for AdminPurgeComment { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::{ source::{ diff --git a/crates/db_schema/src/impls/password_reset_request.rs b/crates/db_schema/src/impls/password_reset_request.rs index 3b910b1d3..491097135 100644 --- a/crates/db_schema/src/impls/password_reset_request.rs +++ b/crates/db_schema/src/impls/password_reset_request.rs @@ -81,9 +81,9 @@ impl PasswordResetRequest { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::{ source::{ diff --git a/crates/db_schema/src/impls/person.rs b/crates/db_schema/src/impls/person.rs index 0de7c32f5..c90f67891 100644 --- a/crates/db_schema/src/impls/person.rs +++ b/crates/db_schema/src/impls/person.rs @@ -212,9 +212,9 @@ impl PersonFollower { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::{ source::{ diff --git a/crates/db_schema/src/impls/person_mention.rs b/crates/db_schema/src/impls/person_mention.rs index 75950e7e9..9882e662c 100644 --- a/crates/db_schema/src/impls/person_mention.rs +++ b/crates/db_schema/src/impls/person_mention.rs @@ -74,9 +74,9 @@ impl PersonMention { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::{ source::{ diff --git a/crates/db_schema/src/impls/post.rs b/crates/db_schema/src/impls/post.rs index 3425a795d..8db871ad5 100644 --- a/crates/db_schema/src/impls/post.rs +++ b/crates/db_schema/src/impls/post.rs @@ -362,9 +362,9 @@ impl PostHide { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::{ source::{ diff --git a/crates/db_schema/src/impls/post_report.rs b/crates/db_schema/src/impls/post_report.rs index face766db..260574bd2 100644 --- a/crates/db_schema/src/impls/post_report.rs +++ b/crates/db_schema/src/impls/post_report.rs @@ -80,9 +80,9 @@ impl Reportable for PostReport { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use super::*; use crate::{ diff --git a/crates/db_schema/src/impls/private_message.rs b/crates/db_schema/src/impls/private_message.rs index 961e36518..ee0009189 100644 --- a/crates/db_schema/src/impls/private_message.rs +++ b/crates/db_schema/src/impls/private_message.rs @@ -74,9 +74,9 @@ impl PrivateMessage { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::{ source::{ diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index 9a89902e7..465ecb4cd 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -536,9 +536,9 @@ impl Queries { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use super::*; use pretty_assertions::assert_eq; diff --git a/crates/db_views/src/comment_report_view.rs b/crates/db_views/src/comment_report_view.rs index 317ebf29a..0da5b3cff 100644 --- a/crates/db_views/src/comment_report_view.rs +++ b/crates/db_views/src/comment_report_view.rs @@ -258,9 +258,9 @@ impl CommentReportQuery { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::{ comment_report_view::{CommentReportQuery, CommentReportView}, diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index f8e91b501..01ff394eb 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -426,9 +426,9 @@ impl<'a> CommentQuery<'a> { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::{ comment_view::{CommentQuery, CommentSortType, CommentView, DbPool}, diff --git a/crates/db_views/src/post_report_view.rs b/crates/db_views/src/post_report_view.rs index 20795c8c0..878937d01 100644 --- a/crates/db_views/src/post_report_view.rs +++ b/crates/db_views/src/post_report_view.rs @@ -283,9 +283,9 @@ impl PostReportQuery { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::{ post_report_view::{PostReportQuery, PostReportView}, diff --git a/crates/db_views/src/private_message_report_view.rs b/crates/db_views/src/private_message_report_view.rs index 2c6919542..091071b16 100644 --- a/crates/db_views/src/private_message_report_view.rs +++ b/crates/db_views/src/private_message_report_view.rs @@ -106,9 +106,9 @@ impl PrivateMessageReportQuery { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::private_message_report_view::PrivateMessageReportQuery; use lemmy_db_schema::{ diff --git a/crates/db_views/src/private_message_view.rs b/crates/db_views/src/private_message_view.rs index a3e2469c9..466f3bdf0 100644 --- a/crates/db_views/src/private_message_view.rs +++ b/crates/db_views/src/private_message_view.rs @@ -173,9 +173,9 @@ impl PrivateMessageQuery { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::{private_message_view::PrivateMessageQuery, structs::PrivateMessageView}; use lemmy_db_schema::{ diff --git a/crates/db_views/src/registration_application_view.rs b/crates/db_views/src/registration_application_view.rs index c2f2e3120..85916bb90 100644 --- a/crates/db_views/src/registration_application_view.rs +++ b/crates/db_views/src/registration_application_view.rs @@ -127,9 +127,9 @@ impl RegistrationApplicationQuery { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::registration_application_view::{ RegistrationApplicationQuery, diff --git a/crates/db_views/src/vote_view.rs b/crates/db_views/src/vote_view.rs index 723c188f5..26df3bdbb 100644 --- a/crates/db_views/src/vote_view.rs +++ b/crates/db_views/src/vote_view.rs @@ -50,9 +50,9 @@ impl VoteView { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::structs::VoteView; use lemmy_db_schema::{ diff --git a/crates/db_views_actor/src/community_view.rs b/crates/db_views_actor/src/community_view.rs index 98a146c15..3107478dc 100644 --- a/crates/db_views_actor/src/community_view.rs +++ b/crates/db_views_actor/src/community_view.rs @@ -250,9 +250,9 @@ impl<'a> CommunityQuery<'a> { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::{community_view::CommunityQuery, structs::CommunityView}; use lemmy_db_schema::{ diff --git a/crates/db_views_actor/src/person_view.rs b/crates/db_views_actor/src/person_view.rs index 1ee51a819..b3eac296d 100644 --- a/crates/db_views_actor/src/person_view.rs +++ b/crates/db_views_actor/src/person_view.rs @@ -163,9 +163,9 @@ impl PersonQuery { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use super::*; use diesel::NotFound; diff --git a/crates/utils/src/rate_limit/mod.rs b/crates/utils/src/rate_limit/mod.rs index b2efbe2c9..de64bac46 100644 --- a/crates/utils/src/rate_limit/mod.rs +++ b/crates/utils/src/rate_limit/mod.rs @@ -221,9 +221,9 @@ fn parse_ip(addr: &str) -> Option { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] #[test] fn test_parse_ip() { diff --git a/crates/utils/src/rate_limit/rate_limiter.rs b/crates/utils/src/rate_limit/rate_limiter.rs index 66d830c7e..3f89aee7e 100644 --- a/crates/utils/src/rate_limit/rate_limiter.rs +++ b/crates/utils/src/rate_limit/rate_limiter.rs @@ -306,9 +306,9 @@ fn split_ipv6(ip: Ipv6Addr) -> ([u8; 6], u8, u8) { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use super::{ActionType, BucketConfig, InstantSecs, RateLimitState, RateLimitedGroup}; use pretty_assertions::assert_eq; diff --git a/crates/utils/src/utils/markdown/mod.rs b/crates/utils/src/utils/markdown/mod.rs index c3def13a7..87e2cb3a2 100644 --- a/crates/utils/src/utils/markdown/mod.rs +++ b/crates/utils/src/utils/markdown/mod.rs @@ -107,9 +107,9 @@ pub fn markdown_check_for_blocked_urls(text: &str, blocklist: &RegexSet) -> Lemm } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use super::*; use pretty_assertions::assert_eq; diff --git a/crates/utils/src/utils/markdown/spoiler_rule.rs b/crates/utils/src/utils/markdown/spoiler_rule.rs index e41ea436f..3f12807fd 100644 --- a/crates/utils/src/utils/markdown/spoiler_rule.rs +++ b/crates/utils/src/utils/markdown/spoiler_rule.rs @@ -134,9 +134,9 @@ pub fn add(markdown_parser: &mut MarkdownIt) { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::utils::markdown::spoiler_rule::add; use markdown_it::MarkdownIt; diff --git a/crates/utils/src/utils/mention.rs b/crates/utils/src/utils/mention.rs index 9e9ee64a2..7e5e5f27c 100644 --- a/crates/utils/src/utils/mention.rs +++ b/crates/utils/src/utils/mention.rs @@ -34,9 +34,9 @@ pub fn scrape_text_for_mentions(text: &str) -> Vec { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod test { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::utils::mention::scrape_text_for_mentions; use pretty_assertions::assert_eq; diff --git a/crates/utils/src/utils/slurs.rs b/crates/utils/src/utils/slurs.rs index fba43d706..e379ae439 100644 --- a/crates/utils/src/utils/slurs.rs +++ b/crates/utils/src/utils/slurs.rs @@ -64,9 +64,9 @@ pub(crate) fn slurs_vec_to_str(slurs: &[&str]) -> String { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod test { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::utils::slurs::{remove_slurs, slur_check, slurs_vec_to_str}; use pretty_assertions::assert_eq; diff --git a/crates/utils/src/utils/validation.rs b/crates/utils/src/utils/validation.rs index f9b2a87e5..93d581327 100644 --- a/crates/utils/src/utils/validation.rs +++ b/crates/utils/src/utils/validation.rs @@ -327,9 +327,9 @@ pub fn check_urls_are_valid(urls: &Vec) -> LemmyResult> { } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use crate::{ error::LemmyErrorType, diff --git a/src/scheduled_tasks.rs b/src/scheduled_tasks.rs index 38eb4ece2..491902fb3 100644 --- a/src/scheduled_tasks.rs +++ b/src/scheduled_tasks.rs @@ -517,9 +517,9 @@ async fn update_instance_software( } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use lemmy_routes::nodeinfo::NodeInfo; use pretty_assertions::assert_eq; diff --git a/src/session_middleware.rs b/src/session_middleware.rs index 474709dbe..2bee64ca0 100644 --- a/src/session_middleware.rs +++ b/src/session_middleware.rs @@ -98,9 +98,9 @@ where } #[cfg(test)] +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] mod tests { - #![allow(clippy::unwrap_used)] - #![allow(clippy::indexing_slicing)] use super::*; use actix_web::test::TestRequest; From 7929e7760268ef2fa247f56489313cb0980fb7b6 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 26 Mar 2024 10:46:37 -0400 Subject: [PATCH 31/31] Fixing issue with comment replies wrongly marked as read. (#4567) * Fixing issue with comment replies wrongly marked as read. - Fixes #4566 * Elaborating on a comment. --- crates/api_crud/src/comment/create.rs | 10 ++++-- crates/db_schema/src/impls/comment_reply.rs | 33 ++++++++++++++------ crates/db_schema/src/impls/person_mention.rs | 22 ++++++------- 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/crates/api_crud/src/comment/create.rs b/crates/api_crud/src/comment/create.rs index 9269ec382..acb386c60 100644 --- a/crates/api_crud/src/comment/create.rs +++ b/crates/api_crud/src/comment/create.rs @@ -164,10 +164,15 @@ pub async fn create_comment( ) .await?; - // If its a reply, mark the parent as read + // If we're responding to a comment where we're the recipient, + // (ie we're the grandparent, or the recipient of the parent comment_reply), + // then mark the parent as read. + // Then we don't have to do it manually after we respond to a comment. if let Some(parent) = parent_opt { + let person_id = local_user_view.person.id; let parent_id = parent.id; - let comment_reply = CommentReply::read_by_comment(&mut context.pool(), parent_id).await; + let comment_reply = + CommentReply::read_by_comment_and_person(&mut context.pool(), parent_id, person_id).await; if let Ok(reply) = comment_reply { CommentReply::update( &mut context.pool(), @@ -179,7 +184,6 @@ pub async fn create_comment( } // If the parent has PersonMentions mark them as read too - let person_id = local_user_view.person.id; let person_mention = PersonMention::read_by_comment_and_person(&mut context.pool(), parent_id, person_id).await; if let Ok(mention) = person_mention { diff --git a/crates/db_schema/src/impls/comment_reply.rs b/crates/db_schema/src/impls/comment_reply.rs index 40c99e045..e6d0915e9 100644 --- a/crates/db_schema/src/impls/comment_reply.rs +++ b/crates/db_schema/src/impls/comment_reply.rs @@ -1,6 +1,6 @@ use crate::{ newtypes::{CommentId, CommentReplyId, PersonId}, - schema::comment_reply::dsl::{comment_id, comment_reply, read, recipient_id}, + schema::comment_reply, source::comment_reply::{CommentReply, CommentReplyInsertForm, CommentReplyUpdateForm}, traits::Crud, utils::{get_conn, DbPool}, @@ -22,9 +22,9 @@ impl Crud for CommentReply { // since the return here isnt utilized, we dont need to do an update // but get_result doesnt return the existing row here - insert_into(comment_reply) + insert_into(comment_reply::table) .values(comment_reply_form) - .on_conflict((recipient_id, comment_id)) + .on_conflict((comment_reply::recipient_id, comment_reply::comment_id)) .do_update() .set(comment_reply_form) .get_result::(conn) @@ -37,7 +37,7 @@ impl Crud for CommentReply { comment_reply_form: &Self::UpdateForm, ) -> Result { let conn = &mut get_conn(pool).await?; - diesel::update(comment_reply.find(comment_reply_id)) + diesel::update(comment_reply::table.find(comment_reply_id)) .set(comment_reply_form) .get_result::(conn) .await @@ -51,11 +51,11 @@ impl CommentReply { ) -> Result, Error> { let conn = &mut get_conn(pool).await?; diesel::update( - comment_reply - .filter(recipient_id.eq(for_recipient_id)) - .filter(read.eq(false)), + comment_reply::table + .filter(comment_reply::recipient_id.eq(for_recipient_id)) + .filter(comment_reply::read.eq(false)), ) - .set(read.eq(true)) + .set(comment_reply::read.eq(true)) .get_results::(conn) .await } @@ -65,8 +65,21 @@ impl CommentReply { for_comment_id: CommentId, ) -> Result { let conn = &mut get_conn(pool).await?; - comment_reply - .filter(comment_id.eq(for_comment_id)) + comment_reply::table + .filter(comment_reply::comment_id.eq(for_comment_id)) + .first::(conn) + .await + } + + pub async fn read_by_comment_and_person( + pool: &mut DbPool<'_>, + for_comment_id: CommentId, + for_recipient_id: PersonId, + ) -> Result { + let conn = &mut get_conn(pool).await?; + comment_reply::table + .filter(comment_reply::comment_id.eq(for_comment_id)) + .filter(comment_reply::recipient_id.eq(for_recipient_id)) .first::(conn) .await } diff --git a/crates/db_schema/src/impls/person_mention.rs b/crates/db_schema/src/impls/person_mention.rs index 9882e662c..5524f87ee 100644 --- a/crates/db_schema/src/impls/person_mention.rs +++ b/crates/db_schema/src/impls/person_mention.rs @@ -1,6 +1,6 @@ use crate::{ newtypes::{CommentId, PersonId, PersonMentionId}, - schema::person_mention::dsl::{comment_id, person_mention, read, recipient_id}, + schema::person_mention, source::person_mention::{PersonMention, PersonMentionInsertForm, PersonMentionUpdateForm}, traits::Crud, utils::{get_conn, DbPool}, @@ -21,9 +21,9 @@ impl Crud for PersonMention { let conn = &mut get_conn(pool).await?; // since the return here isnt utilized, we dont need to do an update // but get_result doesnt return the existing row here - insert_into(person_mention) + insert_into(person_mention::table) .values(person_mention_form) - .on_conflict((recipient_id, comment_id)) + .on_conflict((person_mention::recipient_id, person_mention::comment_id)) .do_update() .set(person_mention_form) .get_result::(conn) @@ -36,7 +36,7 @@ impl Crud for PersonMention { person_mention_form: &Self::UpdateForm, ) -> Result { let conn = &mut get_conn(pool).await?; - diesel::update(person_mention.find(person_mention_id)) + diesel::update(person_mention::table.find(person_mention_id)) .set(person_mention_form) .get_result::(conn) .await @@ -50,11 +50,11 @@ impl PersonMention { ) -> Result, Error> { let conn = &mut get_conn(pool).await?; diesel::update( - person_mention - .filter(recipient_id.eq(for_recipient_id)) - .filter(read.eq(false)), + person_mention::table + .filter(person_mention::recipient_id.eq(for_recipient_id)) + .filter(person_mention::read.eq(false)), ) - .set(read.eq(true)) + .set(person_mention::read.eq(true)) .get_results::(conn) .await } @@ -65,9 +65,9 @@ impl PersonMention { for_recipient_id: PersonId, ) -> Result { let conn = &mut get_conn(pool).await?; - person_mention - .filter(comment_id.eq(for_comment_id)) - .filter(recipient_id.eq(for_recipient_id)) + person_mention::table + .filter(person_mention::comment_id.eq(for_comment_id)) + .filter(person_mention::recipient_id.eq(for_recipient_id)) .first::(conn) .await }