mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-02 06:11:03 +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 actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
request::delete_image_from_pictrs,
|
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
site::PurgePerson,
|
site::PurgePerson,
|
||||||
utils::is_admin,
|
utils::{is_admin, purge_local_user_images},
|
||||||
SuccessResponse,
|
SuccessResponse,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
images::LocalImage,
|
|
||||||
moderator::{AdminPurgePerson, AdminPurgePersonForm},
|
moderator::{AdminPurgePerson, AdminPurgePersonForm},
|
||||||
person::{Person, PersonUpdateForm},
|
person::{Person, PersonUpdateForm},
|
||||||
},
|
},
|
||||||
|
@ -28,17 +26,7 @@ pub async fn purge_person(
|
||||||
// Only let admin purge an item
|
// Only let admin purge an item
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
||||||
// Read the person to get their images
|
purge_local_user_images(data.person_id, &context).await.ok();
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear profile data.
|
// Clear profile data.
|
||||||
Person::delete_account(&mut context.pool(), data.person_id).await?;
|
Person::delete_account(&mut context.pool(), data.person_id).await?;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
request::purge_image_from_pictrs,
|
request::{delete_image_from_pictrs, purge_image_from_pictrs},
|
||||||
site::{FederatedInstances, InstanceWithFederationState},
|
site::{FederatedInstances, InstanceWithFederationState},
|
||||||
};
|
};
|
||||||
use chrono::{DateTime, Days, Local, TimeZone, Utc};
|
use chrono::{DateTime, Days, Local, TimeZone, Utc};
|
||||||
|
@ -12,7 +12,7 @@ use lemmy_db_schema::{
|
||||||
community::{Community, CommunityModerator, CommunityUpdateForm},
|
community::{Community, CommunityModerator, CommunityUpdateForm},
|
||||||
community_block::CommunityBlock,
|
community_block::CommunityBlock,
|
||||||
email_verification::{EmailVerification, EmailVerificationForm},
|
email_verification::{EmailVerification, EmailVerificationForm},
|
||||||
images::RemoteImage,
|
images::{LocalImage, RemoteImage},
|
||||||
instance::Instance,
|
instance::Instance,
|
||||||
instance_block::InstanceBlock,
|
instance_block::InstanceBlock,
|
||||||
local_site::LocalSite,
|
local_site::LocalSite,
|
||||||
|
@ -615,6 +615,25 @@ pub async fn purge_image_posts_for_person(
|
||||||
Ok(())
|
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(
|
pub async fn purge_image_posts_for_community(
|
||||||
banned_community_id: CommunityId,
|
banned_community_id: CommunityId,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
|
@ -756,15 +775,22 @@ pub async fn purge_user_account(
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let pool = &mut context.pool();
|
let pool = &mut context.pool();
|
||||||
// Delete their images
|
|
||||||
let person = Person::read(pool, person_id).await?;
|
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 {
|
if let Some(avatar) = person.avatar {
|
||||||
purge_image_from_pictrs(&avatar, context).await.ok();
|
purge_image_from_pictrs(&avatar, context).await.ok();
|
||||||
}
|
}
|
||||||
if let Some(banner) = person.banner {
|
if let Some(banner) = person.banner {
|
||||||
purge_image_from_pictrs(&banner, context).await.ok();
|
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
|
// Comments
|
||||||
Comment::permadelete_for_creator(pool, person_id)
|
Comment::permadelete_for_creator(pool, person_id)
|
||||||
|
@ -776,9 +802,6 @@ pub async fn purge_user_account(
|
||||||
.await
|
.await
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntUpdatePost)?;
|
.with_lemmy_type(LemmyErrorType::CouldntUpdatePost)?;
|
||||||
|
|
||||||
// Purge image posts
|
|
||||||
purge_image_posts_for_person(person_id, context).await?;
|
|
||||||
|
|
||||||
// Leave communities they mod
|
// Leave communities they mod
|
||||||
CommunityModerator::leave_all_communities(pool, person_id).await?;
|
CommunityModerator::leave_all_communities(pool, person_id).await?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue