From 148f33def529b30f07bb8679827a8affd14d8c1e Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sat, 15 Apr 2023 19:41:05 -0400 Subject: [PATCH] Leave modded communities on account deletion. Fixes #2560 (#2810) --- crates/api_common/src/utils.rs | 5 ++++- crates/db_schema/src/impls/community.rs | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/api_common/src/utils.rs b/crates/api_common/src/utils.rs index c6bb9ddc4..c94a799db 100644 --- a/crates/api_common/src/utils.rs +++ b/crates/api_common/src/utils.rs @@ -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(()) diff --git a/crates/db_schema/src/impls/community.rs b/crates/db_schema/src/impls/community.rs index fe41d4d58..e717b8a86 100644 --- a/crates/db_schema/src/impls/community.rs +++ b/crates/db_schema/src/impls/community.rs @@ -152,6 +152,17 @@ impl CommunityModerator { .await } + pub async fn leave_all_communities( + pool: &DbPool, + for_person_id: PersonId, + ) -> Result { + 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,