mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-10-01 01:36:12 -04:00
Compare commits
No commits in common. "7c43f4e86f756f78be98a897c82fadc64585d67f" and "3a4f67fa609771c23c2228dccbd2174649b5b528" have entirely different histories.
7c43f4e86f
...
3a4f67fa60
@ -5,7 +5,7 @@ use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
person::{BanPerson, BanPersonResponse},
|
||||
send_activity::{ActivityChannel, SendActivityData},
|
||||
utils::{check_expire_time, is_admin, remove_or_restore_user_data},
|
||||
utils::{check_expire_time, is_admin, remove_user_data, restore_user_data},
|
||||
};
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
@ -66,15 +66,11 @@ pub async fn ban_from_site(
|
||||
|
||||
// Remove their data if that's desired
|
||||
if data.remove_or_restore_data.unwrap_or(false) {
|
||||
let removed = data.ban;
|
||||
remove_or_restore_user_data(
|
||||
local_user_view.person.id,
|
||||
person.id,
|
||||
removed,
|
||||
&data.reason,
|
||||
&context,
|
||||
)
|
||||
.await?;
|
||||
if data.ban {
|
||||
remove_user_data(local_user_view.person.id, person.id, &data.reason, &context).await?;
|
||||
} else {
|
||||
restore_user_data(local_user_view.person.id, person.id, &data.reason, &context).await?;
|
||||
}
|
||||
};
|
||||
|
||||
// Mod tables
|
||||
|
@ -76,7 +76,5 @@ pub async fn leave_admin(
|
||||
admin_oauth_providers: None,
|
||||
blocked_urls,
|
||||
tagline,
|
||||
taglines: vec![],
|
||||
custom_emojis: vec![],
|
||||
}))
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ use serde_with::skip_serializing_none;
|
||||
use ts_rs::TS;
|
||||
use url::Url;
|
||||
|
||||
#[skip_serializing_none]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[cfg_attr(feature = "full", derive(TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
|
@ -306,8 +306,6 @@ pub struct EditSite {
|
||||
/// The response for a site.
|
||||
pub struct SiteResponse {
|
||||
pub site_view: SiteView,
|
||||
/// deprecated, use field `tagline` or /api/v3/tagline/list
|
||||
pub taglines: Vec<()>,
|
||||
}
|
||||
|
||||
#[skip_serializing_none]
|
||||
@ -322,10 +320,6 @@ pub struct GetSiteResponse {
|
||||
pub my_user: Option<MyUserInfo>,
|
||||
pub all_languages: Vec<Language>,
|
||||
pub discussion_languages: Vec<LanguageId>,
|
||||
/// deprecated, use field `tagline` or /api/v3/tagline/list
|
||||
pub taglines: Vec<()>,
|
||||
/// deprecated, use /api/v3/custom_emoji/list
|
||||
pub custom_emojis: Vec<()>,
|
||||
/// If the site has any taglines, a random one is included here for displaying
|
||||
pub tagline: Option<Tagline>,
|
||||
/// A list of external auth methods your site supports.
|
||||
|
@ -668,106 +668,139 @@ pub async fn purge_image_posts_for_community(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Removes or restores user data.
|
||||
pub async fn remove_or_restore_user_data(
|
||||
pub async fn remove_user_data(
|
||||
mod_person_id: PersonId,
|
||||
banned_person_id: PersonId,
|
||||
removed: bool,
|
||||
reason: &Option<String>,
|
||||
context: &LemmyContext,
|
||||
) -> LemmyResult<()> {
|
||||
let pool = &mut context.pool();
|
||||
let removed = true;
|
||||
|
||||
// Only these actions are possible when removing, not restoring
|
||||
if removed {
|
||||
// Purge user images
|
||||
let person = Person::read(pool, banned_person_id).await?;
|
||||
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();
|
||||
}
|
||||
// Purge user images
|
||||
let person = Person::read(pool, banned_person_id).await?;
|
||||
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();
|
||||
}
|
||||
|
||||
// Update the fields to None
|
||||
Person::update(
|
||||
// Update the fields to None
|
||||
Person::update(
|
||||
pool,
|
||||
banned_person_id,
|
||||
&PersonUpdateForm {
|
||||
avatar: Some(None),
|
||||
banner: Some(None),
|
||||
bio: Some(None),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Posts
|
||||
let removed_posts =
|
||||
Post::update_removed_for_creator(pool, banned_person_id, None, removed).await?;
|
||||
create_modlog_entries_for_removed_or_restored_posts(
|
||||
pool,
|
||||
mod_person_id,
|
||||
removed_posts.iter().map(|r| r.id).collect(),
|
||||
removed,
|
||||
reason,
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Purge image posts
|
||||
purge_image_posts_for_person(banned_person_id, context).await?;
|
||||
|
||||
// Comments
|
||||
let removed_comments =
|
||||
Comment::update_removed_for_creator(pool, banned_person_id, removed).await?;
|
||||
create_modlog_entries_for_removed_or_restored_comments(
|
||||
pool,
|
||||
mod_person_id,
|
||||
removed_comments.iter().map(|r| r.id).collect(),
|
||||
removed,
|
||||
reason,
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Communities
|
||||
// Remove all communities where they're the top mod
|
||||
// for now, remove the communities manually
|
||||
let first_mod_communities = CommunityModeratorView::get_community_first_mods(pool).await?;
|
||||
|
||||
// Filter to only this banned users top communities
|
||||
let banned_user_first_communities: Vec<CommunityModeratorView> = first_mod_communities
|
||||
.into_iter()
|
||||
.filter(|fmc| fmc.moderator.id == banned_person_id)
|
||||
.collect();
|
||||
|
||||
for first_mod_community in banned_user_first_communities {
|
||||
let community_id = first_mod_community.community.id;
|
||||
Community::update(
|
||||
pool,
|
||||
banned_person_id,
|
||||
&PersonUpdateForm {
|
||||
avatar: Some(None),
|
||||
banner: Some(None),
|
||||
bio: Some(None),
|
||||
community_id,
|
||||
&CommunityUpdateForm {
|
||||
removed: Some(removed),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Purge image posts
|
||||
purge_image_posts_for_person(banned_person_id, context).await?;
|
||||
|
||||
// Communities
|
||||
// Remove all communities where they're the top mod
|
||||
// for now, remove the communities manually
|
||||
let first_mod_communities = CommunityModeratorView::get_community_first_mods(pool).await?;
|
||||
|
||||
// Filter to only this banned users top communities
|
||||
let banned_user_first_communities: Vec<CommunityModeratorView> = first_mod_communities
|
||||
.into_iter()
|
||||
.filter(|fmc| fmc.moderator.id == banned_person_id)
|
||||
.collect();
|
||||
|
||||
for first_mod_community in banned_user_first_communities {
|
||||
let community_id = first_mod_community.community.id;
|
||||
Community::update(
|
||||
pool,
|
||||
community_id,
|
||||
&CommunityUpdateForm {
|
||||
removed: Some(removed),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Delete the community images
|
||||
if let Some(icon) = first_mod_community.community.icon {
|
||||
purge_image_from_pictrs(&icon, context).await.ok();
|
||||
}
|
||||
if let Some(banner) = first_mod_community.community.banner {
|
||||
purge_image_from_pictrs(&banner, context).await.ok();
|
||||
}
|
||||
// Update the fields to None
|
||||
Community::update(
|
||||
pool,
|
||||
community_id,
|
||||
&CommunityUpdateForm {
|
||||
icon: Some(None),
|
||||
banner: Some(None),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
// Delete the community images
|
||||
if let Some(icon) = first_mod_community.community.icon {
|
||||
purge_image_from_pictrs(&icon, context).await.ok();
|
||||
}
|
||||
if let Some(banner) = first_mod_community.community.banner {
|
||||
purge_image_from_pictrs(&banner, context).await.ok();
|
||||
}
|
||||
// Update the fields to None
|
||||
Community::update(
|
||||
pool,
|
||||
community_id,
|
||||
&CommunityUpdateForm {
|
||||
icon: Some(None),
|
||||
banner: Some(None),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// We can't restore their images, but we can unremove their posts and comments
|
||||
pub async fn restore_user_data(
|
||||
mod_person_id: PersonId,
|
||||
banned_person_id: PersonId,
|
||||
reason: &Option<String>,
|
||||
context: &LemmyContext,
|
||||
) -> LemmyResult<()> {
|
||||
let pool = &mut context.pool();
|
||||
let removed = false;
|
||||
|
||||
// Posts
|
||||
let removed_or_restored_posts =
|
||||
let restored_posts =
|
||||
Post::update_removed_for_creator(pool, banned_person_id, None, removed).await?;
|
||||
create_modlog_entries_for_removed_or_restored_posts(
|
||||
pool,
|
||||
mod_person_id,
|
||||
removed_or_restored_posts.iter().map(|r| r.id).collect(),
|
||||
restored_posts.iter().map(|r| r.id).collect(),
|
||||
removed,
|
||||
reason,
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Comments
|
||||
let removed_or_restored_comments =
|
||||
let restored_comments =
|
||||
Comment::update_removed_for_creator(pool, banned_person_id, removed).await?;
|
||||
create_modlog_entries_for_removed_or_restored_comments(
|
||||
pool,
|
||||
mod_person_id,
|
||||
removed_or_restored_comments.iter().map(|r| r.id).collect(),
|
||||
restored_comments.iter().map(|r| r.id).collect(),
|
||||
removed,
|
||||
reason,
|
||||
)
|
||||
@ -780,7 +813,7 @@ async fn create_modlog_entries_for_removed_or_restored_posts(
|
||||
pool: &mut DbPool<'_>,
|
||||
mod_person_id: PersonId,
|
||||
post_ids: Vec<PostId>,
|
||||
removed: bool,
|
||||
new_removed: bool,
|
||||
reason: &Option<String>,
|
||||
) -> LemmyResult<()> {
|
||||
// Build the forms
|
||||
@ -789,7 +822,7 @@ async fn create_modlog_entries_for_removed_or_restored_posts(
|
||||
.map(|&post_id| ModRemovePostForm {
|
||||
mod_person_id,
|
||||
post_id,
|
||||
removed: Some(removed),
|
||||
removed: Some(new_removed),
|
||||
reason: reason.clone(),
|
||||
})
|
||||
.collect();
|
||||
@ -803,7 +836,7 @@ async fn create_modlog_entries_for_removed_or_restored_comments(
|
||||
pool: &mut DbPool<'_>,
|
||||
mod_person_id: PersonId,
|
||||
comment_ids: Vec<CommentId>,
|
||||
removed: bool,
|
||||
new_removed: bool,
|
||||
reason: &Option<String>,
|
||||
) -> LemmyResult<()> {
|
||||
// Build the forms
|
||||
@ -812,7 +845,7 @@ async fn create_modlog_entries_for_removed_or_restored_comments(
|
||||
.map(|&comment_id| ModRemoveCommentForm {
|
||||
mod_person_id,
|
||||
comment_id,
|
||||
removed: Some(removed),
|
||||
removed: Some(new_removed),
|
||||
reason: reason.clone(),
|
||||
})
|
||||
.collect();
|
||||
@ -1283,10 +1316,9 @@ mod tests {
|
||||
let _inserted_comment_2 = Comment::create(pool, &comment_form_2, None).await?;
|
||||
|
||||
// Remove the user data
|
||||
remove_or_restore_user_data(
|
||||
remove_user_data(
|
||||
inserted_mod.id,
|
||||
inserted_person.id,
|
||||
true,
|
||||
&Some("a remove reason".to_string()),
|
||||
&context,
|
||||
)
|
||||
@ -1337,10 +1369,9 @@ mod tests {
|
||||
assert_eq!(vec![true, true], removed_comments);
|
||||
|
||||
// Now restore the content, and make sure it got appended
|
||||
remove_or_restore_user_data(
|
||||
restore_user_data(
|
||||
inserted_mod.id,
|
||||
inserted_person.id,
|
||||
false,
|
||||
&Some("a restore reason".to_string()),
|
||||
&context,
|
||||
)
|
||||
|
@ -139,10 +139,7 @@ pub async fn create_site(
|
||||
local_site_rate_limit_to_rate_limit_config(&site_view.local_site_rate_limit);
|
||||
context.rate_limit_cell().set_config(rate_limit_config);
|
||||
|
||||
Ok(Json(SiteResponse {
|
||||
site_view,
|
||||
taglines: vec![],
|
||||
}))
|
||||
Ok(Json(SiteResponse { site_view }))
|
||||
}
|
||||
|
||||
fn validate_create_payload(local_site: &LocalSite, create_site: &CreateSite) -> LemmyResult<()> {
|
||||
|
@ -59,8 +59,6 @@ pub async fn get_site(
|
||||
tagline,
|
||||
oauth_providers: Some(oauth_providers),
|
||||
admin_oauth_providers: Some(admin_oauth_providers),
|
||||
taglines: vec![],
|
||||
custom_emojis: vec![],
|
||||
})
|
||||
})
|
||||
.await
|
||||
|
@ -193,10 +193,7 @@ pub async fn update_site(
|
||||
local_site_rate_limit_to_rate_limit_config(&site_view.local_site_rate_limit);
|
||||
context.rate_limit_cell().set_config(rate_limit_config);
|
||||
|
||||
Ok(Json(SiteResponse {
|
||||
site_view,
|
||||
taglines: vec![],
|
||||
}))
|
||||
Ok(Json(SiteResponse { site_view }))
|
||||
}
|
||||
|
||||
fn validate_update_payload(local_site: &LocalSite, edit_site: &EditSite) -> LemmyResult<()> {
|
||||
|
@ -23,7 +23,7 @@ use anyhow::anyhow;
|
||||
use chrono::{DateTime, Utc};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
utils::{remove_or_restore_user_data, remove_or_restore_user_data_in_community},
|
||||
utils::{remove_or_restore_user_data_in_community, remove_user_data},
|
||||
};
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
@ -174,8 +174,7 @@ impl ActivityHandler for BlockUser {
|
||||
)
|
||||
.await?;
|
||||
if self.remove_data.unwrap_or(false) {
|
||||
remove_or_restore_user_data(mod_person.id, blocked_person.id, true, &reason, context)
|
||||
.await?;
|
||||
remove_user_data(mod_person.id, blocked_person.id, &reason, context).await?;
|
||||
}
|
||||
|
||||
// write mod log
|
||||
|
@ -19,7 +19,7 @@ use activitypub_federation::{
|
||||
};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
utils::{remove_or_restore_user_data, remove_or_restore_user_data_in_community},
|
||||
utils::{remove_or_restore_user_data_in_community, restore_user_data},
|
||||
};
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
@ -120,8 +120,7 @@ impl ActivityHandler for UndoBlockUser {
|
||||
.await?;
|
||||
|
||||
if self.restore_data.unwrap_or(false) {
|
||||
remove_or_restore_user_data(mod_person.id, blocked_person.id, false, &None, context)
|
||||
.await?;
|
||||
restore_user_data(mod_person.id, blocked_person.id, &None, context).await?;
|
||||
}
|
||||
|
||||
// write mod log
|
||||
|
@ -40,12 +40,12 @@ impl Comment {
|
||||
pub async fn update_removed_for_creator(
|
||||
pool: &mut DbPool<'_>,
|
||||
for_creator_id: PersonId,
|
||||
removed: bool,
|
||||
new_removed: bool,
|
||||
) -> Result<Vec<Self>, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(comment::table.filter(comment::creator_id.eq(for_creator_id)))
|
||||
.set((
|
||||
comment::removed.eq(removed),
|
||||
comment::removed.eq(new_removed),
|
||||
comment::updated.eq(naive_now()),
|
||||
))
|
||||
.get_results::<Self>(conn)
|
||||
|
@ -145,7 +145,7 @@ impl Post {
|
||||
pool: &mut DbPool<'_>,
|
||||
for_creator_id: PersonId,
|
||||
for_community_id: Option<CommunityId>,
|
||||
removed: bool,
|
||||
new_removed: bool,
|
||||
) -> Result<Vec<Self>, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
|
||||
@ -157,7 +157,7 @@ impl Post {
|
||||
}
|
||||
|
||||
update
|
||||
.set((post::removed.eq(removed), post::updated.eq(naive_now())))
|
||||
.set((post::removed.eq(new_removed), post::updated.eq(naive_now())))
|
||||
.get_results::<Self>(conn)
|
||||
.await
|
||||
}
|
||||
|
@ -769,7 +769,7 @@ diesel::table! {
|
||||
featured_local -> Bool,
|
||||
url_content_type -> Nullable<Text>,
|
||||
alt_text -> Nullable<Text>,
|
||||
scheduled_publish_time -> Nullable<Timestamptz>,
|
||||
scheduled_publish_time -> Nullable<Timestamptz>
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user