|
|
@ -24,7 +24,7 @@ use lemmy_db_schema::{
|
|
|
|
registration_application::RegistrationApplication,
|
|
|
|
registration_application::RegistrationApplication,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
traits::{Crud, Readable},
|
|
|
|
traits::{Crud, Readable},
|
|
|
|
utils::DbPool,
|
|
|
|
utils::{get_conn, DbConn, DbPool},
|
|
|
|
RegistrationMode,
|
|
|
|
RegistrationMode,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
use lemmy_db_views::{comment_view::CommentQuery, structs::LocalUserView};
|
|
|
|
use lemmy_db_views::{comment_view::CommentQuery, structs::LocalUserView};
|
|
|
@ -51,11 +51,11 @@ use url::{ParseError, Url};
|
|
|
|
|
|
|
|
|
|
|
|
#[tracing::instrument(skip_all)]
|
|
|
|
#[tracing::instrument(skip_all)]
|
|
|
|
pub async fn is_mod_or_admin(
|
|
|
|
pub async fn is_mod_or_admin(
|
|
|
|
pool: &DbPool,
|
|
|
|
conn: &mut DbConn,
|
|
|
|
person_id: PersonId,
|
|
|
|
person_id: PersonId,
|
|
|
|
community_id: CommunityId,
|
|
|
|
community_id: CommunityId,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
let is_mod_or_admin = CommunityView::is_mod_or_admin(pool, person_id, community_id).await?;
|
|
|
|
let is_mod_or_admin = CommunityView::is_mod_or_admin(conn, person_id, community_id).await?;
|
|
|
|
if !is_mod_or_admin {
|
|
|
|
if !is_mod_or_admin {
|
|
|
|
return Err(LemmyError::from_message("not_a_mod_or_admin"));
|
|
|
|
return Err(LemmyError::from_message("not_a_mod_or_admin"));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -64,13 +64,13 @@ pub async fn is_mod_or_admin(
|
|
|
|
|
|
|
|
|
|
|
|
#[tracing::instrument(skip_all)]
|
|
|
|
#[tracing::instrument(skip_all)]
|
|
|
|
pub async fn is_mod_or_admin_opt(
|
|
|
|
pub async fn is_mod_or_admin_opt(
|
|
|
|
pool: &DbPool,
|
|
|
|
conn: &mut DbConn,
|
|
|
|
local_user_view: Option<&LocalUserView>,
|
|
|
|
local_user_view: Option<&LocalUserView>,
|
|
|
|
community_id: Option<CommunityId>,
|
|
|
|
community_id: Option<CommunityId>,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
if let Some(local_user_view) = local_user_view {
|
|
|
|
if let Some(local_user_view) = local_user_view {
|
|
|
|
if let Some(community_id) = community_id {
|
|
|
|
if let Some(community_id) = community_id {
|
|
|
|
is_mod_or_admin(pool, local_user_view.person.id, community_id).await
|
|
|
|
is_mod_or_admin(conn, local_user_view.person.id, community_id).await
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
is_admin(local_user_view)
|
|
|
|
is_admin(local_user_view)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -79,8 +79,8 @@ pub async fn is_mod_or_admin_opt(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub async fn is_top_admin(pool: &DbPool, person_id: PersonId) -> Result<(), LemmyError> {
|
|
|
|
pub async fn is_top_admin(conn: &mut DbConn, person_id: PersonId) -> Result<(), LemmyError> {
|
|
|
|
let admins = PersonView::admins(pool).await?;
|
|
|
|
let admins = PersonView::admins(conn).await?;
|
|
|
|
let top_admin = admins
|
|
|
|
let top_admin = admins
|
|
|
|
.first()
|
|
|
|
.first()
|
|
|
|
.ok_or_else(|| LemmyError::from_message("no admins"))?;
|
|
|
|
.ok_or_else(|| LemmyError::from_message("no admins"))?;
|
|
|
@ -114,8 +114,8 @@ pub fn is_top_mod(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[tracing::instrument(skip_all)]
|
|
|
|
#[tracing::instrument(skip_all)]
|
|
|
|
pub async fn get_post(post_id: PostId, pool: &DbPool) -> Result<Post, LemmyError> {
|
|
|
|
pub async fn get_post(post_id: PostId, conn: &mut DbConn) -> Result<Post, LemmyError> {
|
|
|
|
Post::read(pool, post_id)
|
|
|
|
Post::read(conn, post_id)
|
|
|
|
.await
|
|
|
|
.await
|
|
|
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_post"))
|
|
|
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_post"))
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -124,11 +124,11 @@ pub async fn get_post(post_id: PostId, pool: &DbPool) -> Result<Post, LemmyError
|
|
|
|
pub async fn mark_post_as_read(
|
|
|
|
pub async fn mark_post_as_read(
|
|
|
|
person_id: PersonId,
|
|
|
|
person_id: PersonId,
|
|
|
|
post_id: PostId,
|
|
|
|
post_id: PostId,
|
|
|
|
pool: &DbPool,
|
|
|
|
conn: &mut DbConn,
|
|
|
|
) -> Result<PostRead, LemmyError> {
|
|
|
|
) -> Result<PostRead, LemmyError> {
|
|
|
|
let post_read_form = PostReadForm { post_id, person_id };
|
|
|
|
let post_read_form = PostReadForm { post_id, person_id };
|
|
|
|
|
|
|
|
|
|
|
|
PostRead::mark_as_read(pool, &post_read_form)
|
|
|
|
PostRead::mark_as_read(conn, &post_read_form)
|
|
|
|
.await
|
|
|
|
.await
|
|
|
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_mark_post_as_read"))
|
|
|
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_mark_post_as_read"))
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -137,11 +137,11 @@ pub async fn mark_post_as_read(
|
|
|
|
pub async fn mark_post_as_unread(
|
|
|
|
pub async fn mark_post_as_unread(
|
|
|
|
person_id: PersonId,
|
|
|
|
person_id: PersonId,
|
|
|
|
post_id: PostId,
|
|
|
|
post_id: PostId,
|
|
|
|
pool: &DbPool,
|
|
|
|
conn: &mut DbConn,
|
|
|
|
) -> Result<usize, LemmyError> {
|
|
|
|
) -> Result<usize, LemmyError> {
|
|
|
|
let post_read_form = PostReadForm { post_id, person_id };
|
|
|
|
let post_read_form = PostReadForm { post_id, person_id };
|
|
|
|
|
|
|
|
|
|
|
|
PostRead::mark_as_unread(pool, &post_read_form)
|
|
|
|
PostRead::mark_as_unread(conn, &post_read_form)
|
|
|
|
.await
|
|
|
|
.await
|
|
|
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_mark_post_as_read"))
|
|
|
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_mark_post_as_read"))
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -155,7 +155,7 @@ pub async fn local_user_view_from_jwt(
|
|
|
|
.map_err(|e| e.with_message("not_logged_in"))?
|
|
|
|
.map_err(|e| e.with_message("not_logged_in"))?
|
|
|
|
.claims;
|
|
|
|
.claims;
|
|
|
|
let local_user_id = LocalUserId(claims.sub);
|
|
|
|
let local_user_id = LocalUserId(claims.sub);
|
|
|
|
let local_user_view = LocalUserView::read(context.pool(), local_user_id).await?;
|
|
|
|
let local_user_view = LocalUserView::read(&mut *context.conn().await?, local_user_id).await?;
|
|
|
|
check_user_valid(
|
|
|
|
check_user_valid(
|
|
|
|
local_user_view.person.banned,
|
|
|
|
local_user_view.person.banned,
|
|
|
|
local_user_view.person.ban_expires,
|
|
|
|
local_user_view.person.ban_expires,
|
|
|
@ -210,9 +210,9 @@ pub fn check_user_valid(
|
|
|
|
pub async fn check_community_ban(
|
|
|
|
pub async fn check_community_ban(
|
|
|
|
person_id: PersonId,
|
|
|
|
person_id: PersonId,
|
|
|
|
community_id: CommunityId,
|
|
|
|
community_id: CommunityId,
|
|
|
|
pool: &DbPool,
|
|
|
|
conn: &mut DbConn,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
let is_banned = CommunityPersonBanView::get(pool, person_id, community_id)
|
|
|
|
let is_banned = CommunityPersonBanView::get(conn, person_id, community_id)
|
|
|
|
.await
|
|
|
|
.await
|
|
|
|
.is_ok();
|
|
|
|
.is_ok();
|
|
|
|
if is_banned {
|
|
|
|
if is_banned {
|
|
|
@ -225,9 +225,9 @@ pub async fn check_community_ban(
|
|
|
|
#[tracing::instrument(skip_all)]
|
|
|
|
#[tracing::instrument(skip_all)]
|
|
|
|
pub async fn check_community_deleted_or_removed(
|
|
|
|
pub async fn check_community_deleted_or_removed(
|
|
|
|
community_id: CommunityId,
|
|
|
|
community_id: CommunityId,
|
|
|
|
pool: &DbPool,
|
|
|
|
conn: &mut DbConn,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
let community = Community::read(pool, community_id)
|
|
|
|
let community = Community::read(conn, community_id)
|
|
|
|
.await
|
|
|
|
.await
|
|
|
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
|
|
|
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
|
|
|
|
if community.deleted || community.removed {
|
|
|
|
if community.deleted || community.removed {
|
|
|
@ -249,9 +249,9 @@ pub fn check_post_deleted_or_removed(post: &Post) -> Result<(), LemmyError> {
|
|
|
|
pub async fn check_person_block(
|
|
|
|
pub async fn check_person_block(
|
|
|
|
my_id: PersonId,
|
|
|
|
my_id: PersonId,
|
|
|
|
potential_blocker_id: PersonId,
|
|
|
|
potential_blocker_id: PersonId,
|
|
|
|
pool: &DbPool,
|
|
|
|
conn: &mut DbConn,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
let is_blocked = PersonBlock::read(pool, potential_blocker_id, my_id)
|
|
|
|
let is_blocked = PersonBlock::read(conn, potential_blocker_id, my_id)
|
|
|
|
.await
|
|
|
|
.await
|
|
|
|
.is_ok();
|
|
|
|
.is_ok();
|
|
|
|
if is_blocked {
|
|
|
|
if is_blocked {
|
|
|
@ -285,12 +285,16 @@ pub async fn build_federated_instances(
|
|
|
|
local_site: &LocalSite,
|
|
|
|
local_site: &LocalSite,
|
|
|
|
pool: &DbPool,
|
|
|
|
pool: &DbPool,
|
|
|
|
) -> Result<Option<FederatedInstances>, LemmyError> {
|
|
|
|
) -> Result<Option<FederatedInstances>, LemmyError> {
|
|
|
|
|
|
|
|
let conn_0 = &mut *get_conn(pool).await?;
|
|
|
|
|
|
|
|
let conn_1 = &mut *get_conn(pool).await?;
|
|
|
|
|
|
|
|
let conn_2 = &mut *get_conn(pool).await?;
|
|
|
|
|
|
|
|
|
|
|
|
if local_site.federation_enabled {
|
|
|
|
if local_site.federation_enabled {
|
|
|
|
// TODO I hate that this requires 3 queries
|
|
|
|
// TODO I hate that this requires 3 queries
|
|
|
|
let (linked, allowed, blocked) = try_join!(
|
|
|
|
let (linked, allowed, blocked) = try_join!(
|
|
|
|
Instance::linked(pool),
|
|
|
|
Instance::linked(conn_0),
|
|
|
|
Instance::allowlist(pool),
|
|
|
|
Instance::allowlist(conn_1),
|
|
|
|
Instance::blocklist(pool)
|
|
|
|
Instance::blocklist(conn_2)
|
|
|
|
)?;
|
|
|
|
)?;
|
|
|
|
|
|
|
|
|
|
|
|
Ok(Some(FederatedInstances {
|
|
|
|
Ok(Some(FederatedInstances {
|
|
|
@ -356,7 +360,7 @@ pub fn send_email_to_user(
|
|
|
|
|
|
|
|
|
|
|
|
pub async fn send_password_reset_email(
|
|
|
|
pub async fn send_password_reset_email(
|
|
|
|
user: &LocalUserView,
|
|
|
|
user: &LocalUserView,
|
|
|
|
pool: &DbPool,
|
|
|
|
conn: &mut DbConn,
|
|
|
|
settings: &Settings,
|
|
|
|
settings: &Settings,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
// Generate a random token
|
|
|
|
// Generate a random token
|
|
|
@ -365,7 +369,7 @@ pub async fn send_password_reset_email(
|
|
|
|
// Insert the row
|
|
|
|
// Insert the row
|
|
|
|
let token2 = token.clone();
|
|
|
|
let token2 = token.clone();
|
|
|
|
let local_user_id = user.local_user.id;
|
|
|
|
let local_user_id = user.local_user.id;
|
|
|
|
PasswordResetRequest::create_token(pool, local_user_id, &token2).await?;
|
|
|
|
PasswordResetRequest::create_token(conn, local_user_id, &token2).await?;
|
|
|
|
|
|
|
|
|
|
|
|
let email = &user.local_user.email.clone().expect("email");
|
|
|
|
let email = &user.local_user.email.clone().expect("email");
|
|
|
|
let lang = get_interface_language(user);
|
|
|
|
let lang = get_interface_language(user);
|
|
|
@ -380,7 +384,7 @@ pub async fn send_password_reset_email(
|
|
|
|
pub async fn send_verification_email(
|
|
|
|
pub async fn send_verification_email(
|
|
|
|
user: &LocalUserView,
|
|
|
|
user: &LocalUserView,
|
|
|
|
new_email: &str,
|
|
|
|
new_email: &str,
|
|
|
|
pool: &DbPool,
|
|
|
|
conn: &mut DbConn,
|
|
|
|
settings: &Settings,
|
|
|
|
settings: &Settings,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
let form = EmailVerificationForm {
|
|
|
|
let form = EmailVerificationForm {
|
|
|
@ -393,7 +397,7 @@ pub async fn send_verification_email(
|
|
|
|
settings.get_protocol_and_hostname(),
|
|
|
|
settings.get_protocol_and_hostname(),
|
|
|
|
&form.verification_token
|
|
|
|
&form.verification_token
|
|
|
|
);
|
|
|
|
);
|
|
|
|
EmailVerification::create(pool, &form).await?;
|
|
|
|
EmailVerification::create(conn, &form).await?;
|
|
|
|
|
|
|
|
|
|
|
|
let lang = get_interface_language(user);
|
|
|
|
let lang = get_interface_language(user);
|
|
|
|
let subject = lang.verify_email_subject(&settings.hostname);
|
|
|
|
let subject = lang.verify_email_subject(&settings.hostname);
|
|
|
@ -464,11 +468,11 @@ pub fn send_application_approved_email(
|
|
|
|
/// Send a new applicant email notification to all admins
|
|
|
|
/// Send a new applicant email notification to all admins
|
|
|
|
pub async fn send_new_applicant_email_to_admins(
|
|
|
|
pub async fn send_new_applicant_email_to_admins(
|
|
|
|
applicant_username: &str,
|
|
|
|
applicant_username: &str,
|
|
|
|
pool: &DbPool,
|
|
|
|
conn: &mut DbConn,
|
|
|
|
settings: &Settings,
|
|
|
|
settings: &Settings,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
// Collect the admins with emails
|
|
|
|
// Collect the admins with emails
|
|
|
|
let admins = LocalUserView::list_admins_with_emails(pool).await?;
|
|
|
|
let admins = LocalUserView::list_admins_with_emails(conn).await?;
|
|
|
|
|
|
|
|
|
|
|
|
let applications_link = &format!(
|
|
|
|
let applications_link = &format!(
|
|
|
|
"{}/registration_applications",
|
|
|
|
"{}/registration_applications",
|
|
|
@ -489,11 +493,11 @@ pub async fn send_new_applicant_email_to_admins(
|
|
|
|
pub async fn send_new_report_email_to_admins(
|
|
|
|
pub async fn send_new_report_email_to_admins(
|
|
|
|
reporter_username: &str,
|
|
|
|
reporter_username: &str,
|
|
|
|
reported_username: &str,
|
|
|
|
reported_username: &str,
|
|
|
|
pool: &DbPool,
|
|
|
|
conn: &mut DbConn,
|
|
|
|
settings: &Settings,
|
|
|
|
settings: &Settings,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
// Collect the admins with emails
|
|
|
|
// Collect the admins with emails
|
|
|
|
let admins = LocalUserView::list_admins_with_emails(pool).await?;
|
|
|
|
let admins = LocalUserView::list_admins_with_emails(conn).await?;
|
|
|
|
|
|
|
|
|
|
|
|
let reports_link = &format!("{}/reports", settings.get_protocol_and_hostname(),);
|
|
|
|
let reports_link = &format!("{}/reports", settings.get_protocol_and_hostname(),);
|
|
|
|
|
|
|
|
|
|
|
@ -510,7 +514,7 @@ pub async fn send_new_report_email_to_admins(
|
|
|
|
pub async fn check_registration_application(
|
|
|
|
pub async fn check_registration_application(
|
|
|
|
local_user_view: &LocalUserView,
|
|
|
|
local_user_view: &LocalUserView,
|
|
|
|
local_site: &LocalSite,
|
|
|
|
local_site: &LocalSite,
|
|
|
|
pool: &DbPool,
|
|
|
|
conn: &mut DbConn,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
if (local_site.registration_mode == RegistrationMode::RequireApplication
|
|
|
|
if (local_site.registration_mode == RegistrationMode::RequireApplication
|
|
|
|
|| local_site.registration_mode == RegistrationMode::Closed)
|
|
|
|
|| local_site.registration_mode == RegistrationMode::Closed)
|
|
|
@ -519,7 +523,7 @@ pub async fn check_registration_application(
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Fetch the registration, see if its denied
|
|
|
|
// Fetch the registration, see if its denied
|
|
|
|
let local_user_id = local_user_view.local_user.id;
|
|
|
|
let local_user_id = local_user_view.local_user.id;
|
|
|
|
let registration = RegistrationApplication::find_by_local_user_id(pool, local_user_id).await?;
|
|
|
|
let registration = RegistrationApplication::find_by_local_user_id(conn, local_user_id).await?;
|
|
|
|
if let Some(deny_reason) = registration.deny_reason {
|
|
|
|
if let Some(deny_reason) = registration.deny_reason {
|
|
|
|
let lang = get_interface_language(local_user_view);
|
|
|
|
let lang = get_interface_language(local_user_view);
|
|
|
|
let registration_denied_message = format!("{}: {}", lang.registration_denied(), &deny_reason);
|
|
|
|
let registration_denied_message = format!("{}: {}", lang.registration_denied(), &deny_reason);
|
|
|
@ -544,11 +548,11 @@ pub fn check_private_instance_and_federation_enabled(
|
|
|
|
|
|
|
|
|
|
|
|
pub async fn purge_image_posts_for_person(
|
|
|
|
pub async fn purge_image_posts_for_person(
|
|
|
|
banned_person_id: PersonId,
|
|
|
|
banned_person_id: PersonId,
|
|
|
|
pool: &DbPool,
|
|
|
|
conn: &mut DbConn,
|
|
|
|
settings: &Settings,
|
|
|
|
settings: &Settings,
|
|
|
|
client: &ClientWithMiddleware,
|
|
|
|
client: &ClientWithMiddleware,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
let posts = Post::fetch_pictrs_posts_for_creator(pool, banned_person_id).await?;
|
|
|
|
let posts = Post::fetch_pictrs_posts_for_creator(conn, banned_person_id).await?;
|
|
|
|
for post in posts {
|
|
|
|
for post in posts {
|
|
|
|
if let Some(url) = post.url {
|
|
|
|
if let Some(url) = post.url {
|
|
|
|
purge_image_from_pictrs(client, settings, &url).await.ok();
|
|
|
|
purge_image_from_pictrs(client, settings, &url).await.ok();
|
|
|
@ -560,18 +564,18 @@ pub async fn purge_image_posts_for_person(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Post::remove_pictrs_post_images_and_thumbnails_for_creator(pool, banned_person_id).await?;
|
|
|
|
Post::remove_pictrs_post_images_and_thumbnails_for_creator(conn, banned_person_id).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,
|
|
|
|
pool: &DbPool,
|
|
|
|
conn: &mut DbConn,
|
|
|
|
settings: &Settings,
|
|
|
|
settings: &Settings,
|
|
|
|
client: &ClientWithMiddleware,
|
|
|
|
client: &ClientWithMiddleware,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
let posts = Post::fetch_pictrs_posts_for_community(pool, banned_community_id).await?;
|
|
|
|
let posts = Post::fetch_pictrs_posts_for_community(conn, banned_community_id).await?;
|
|
|
|
for post in posts {
|
|
|
|
for post in posts {
|
|
|
|
if let Some(url) = post.url {
|
|
|
|
if let Some(url) = post.url {
|
|
|
|
purge_image_from_pictrs(client, settings, &url).await.ok();
|
|
|
|
purge_image_from_pictrs(client, settings, &url).await.ok();
|
|
|
@ -583,19 +587,19 @@ pub async fn purge_image_posts_for_community(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Post::remove_pictrs_post_images_and_thumbnails_for_community(pool, banned_community_id).await?;
|
|
|
|
Post::remove_pictrs_post_images_and_thumbnails_for_community(conn, banned_community_id).await?;
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub async fn remove_user_data(
|
|
|
|
pub async fn remove_user_data(
|
|
|
|
banned_person_id: PersonId,
|
|
|
|
banned_person_id: PersonId,
|
|
|
|
pool: &DbPool,
|
|
|
|
conn: &mut DbConn,
|
|
|
|
settings: &Settings,
|
|
|
|
settings: &Settings,
|
|
|
|
client: &ClientWithMiddleware,
|
|
|
|
client: &ClientWithMiddleware,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
// Purge user images
|
|
|
|
// Purge user images
|
|
|
|
let person = Person::read(pool, banned_person_id).await?;
|
|
|
|
let person = Person::read(conn, banned_person_id).await?;
|
|
|
|
if let Some(avatar) = person.avatar {
|
|
|
|
if let Some(avatar) = person.avatar {
|
|
|
|
purge_image_from_pictrs(client, settings, &avatar)
|
|
|
|
purge_image_from_pictrs(client, settings, &avatar)
|
|
|
|
.await
|
|
|
|
.await
|
|
|
@ -609,7 +613,7 @@ pub async fn remove_user_data(
|
|
|
|
|
|
|
|
|
|
|
|
// Update the fields to None
|
|
|
|
// Update the fields to None
|
|
|
|
Person::update(
|
|
|
|
Person::update(
|
|
|
|
pool,
|
|
|
|
conn,
|
|
|
|
banned_person_id,
|
|
|
|
banned_person_id,
|
|
|
|
&PersonUpdateForm::builder()
|
|
|
|
&PersonUpdateForm::builder()
|
|
|
|
.avatar(Some(None))
|
|
|
|
.avatar(Some(None))
|
|
|
@ -619,15 +623,15 @@ pub async fn remove_user_data(
|
|
|
|
.await?;
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
|
|
// Posts
|
|
|
|
// Posts
|
|
|
|
Post::update_removed_for_creator(pool, banned_person_id, None, true).await?;
|
|
|
|
Post::update_removed_for_creator(conn, banned_person_id, None, true).await?;
|
|
|
|
|
|
|
|
|
|
|
|
// Purge image posts
|
|
|
|
// Purge image posts
|
|
|
|
purge_image_posts_for_person(banned_person_id, pool, settings, client).await?;
|
|
|
|
purge_image_posts_for_person(banned_person_id, conn, settings, client).await?;
|
|
|
|
|
|
|
|
|
|
|
|
// Communities
|
|
|
|
// Communities
|
|
|
|
// Remove all communities where they're the top mod
|
|
|
|
// Remove all communities where they're the top mod
|
|
|
|
// for now, remove the communities manually
|
|
|
|
// for now, remove the communities manually
|
|
|
|
let first_mod_communities = CommunityModeratorView::get_community_first_mods(pool).await?;
|
|
|
|
let first_mod_communities = CommunityModeratorView::get_community_first_mods(conn).await?;
|
|
|
|
|
|
|
|
|
|
|
|
// Filter to only this banned users top communities
|
|
|
|
// Filter to only this banned users top communities
|
|
|
|
let banned_user_first_communities: Vec<CommunityModeratorView> = first_mod_communities
|
|
|
|
let banned_user_first_communities: Vec<CommunityModeratorView> = first_mod_communities
|
|
|
@ -638,7 +642,7 @@ pub async fn remove_user_data(
|
|
|
|
for first_mod_community in banned_user_first_communities {
|
|
|
|
for first_mod_community in banned_user_first_communities {
|
|
|
|
let community_id = first_mod_community.community.id;
|
|
|
|
let community_id = first_mod_community.community.id;
|
|
|
|
Community::update(
|
|
|
|
Community::update(
|
|
|
|
pool,
|
|
|
|
conn,
|
|
|
|
community_id,
|
|
|
|
community_id,
|
|
|
|
&CommunityUpdateForm::builder().removed(Some(true)).build(),
|
|
|
|
&CommunityUpdateForm::builder().removed(Some(true)).build(),
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -655,7 +659,7 @@ pub async fn remove_user_data(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Update the fields to None
|
|
|
|
// Update the fields to None
|
|
|
|
Community::update(
|
|
|
|
Community::update(
|
|
|
|
pool,
|
|
|
|
conn,
|
|
|
|
community_id,
|
|
|
|
community_id,
|
|
|
|
&CommunityUpdateForm::builder()
|
|
|
|
&CommunityUpdateForm::builder()
|
|
|
|
.icon(Some(None))
|
|
|
|
.icon(Some(None))
|
|
|
@ -666,7 +670,7 @@ pub async fn remove_user_data(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Comments
|
|
|
|
// Comments
|
|
|
|
Comment::update_removed_for_creator(pool, banned_person_id, true).await?;
|
|
|
|
Comment::update_removed_for_creator(conn, banned_person_id, true).await?;
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -674,15 +678,15 @@ pub async fn remove_user_data(
|
|
|
|
pub async fn remove_user_data_in_community(
|
|
|
|
pub async fn remove_user_data_in_community(
|
|
|
|
community_id: CommunityId,
|
|
|
|
community_id: CommunityId,
|
|
|
|
banned_person_id: PersonId,
|
|
|
|
banned_person_id: PersonId,
|
|
|
|
pool: &DbPool,
|
|
|
|
conn: &mut DbConn,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
// Posts
|
|
|
|
// Posts
|
|
|
|
Post::update_removed_for_creator(pool, banned_person_id, Some(community_id), true).await?;
|
|
|
|
Post::update_removed_for_creator(conn, banned_person_id, Some(community_id), true).await?;
|
|
|
|
|
|
|
|
|
|
|
|
// Comments
|
|
|
|
// Comments
|
|
|
|
// TODO Diesel doesn't allow updates with joins, so this has to be a loop
|
|
|
|
// TODO Diesel doesn't allow updates with joins, so this has to be a loop
|
|
|
|
let comments = CommentQuery::builder()
|
|
|
|
let comments = CommentQuery::builder()
|
|
|
|
.pool(pool)
|
|
|
|
.conn(conn)
|
|
|
|
.creator_id(Some(banned_person_id))
|
|
|
|
.creator_id(Some(banned_person_id))
|
|
|
|
.community_id(Some(community_id))
|
|
|
|
.community_id(Some(community_id))
|
|
|
|
.limit(Some(i64::MAX))
|
|
|
|
.limit(Some(i64::MAX))
|
|
|
@ -693,7 +697,7 @@ pub async fn remove_user_data_in_community(
|
|
|
|
for comment_view in &comments {
|
|
|
|
for comment_view in &comments {
|
|
|
|
let comment_id = comment_view.comment.id;
|
|
|
|
let comment_id = comment_view.comment.id;
|
|
|
|
Comment::update(
|
|
|
|
Comment::update(
|
|
|
|
pool,
|
|
|
|
conn,
|
|
|
|
comment_id,
|
|
|
|
comment_id,
|
|
|
|
&CommentUpdateForm::builder().removed(Some(true)).build(),
|
|
|
|
&CommentUpdateForm::builder().removed(Some(true)).build(),
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -705,12 +709,12 @@ pub async fn remove_user_data_in_community(
|
|
|
|
|
|
|
|
|
|
|
|
pub async fn delete_user_account(
|
|
|
|
pub async fn delete_user_account(
|
|
|
|
person_id: PersonId,
|
|
|
|
person_id: PersonId,
|
|
|
|
pool: &DbPool,
|
|
|
|
conn: &mut DbConn,
|
|
|
|
settings: &Settings,
|
|
|
|
settings: &Settings,
|
|
|
|
client: &ClientWithMiddleware,
|
|
|
|
client: &ClientWithMiddleware,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
// Delete their images
|
|
|
|
// Delete their images
|
|
|
|
let person = Person::read(pool, person_id).await?;
|
|
|
|
let person = Person::read(conn, person_id).await?;
|
|
|
|
if let Some(avatar) = person.avatar {
|
|
|
|
if let Some(avatar) = person.avatar {
|
|
|
|
purge_image_from_pictrs(client, settings, &avatar)
|
|
|
|
purge_image_from_pictrs(client, settings, &avatar)
|
|
|
|
.await
|
|
|
|
.await
|
|
|
@ -724,22 +728,22 @@ pub async fn delete_user_account(
|
|
|
|
// No need to update avatar and banner, those are handled in Person::delete_account
|
|
|
|
// No need to update avatar and banner, those are handled in Person::delete_account
|
|
|
|
|
|
|
|
|
|
|
|
// Comments
|
|
|
|
// Comments
|
|
|
|
Comment::permadelete_for_creator(pool, person_id)
|
|
|
|
Comment::permadelete_for_creator(conn, person_id)
|
|
|
|
.await
|
|
|
|
.await
|
|
|
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
|
|
|
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
|
|
|
|
|
|
|
|
|
|
|
|
// Posts
|
|
|
|
// Posts
|
|
|
|
Post::permadelete_for_creator(pool, person_id)
|
|
|
|
Post::permadelete_for_creator(conn, person_id)
|
|
|
|
.await
|
|
|
|
.await
|
|
|
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_post"))?;
|
|
|
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_post"))?;
|
|
|
|
|
|
|
|
|
|
|
|
// Purge image posts
|
|
|
|
// Purge image posts
|
|
|
|
purge_image_posts_for_person(person_id, pool, settings, client).await?;
|
|
|
|
purge_image_posts_for_person(person_id, conn, settings, client).await?;
|
|
|
|
|
|
|
|
|
|
|
|
// Leave communities they mod
|
|
|
|
// Leave communities they mod
|
|
|
|
CommunityModerator::leave_all_communities(pool, person_id).await?;
|
|
|
|
CommunityModerator::leave_all_communities(conn, person_id).await?;
|
|
|
|
|
|
|
|
|
|
|
|
Person::delete_account(pool, person_id).await?;
|
|
|
|
Person::delete_account(conn, person_id).await?;
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|