mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-01 22:01:49 +00:00
Delete a person's local images on delete account.
This commit is contained in:
parent
157378b4c9
commit
7387a046ad
2 changed files with 32 additions and 21 deletions
|
@ -2,15 +2,13 @@ use activitypub_federation::config::Data;
|
|||
use actix_web::web::Json;
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
request::delete_image_from_pictrs,
|
||||
send_activity::{ActivityChannel, SendActivityData},
|
||||
site::PurgePerson,
|
||||
utils::is_admin,
|
||||
utils::{is_admin, purge_local_user_images},
|
||||
SuccessResponse,
|
||||
};
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
images::LocalImage,
|
||||
moderator::{AdminPurgePerson, AdminPurgePersonForm},
|
||||
person::{Person, PersonUpdateForm},
|
||||
},
|
||||
|
@ -28,17 +26,7 @@ pub async fn purge_person(
|
|||
// Only let admin purge an item
|
||||
is_admin(&local_user_view)?;
|
||||
|
||||
// Read the person to get their images
|
||||
if let Ok(local_user) = LocalUserView::read_person(&mut context.pool(), data.person_id).await {
|
||||
let pictrs_uploads =
|
||||
LocalImage::get_all_by_local_user_id(&mut context.pool(), &local_user.local_user.id).await?;
|
||||
|
||||
for upload in pictrs_uploads {
|
||||
delete_image_from_pictrs(&upload.pictrs_alias, &upload.pictrs_delete_token, &context)
|
||||
.await
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
purge_local_user_images(data.person_id, &context).await.ok();
|
||||
|
||||
// Clear profile data.
|
||||
Person::delete_account(&mut context.pool(), data.person_id).await?;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
context::LemmyContext,
|
||||
request::purge_image_from_pictrs,
|
||||
request::{delete_image_from_pictrs, purge_image_from_pictrs},
|
||||
site::{FederatedInstances, InstanceWithFederationState},
|
||||
};
|
||||
use chrono::{DateTime, Days, Local, TimeZone, Utc};
|
||||
|
@ -12,7 +12,7 @@ use lemmy_db_schema::{
|
|||
community::{Community, CommunityModerator, CommunityUpdateForm},
|
||||
community_block::CommunityBlock,
|
||||
email_verification::{EmailVerification, EmailVerificationForm},
|
||||
images::RemoteImage,
|
||||
images::{LocalImage, RemoteImage},
|
||||
instance::Instance,
|
||||
instance_block::InstanceBlock,
|
||||
local_site::LocalSite,
|
||||
|
@ -615,6 +615,25 @@ pub async fn purge_image_posts_for_person(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Delete a local_user's images
|
||||
pub async fn purge_local_user_images(
|
||||
person_id: PersonId,
|
||||
context: &LemmyContext,
|
||||
) -> Result<(), LemmyError> {
|
||||
// Delete their images
|
||||
if let Ok(local_user) = LocalUserView::read_person(&mut context.pool(), person_id).await {
|
||||
let pictrs_uploads =
|
||||
LocalImage::get_all_by_local_user_id(&mut context.pool(), &local_user.local_user.id).await?;
|
||||
|
||||
for upload in pictrs_uploads {
|
||||
delete_image_from_pictrs(&upload.pictrs_alias, &upload.pictrs_delete_token, context)
|
||||
.await
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn purge_image_posts_for_community(
|
||||
banned_community_id: CommunityId,
|
||||
context: &LemmyContext,
|
||||
|
@ -756,15 +775,22 @@ pub async fn purge_user_account(
|
|||
context: &LemmyContext,
|
||||
) -> Result<(), LemmyError> {
|
||||
let pool = &mut context.pool();
|
||||
// Delete their images
|
||||
|
||||
let person = Person::read(pool, person_id).await?;
|
||||
|
||||
// Delete their local images, if they're a local user
|
||||
purge_local_user_images(person_id, context).await.ok();
|
||||
|
||||
// No need to update avatar and banner, those are handled in Person::delete_account
|
||||
if let Some(avatar) = person.avatar {
|
||||
purge_image_from_pictrs(&avatar, context).await.ok();
|
||||
}
|
||||
if let Some(banner) = person.banner {
|
||||
purge_image_from_pictrs(&banner, context).await.ok();
|
||||
}
|
||||
// No need to update avatar and banner, those are handled in Person::delete_account
|
||||
|
||||
// Purge image posts
|
||||
purge_image_posts_for_person(person_id, context).await.ok();
|
||||
|
||||
// Comments
|
||||
Comment::permadelete_for_creator(pool, person_id)
|
||||
|
@ -776,9 +802,6 @@ pub async fn purge_user_account(
|
|||
.await
|
||||
.with_lemmy_type(LemmyErrorType::CouldntUpdatePost)?;
|
||||
|
||||
// Purge image posts
|
||||
purge_image_posts_for_person(person_id, context).await?;
|
||||
|
||||
// Leave communities they mod
|
||||
CommunityModerator::leave_all_communities(pool, person_id).await?;
|
||||
|
||||
|
|
Loading…
Reference in a new issue