X-Git-Url: http://these/git/?a=blobdiff_plain;f=crates%2Fdb_schema%2Fsrc%2Fimpls%2Ffederation_allowlist.rs;h=eb67acce8bc0ca614bdc49ce519e32285eded51b;hb=92568956353f21649ed9aff68b42699c9d036f30;hp=c0b4020ef159e63ef53918ec3a0537538ac9f106;hpb=6f3bf4634b0e1cf529c4683d6ee971917e2bfa50;p=lemmy.git diff --git a/crates/db_schema/src/impls/federation_allowlist.rs b/crates/db_schema/src/impls/federation_allowlist.rs index c0b4020e..eb67acce 100644 --- a/crates/db_schema/src/impls/federation_allowlist.rs +++ b/crates/db_schema/src/impls/federation_allowlist.rs @@ -10,7 +10,7 @@ use diesel::{dsl::insert_into, result::Error}; use diesel_async::{AsyncPgConnection, RunQueryDsl}; impl FederationAllowList { - pub async fn replace(pool: &DbPool, list_opt: Option>) -> Result<(), Error> { + pub async fn replace(pool: &mut DbPool<'_>, list_opt: Option>) -> Result<(), Error> { let conn = &mut get_conn(pool).await?; conn .build_transaction() @@ -21,7 +21,7 @@ impl FederationAllowList { for domain in list { // Upsert all of these as instances - let instance = Instance::create_conn(conn, &domain).await?; + let instance = Instance::read_or_create(&mut conn.into(), domain).await?; let form = FederationAllowListForm { instance_id: instance.id, @@ -49,6 +49,9 @@ impl FederationAllowList { } #[cfg(test)] mod tests { + #![allow(clippy::unwrap_used)] + #![allow(clippy::indexing_slicing)] + use crate::{ source::{federation_allowlist::FederationAllowList, instance::Instance}, utils::build_db_pool_for_tests, @@ -59,25 +62,25 @@ mod tests { #[serial] async fn test_allowlist_insert_and_clear() { let pool = &build_db_pool_for_tests().await; - let allowed = Some(vec![ + let pool = &mut pool.into(); + let domains = vec![ "tld1.xyz".to_string(), "tld2.xyz".to_string(), "tld3.xyz".to_string(), - ]); + ]; + + let allowed = Some(domains.clone()); FederationAllowList::replace(pool, allowed).await.unwrap(); let allows = Instance::allowlist(pool).await.unwrap(); + let allows_domains = allows + .iter() + .map(|i| i.domain.clone()) + .collect::>(); assert_eq!(3, allows.len()); - assert_eq!( - vec![ - "tld1.xyz".to_string(), - "tld2.xyz".to_string(), - "tld3.xyz".to_string() - ], - allows - ); + assert_eq!(domains, allows_domains); // Now test clearing them via Some(empty vec) let clear_allows = Some(Vec::new());