From: Dessalines Date: Wed, 22 Feb 2023 01:22:54 +0000 (-0500) Subject: Fixing issue with saving site language. Fixes #2748 (#2749) X-Git-Url: http://these/git/%22%7Burl%7D/static/%7B%7D/%7B%60%24%7BrepoUrl%7D?a=commitdiff_plain;h=cd5c79527a906d2ceeb4ddea2c5176fe53d753ce;p=lemmy.git Fixing issue with saving site language. Fixes #2748 (#2749) * Fixing issue with saving site language. Fixes #2748 * Add a warning to Site::read --- diff --git a/crates/api_crud/src/site/update.rs b/crates/api_crud/src/site/update.rs index a169f237..36a09628 100644 --- a/crates/api_crud/src/site/update.rs +++ b/crates/api_crud/src/site/update.rs @@ -44,7 +44,9 @@ impl PerformCrud for EditSite { let data: &EditSite = self; let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; - let local_site = LocalSite::read(context.pool()).await?; + let site_view = SiteView::read_local(context.pool()).await?; + let local_site = site_view.local_site; + let site = site_view.site; // Make sure user is an admin is_admin(&local_user_view)?; @@ -76,9 +78,7 @@ impl PerformCrud for EditSite { } } - let site_id = local_site.site_id; if let Some(discussion_languages) = data.discussion_languages.clone() { - let site = Site::read(context.pool(), site_id).await?; SiteLanguage::update(context.pool(), discussion_languages.clone(), &site).await?; } @@ -92,7 +92,7 @@ impl PerformCrud for EditSite { .updated(Some(Some(naive_now()))) .build(); - Site::update(context.pool(), site_id, &site_form) + Site::update(context.pool(), site.id, &site_form) .await // Ignore errors for all these, so as to not throw errors if no update occurs // Diesel will throw an error for empty update forms diff --git a/crates/db_schema/src/impls/site.rs b/crates/db_schema/src/impls/site.rs index 96f8a2f0..7120b8a6 100644 --- a/crates/db_schema/src/impls/site.rs +++ b/crates/db_schema/src/impls/site.rs @@ -18,9 +18,9 @@ impl Crud for Site { type UpdateForm = SiteUpdateForm; type IdType = SiteId; - async fn read(pool: &DbPool, _site_id: SiteId) -> Result { - let conn = &mut get_conn(pool).await?; - site.first::(conn).await + /// Use SiteView::read_local, or Site::read_from_apub_id instead + async fn read(_pool: &DbPool, _site_id: SiteId) -> Result { + unimplemented!() } async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result {