]> Untitled Git - lemmy.git/commitdiff
Leave modded communities on account deletion. Fixes #2560 (#2810)
authorDessalines <dessalines@users.noreply.github.com>
Sat, 15 Apr 2023 23:41:05 +0000 (19:41 -0400)
committerGitHub <noreply@github.com>
Sat, 15 Apr 2023 23:41:05 +0000 (19:41 -0400)
crates/api_common/src/utils.rs
crates/db_schema/src/impls/community.rs

index c6bb9ddc4a0efed34aaffc24dbe7f55a644e5fe6..c94a799db2337df399487755160b7307537b2f43 100644 (file)
@@ -6,7 +6,7 @@ use lemmy_db_schema::{
   newtypes::{CommunityId, DbUrl, LocalUserId, PersonId, PostId},
   source::{
     comment::{Comment, CommentUpdateForm},
-    community::{Community, CommunityUpdateForm},
+    community::{Community, CommunityModerator, CommunityUpdateForm},
     email_verification::{EmailVerification, EmailVerificationForm},
     instance::Instance,
     local_site::{LocalSite, RegistrationMode},
@@ -774,6 +774,9 @@ pub async fn delete_user_account(
   // Purge image posts
   purge_image_posts_for_person(person_id, pool, settings, client).await?;
 
+  // Leave communities they mod
+  CommunityModerator::leave_all_communities(pool, person_id).await?;
+
   Person::delete_account(pool, person_id).await?;
 
   Ok(())
index fe41d4d587247ee0d71fa4d4550731f598cf196c..e717b8a865e367a0361219cf7349cd872c2db4a9 100644 (file)
@@ -152,6 +152,17 @@ impl CommunityModerator {
       .await
   }
 
+  pub async fn leave_all_communities(
+    pool: &DbPool,
+    for_person_id: PersonId,
+  ) -> Result<usize, Error> {
+    use crate::schema::community_moderator::dsl::{community_moderator, person_id};
+    let conn = &mut get_conn(pool).await?;
+    diesel::delete(community_moderator.filter(person_id.eq(for_person_id)))
+      .execute(conn)
+      .await
+  }
+
   pub async fn get_person_moderated_communities(
     pool: &DbPool,
     for_person_id: PersonId,