2024-03-05 14:31:04 +00:00
|
|
|
use crate::ban_nonlocal_user_from_local_communities;
|
2024-01-25 14:24:09 +00:00
|
|
|
use activitypub_federation::config::Data;
|
|
|
|
use actix_web::web::Json;
|
2022-06-13 19:15:04 +00:00
|
|
|
use lemmy_api_common::{
|
2022-11-28 14:29:33 +00:00
|
|
|
context::LemmyContext,
|
2024-01-25 14:24:09 +00:00
|
|
|
send_activity::{ActivityChannel, SendActivityData},
|
2023-10-19 17:21:05 +00:00
|
|
|
site::PurgePerson,
|
2024-03-27 14:28:02 +00:00
|
|
|
utils::{is_admin, purge_user_account},
|
2023-10-19 17:21:05 +00:00
|
|
|
SuccessResponse,
|
2022-06-13 19:15:04 +00:00
|
|
|
};
|
|
|
|
use lemmy_db_schema::{
|
|
|
|
source::{
|
|
|
|
moderator::{AdminPurgePerson, AdminPurgePersonForm},
|
2023-11-22 14:36:20 +00:00
|
|
|
person::{Person, PersonUpdateForm},
|
2022-06-13 19:15:04 +00:00
|
|
|
},
|
|
|
|
traits::Crud,
|
|
|
|
};
|
2023-09-06 13:13:30 +00:00
|
|
|
use lemmy_db_views::structs::LocalUserView;
|
2024-04-10 14:14:11 +00:00
|
|
|
use lemmy_utils::error::LemmyResult;
|
2022-06-13 19:15:04 +00:00
|
|
|
|
2023-09-05 09:33:46 +00:00
|
|
|
#[tracing::instrument(skip(context))]
|
|
|
|
pub async fn purge_person(
|
|
|
|
data: Json<PurgePerson>,
|
|
|
|
context: Data<LemmyContext>,
|
2023-09-21 10:42:28 +00:00
|
|
|
local_user_view: LocalUserView,
|
2024-04-10 14:14:11 +00:00
|
|
|
) -> LemmyResult<Json<SuccessResponse>> {
|
2023-09-05 09:33:46 +00:00
|
|
|
// Only let admin purge an item
|
|
|
|
is_admin(&local_user_view)?;
|
2022-06-13 19:15:04 +00:00
|
|
|
|
2024-03-05 14:31:04 +00:00
|
|
|
let person = Person::read(&mut context.pool(), data.person_id).await?;
|
|
|
|
ban_nonlocal_user_from_local_communities(
|
|
|
|
&local_user_view,
|
|
|
|
&person,
|
|
|
|
true,
|
|
|
|
&data.reason,
|
|
|
|
&Some(true),
|
|
|
|
&None,
|
|
|
|
&context,
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
2023-11-22 14:36:20 +00:00
|
|
|
// Clear profile data.
|
2024-03-27 14:28:02 +00:00
|
|
|
purge_user_account(data.person_id, &context).await?;
|
|
|
|
|
2023-11-22 14:36:20 +00:00
|
|
|
// Keep person record, but mark as banned to prevent login or refetching from home instance.
|
2024-01-25 14:24:09 +00:00
|
|
|
let person = Person::update(
|
2023-11-22 14:36:20 +00:00
|
|
|
&mut context.pool(),
|
2024-01-25 14:24:09 +00:00
|
|
|
data.person_id,
|
2023-11-22 14:36:20 +00:00
|
|
|
&PersonUpdateForm {
|
|
|
|
banned: Some(true),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.await?;
|
2022-06-13 19:15:04 +00:00
|
|
|
|
2023-09-05 09:33:46 +00:00
|
|
|
// Mod tables
|
|
|
|
let form = AdminPurgePersonForm {
|
|
|
|
admin_person_id: local_user_view.person.id,
|
2023-10-11 14:48:19 +00:00
|
|
|
reason: data.reason.clone(),
|
2023-09-05 09:33:46 +00:00
|
|
|
};
|
|
|
|
AdminPurgePerson::create(&mut context.pool(), &form).await?;
|
2022-06-13 19:15:04 +00:00
|
|
|
|
2024-01-25 14:24:09 +00:00
|
|
|
ActivityChannel::submit_activity(
|
|
|
|
SendActivityData::BanFromSite {
|
|
|
|
moderator: local_user_view.person,
|
|
|
|
banned_user: person,
|
|
|
|
reason: data.reason.clone(),
|
|
|
|
remove_data: Some(true),
|
|
|
|
ban: true,
|
|
|
|
expires: None,
|
|
|
|
},
|
|
|
|
&context,
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
2023-10-19 17:21:05 +00:00
|
|
|
Ok(Json(SuccessResponse::default()))
|
2022-06-13 19:15:04 +00:00
|
|
|
}
|