This commit is contained in:
Dessalines 2024-09-27 17:21:03 +02:00 committed by GitHub
commit 4e72088e9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 371 additions and 97 deletions

View File

@ -92,8 +92,10 @@ pub async fn ban_from_community(
let remove_data = data.ban; let remove_data = data.ban;
remove_or_restore_user_data_in_community( remove_or_restore_user_data_in_community(
data.community_id, data.community_id,
local_user_view.person.id,
banned_person_id, banned_person_id,
remove_data, remove_data,
&data.reason,
&mut context.pool(), &mut context.pool(),
) )
.await?; .await?;

View File

@ -67,9 +67,9 @@ pub async fn ban_from_site(
// Remove their data if that's desired // Remove their data if that's desired
if data.remove_or_restore_data.unwrap_or(false) { if data.remove_or_restore_data.unwrap_or(false) {
if data.ban { if data.ban {
remove_user_data(person.id, &context).await?; remove_user_data(local_user_view.person.id, person.id, &data.reason, &context).await?;
} else { } else {
restore_user_data(person.id, &context).await?; restore_user_data(local_user_view.person.id, person.id, &data.reason, &context).await?;
} }
}; };

View File

@ -11,7 +11,7 @@ use chrono::{DateTime, Days, Local, TimeZone, Utc};
use enum_map::{enum_map, EnumMap}; use enum_map::{enum_map, EnumMap};
use lemmy_db_schema::{ use lemmy_db_schema::{
aggregates::structs::{PersonPostAggregates, PersonPostAggregatesForm}, aggregates::structs::{PersonPostAggregates, PersonPostAggregatesForm},
newtypes::{CommunityId, DbUrl, InstanceId, PersonId, PostId}, newtypes::{CommentId, CommunityId, DbUrl, InstanceId, PersonId, PostId},
source::{ source::{
comment::{Comment, CommentUpdateForm}, comment::{Comment, CommentUpdateForm},
community::{Community, CommunityModerator, CommunityUpdateForm}, community::{Community, CommunityModerator, CommunityUpdateForm},
@ -23,6 +23,7 @@ use lemmy_db_schema::{
local_site::LocalSite, local_site::LocalSite,
local_site_rate_limit::LocalSiteRateLimit, local_site_rate_limit::LocalSiteRateLimit,
local_site_url_blocklist::LocalSiteUrlBlocklist, local_site_url_blocklist::LocalSiteUrlBlocklist,
moderator::{ModRemoveComment, ModRemoveCommentForm, ModRemovePost, ModRemovePostForm},
oauth_account::OAuthAccount, oauth_account::OAuthAccount,
password_reset_request::PasswordResetRequest, password_reset_request::PasswordResetRequest,
person::{Person, PersonUpdateForm}, person::{Person, PersonUpdateForm},
@ -668,10 +669,14 @@ pub async fn purge_image_posts_for_community(
} }
pub async fn remove_user_data( pub async fn remove_user_data(
mod_person_id: PersonId,
banned_person_id: PersonId, banned_person_id: PersonId,
reason: &Option<String>,
context: &LemmyContext, context: &LemmyContext,
) -> LemmyResult<()> { ) -> LemmyResult<()> {
let pool = &mut context.pool(); let pool = &mut context.pool();
let removed = true;
// Purge user images // Purge user images
let person = Person::read(pool, banned_person_id).await?; let person = Person::read(pool, banned_person_id).await?;
if let Some(avatar) = person.avatar { if let Some(avatar) = person.avatar {
@ -695,11 +700,32 @@ pub async fn remove_user_data(
.await?; .await?;
// Posts // Posts
Post::update_removed_for_creator(pool, banned_person_id, None, true).await?; 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
purge_image_posts_for_person(banned_person_id, context).await?; 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 // 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
@ -717,7 +743,7 @@ pub async fn remove_user_data(
pool, pool,
community_id, community_id,
&CommunityUpdateForm { &CommunityUpdateForm {
removed: Some(true), removed: Some(removed),
..Default::default() ..Default::default()
}, },
) )
@ -743,36 +769,111 @@ pub async fn remove_user_data(
.await?; .await?;
} }
// Comments
Comment::update_removed_for_creator(pool, banned_person_id, true).await?;
Ok(()) Ok(())
} }
/// We can't restore their images, but we can unremove their posts and comments /// We can't restore their images, but we can unremove their posts and comments
pub async fn restore_user_data( pub async fn restore_user_data(
mod_person_id: PersonId,
banned_person_id: PersonId, banned_person_id: PersonId,
reason: &Option<String>,
context: &LemmyContext, context: &LemmyContext,
) -> LemmyResult<()> { ) -> LemmyResult<()> {
let pool = &mut context.pool(); let pool = &mut context.pool();
let removed = false;
// Posts // Posts
Post::update_removed_for_creator(pool, banned_person_id, None, false).await?; 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,
restored_posts.iter().map(|r| r.id).collect(),
removed,
reason,
)
.await?;
// Comments // Comments
Comment::update_removed_for_creator(pool, banned_person_id, false).await?; 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,
restored_comments.iter().map(|r| r.id).collect(),
removed,
reason,
)
.await?;
Ok(())
}
async fn create_modlog_entries_for_removed_or_restored_posts(
pool: &mut DbPool<'_>,
mod_person_id: PersonId,
post_ids: Vec<PostId>,
new_removed: bool,
reason: &Option<String>,
) -> LemmyResult<()> {
// Build the forms
let forms = post_ids
.iter()
.map(|&post_id| ModRemovePostForm {
mod_person_id,
post_id,
removed: Some(new_removed),
reason: reason.clone(),
})
.collect();
ModRemovePost::create_multiple(pool, &forms).await?;
Ok(())
}
async fn create_modlog_entries_for_removed_or_restored_comments(
pool: &mut DbPool<'_>,
mod_person_id: PersonId,
comment_ids: Vec<CommentId>,
new_removed: bool,
reason: &Option<String>,
) -> LemmyResult<()> {
// Build the forms
let forms = comment_ids
.iter()
.map(|&comment_id| ModRemoveCommentForm {
mod_person_id,
comment_id,
removed: Some(new_removed),
reason: reason.clone(),
})
.collect();
ModRemoveComment::create_multiple(pool, &forms).await?;
Ok(()) Ok(())
} }
pub async fn remove_or_restore_user_data_in_community( pub async fn remove_or_restore_user_data_in_community(
community_id: CommunityId, community_id: CommunityId,
mod_person_id: PersonId,
banned_person_id: PersonId, banned_person_id: PersonId,
remove: bool, remove: bool,
reason: &Option<String>,
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
) -> LemmyResult<()> { ) -> LemmyResult<()> {
// Posts // Posts
Post::update_removed_for_creator(pool, banned_person_id, Some(community_id), remove).await?; let posts =
Post::update_removed_for_creator(pool, banned_person_id, Some(community_id), remove).await?;
create_modlog_entries_for_removed_or_restored_posts(
pool,
mod_person_id,
posts.iter().map(|r| r.id).collect(),
remove,
reason,
)
.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
@ -798,6 +899,15 @@ pub async fn remove_or_restore_user_data_in_community(
.await?; .await?;
} }
create_modlog_entries_for_removed_or_restored_comments(
pool,
mod_person_id,
comments.iter().map(|r| r.comment.id).collect(),
remove,
reason,
)
.await?;
Ok(()) Ok(())
} }
@ -1067,10 +1177,21 @@ fn build_proxied_image_url(
} }
#[cfg(test)] #[cfg(test)]
#[expect(clippy::unwrap_used)] #[allow(clippy::indexing_slicing)]
mod tests { mod tests {
use super::*; use super::*;
use lemmy_db_schema::source::{
comment::CommentInsertForm,
community::CommunityInsertForm,
person::PersonInsertForm,
post::PostInsertForm,
};
use lemmy_db_views_moderator::structs::{
ModRemoveCommentView,
ModRemovePostView,
ModlogListParams,
};
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
use serial_test::serial; use serial_test::serial;
@ -1092,48 +1213,42 @@ mod tests {
} }
#[test] #[test]
fn test_limit_ban_term() { fn test_limit_ban_term() -> LemmyResult<()> {
// Ban expires in past, should throw error // Ban expires in past, should throw error
assert!(limit_expire_time(Utc::now() - Days::new(5)).is_err()); assert!(limit_expire_time(Utc::now() - Days::new(5)).is_err());
// Legitimate ban term, return same value // Legitimate ban term, return same value
let fourteen_days = Utc::now() + Days::new(14); let fourteen_days = Utc::now() + Days::new(14);
assert_eq!( assert_eq!(limit_expire_time(fourteen_days)?, Some(fourteen_days));
limit_expire_time(fourteen_days).unwrap(),
Some(fourteen_days)
);
let nine_years = Utc::now() + Days::new(365 * 9); let nine_years = Utc::now() + Days::new(365 * 9);
assert_eq!(limit_expire_time(nine_years).unwrap(), Some(nine_years)); assert_eq!(limit_expire_time(nine_years)?, Some(nine_years));
// Too long ban term, changes to None (permanent ban) // Too long ban term, changes to None (permanent ban)
assert_eq!( assert_eq!(limit_expire_time(Utc::now() + Days::new(365 * 11))?, None);
limit_expire_time(Utc::now() + Days::new(365 * 11)).unwrap(),
None Ok(())
);
} }
#[tokio::test] #[tokio::test]
#[serial] #[serial]
async fn test_proxy_image_link() { async fn test_proxy_image_link() -> LemmyResult<()> {
let context = LemmyContext::init_test_context().await; let context = LemmyContext::init_test_context().await;
// image from local domain is unchanged // image from local domain is unchanged
let local_url = Url::parse("http://lemmy-alpha/image.png").unwrap(); let local_url = Url::parse("http://lemmy-alpha/image.png")?;
let proxied = let proxied =
proxy_image_link_internal(local_url.clone(), PictrsImageMode::ProxyAllImages, &context) proxy_image_link_internal(local_url.clone(), PictrsImageMode::ProxyAllImages, &context)
.await .await?;
.unwrap();
assert_eq!(&local_url, proxied.inner()); assert_eq!(&local_url, proxied.inner());
// image from remote domain is proxied // image from remote domain is proxied
let remote_image = Url::parse("http://lemmy-beta/image.png").unwrap(); let remote_image = Url::parse("http://lemmy-beta/image.png")?;
let proxied = proxy_image_link_internal( let proxied = proxy_image_link_internal(
remote_image.clone(), remote_image.clone(),
PictrsImageMode::ProxyAllImages, PictrsImageMode::ProxyAllImages,
&context, &context,
) )
.await .await?;
.unwrap();
assert_eq!( assert_eq!(
"https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Flemmy-beta%2Fimage.png", "https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Flemmy-beta%2Fimage.png",
proxied.as_str() proxied.as_str()
@ -1146,5 +1261,157 @@ mod tests {
.await .await
.is_ok() .is_ok()
); );
Ok(())
}
#[tokio::test]
#[serial]
async fn test_mod_remove_or_restore_data() -> LemmyResult<()> {
let context = LemmyContext::init_test_context().await;
let pool = &mut context.pool();
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?;
let new_mod = PersonInsertForm::test_form(inserted_instance.id, "modder");
let inserted_mod = Person::create(pool, &new_mod).await?;
let new_person = PersonInsertForm::test_form(inserted_instance.id, "chrimbus");
let inserted_person = Person::create(pool, &new_person).await?;
let new_community = CommunityInsertForm::new(
inserted_instance.id,
"mod_community crepes".to_string(),
"nada".to_owned(),
"pubkey".to_string(),
);
let inserted_community = Community::create(pool, &new_community).await?;
let post_form_1 = PostInsertForm::new(
"A test post tubular".into(),
inserted_person.id,
inserted_community.id,
);
let inserted_post_1 = Post::create(pool, &post_form_1).await?;
let post_form_2 = PostInsertForm::new(
"A test post radical".into(),
inserted_person.id,
inserted_community.id,
);
let inserted_post_2 = Post::create(pool, &post_form_2).await?;
let comment_form_1 = CommentInsertForm::new(
inserted_person.id,
inserted_post_1.id,
"A test comment tubular".into(),
);
let _inserted_comment_1 = Comment::create(pool, &comment_form_1, None).await?;
let comment_form_2 = CommentInsertForm::new(
inserted_person.id,
inserted_post_2.id,
"A test comment radical".into(),
);
let _inserted_comment_2 = Comment::create(pool, &comment_form_2, None).await?;
// Remove the user data
remove_user_data(
inserted_mod.id,
inserted_person.id,
&Some("a remove reason".to_string()),
&context,
)
.await?;
// Verify that their posts and comments are removed.
let params = ModlogListParams {
community_id: None,
mod_person_id: None,
other_person_id: None,
post_id: None,
comment_id: None,
page: None,
limit: None,
hide_modlog_names: false,
};
// Posts
let post_modlog = ModRemovePostView::list(pool, params).await?;
assert_eq!(2, post_modlog.len());
let mod_removed_posts = post_modlog
.iter()
.map(|p| p.mod_remove_post.removed)
.collect::<Vec<bool>>();
assert_eq!(vec![true, true], mod_removed_posts);
let removed_posts = post_modlog
.iter()
.map(|p| p.post.removed)
.collect::<Vec<bool>>();
assert_eq!(vec![true, true], removed_posts);
// Comments
let comment_modlog = ModRemoveCommentView::list(pool, params).await?;
assert_eq!(2, comment_modlog.len());
let mod_removed_comments = comment_modlog
.iter()
.map(|p| p.mod_remove_comment.removed)
.collect::<Vec<bool>>();
assert_eq!(vec![true, true], mod_removed_comments);
let removed_comments = comment_modlog
.iter()
.map(|p| p.comment.removed)
.collect::<Vec<bool>>();
assert_eq!(vec![true, true], removed_comments);
// Now restore the content, and make sure it got appended
restore_user_data(
inserted_mod.id,
inserted_person.id,
&Some("a restore reason".to_string()),
&context,
)
.await?;
// Posts
let post_modlog = ModRemovePostView::list(pool, params).await?;
assert_eq!(4, post_modlog.len());
let mod_restored_posts = post_modlog
.iter()
.map(|p| p.mod_remove_post.removed)
.collect::<Vec<bool>>();
assert_eq!(vec![false, false, true, true], mod_restored_posts);
let restored_posts = post_modlog
.iter()
.map(|p| p.post.removed)
.collect::<Vec<bool>>();
// All of these will be false, cause its the current state of the post
assert_eq!(vec![false, false, false, false], restored_posts);
// Comments
let comment_modlog = ModRemoveCommentView::list(pool, params).await?;
assert_eq!(4, comment_modlog.len());
let mod_restored_comments = comment_modlog
.iter()
.map(|p| p.mod_remove_comment.removed)
.collect::<Vec<bool>>();
assert_eq!(vec![false, false, true, true], mod_restored_comments);
let restored_comments = comment_modlog
.iter()
.map(|p| p.comment.removed)
.collect::<Vec<bool>>();
assert_eq!(vec![false, false, false, false], restored_comments);
Instance::delete(pool, inserted_instance.id).await?;
Ok(())
} }
} }

View File

@ -160,6 +160,7 @@ impl ActivityHandler for BlockUser {
let mod_person = self.actor.dereference(context).await?; let mod_person = self.actor.dereference(context).await?;
let blocked_person = self.object.dereference(context).await?; let blocked_person = self.object.dereference(context).await?;
let target = self.target.dereference(context).await?; let target = self.target.dereference(context).await?;
let reason = self.summary;
match target { match target {
SiteOrCommunity::Site(_site) => { SiteOrCommunity::Site(_site) => {
let blocked_person = Person::update( let blocked_person = Person::update(
@ -173,14 +174,14 @@ impl ActivityHandler for BlockUser {
) )
.await?; .await?;
if self.remove_data.unwrap_or(false) { if self.remove_data.unwrap_or(false) {
remove_user_data(blocked_person.id, context).await?; remove_user_data(mod_person.id, blocked_person.id, &reason, context).await?;
} }
// write mod log // write mod log
let form = ModBanForm { let form = ModBanForm {
mod_person_id: mod_person.id, mod_person_id: mod_person.id,
other_person_id: blocked_person.id, other_person_id: blocked_person.id,
reason: self.summary, reason,
banned: Some(true), banned: Some(true),
expires, expires,
}; };
@ -207,8 +208,10 @@ impl ActivityHandler for BlockUser {
if self.remove_data.unwrap_or(false) { if self.remove_data.unwrap_or(false) {
remove_or_restore_user_data_in_community( remove_or_restore_user_data_in_community(
community.id, community.id,
mod_person.id,
blocked_person.id, blocked_person.id,
true, true,
&reason,
&mut context.pool(), &mut context.pool(),
) )
.await?; .await?;
@ -219,7 +222,7 @@ impl ActivityHandler for BlockUser {
mod_person_id: mod_person.id, mod_person_id: mod_person.id,
other_person_id: blocked_person.id, other_person_id: blocked_person.id,
community_id: community.id, community_id: community.id,
reason: self.summary, reason,
banned: Some(true), banned: Some(true),
expires, expires,
}; };

View File

@ -120,7 +120,7 @@ impl ActivityHandler for UndoBlockUser {
.await?; .await?;
if self.restore_data.unwrap_or(false) { if self.restore_data.unwrap_or(false) {
restore_user_data(blocked_person.id, context).await?; restore_user_data(mod_person.id, blocked_person.id, &None, context).await?;
} }
// write mod log // write mod log
@ -144,8 +144,10 @@ impl ActivityHandler for UndoBlockUser {
if self.restore_data.unwrap_or(false) { if self.restore_data.unwrap_or(false) {
remove_or_restore_user_data_in_community( remove_or_restore_user_data_in_community(
community.id, community.id,
mod_person.id,
blocked_person.id, blocked_person.id,
false, false,
&None,
&mut context.pool(), &mut context.pool(),
) )
.await?; .await?;

View File

@ -66,6 +66,20 @@ impl Crud for ModRemovePost {
} }
} }
impl ModRemovePost {
pub async fn create_multiple(
pool: &mut DbPool<'_>,
forms: &Vec<ModRemovePostForm>,
) -> Result<usize, Error> {
use crate::schema::mod_remove_post::dsl::mod_remove_post;
let conn = &mut get_conn(pool).await?;
insert_into(mod_remove_post)
.values(forms)
.execute(conn)
.await
}
}
#[async_trait] #[async_trait]
impl Crud for ModLockPost { impl Crud for ModLockPost {
type InsertForm = ModLockPostForm; type InsertForm = ModLockPostForm;
@ -153,6 +167,20 @@ impl Crud for ModRemoveComment {
} }
} }
impl ModRemoveComment {
pub async fn create_multiple(
pool: &mut DbPool<'_>,
forms: &Vec<ModRemoveCommentForm>,
) -> Result<usize, Error> {
use crate::schema::mod_remove_comment::dsl::mod_remove_comment;
let conn = &mut get_conn(pool).await?;
insert_into(mod_remove_comment)
.values(forms)
.execute(conn)
.await
}
}
#[async_trait] #[async_trait]
impl Crud for ModRemoveCommunity { impl Crud for ModRemoveCommunity {
type InsertForm = ModRemoveCommunityForm; type InsertForm = ModRemoveCommunityForm;
@ -465,7 +493,6 @@ impl Crud for AdminPurgeComment {
} }
#[cfg(test)] #[cfg(test)]
#[expect(clippy::unwrap_used)]
mod tests { mod tests {
use crate::{ use crate::{
@ -499,26 +526,25 @@ mod tests {
traits::Crud, traits::Crud,
utils::build_db_pool_for_tests, utils::build_db_pool_for_tests,
}; };
use diesel::result::Error;
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
use serial_test::serial; use serial_test::serial;
#[tokio::test] #[tokio::test]
#[serial] #[serial]
async fn test_crud() { async fn test_crud() -> Result<(), Error> {
let pool = &build_db_pool_for_tests().await; let pool = &build_db_pool_for_tests().await;
let pool = &mut pool.into(); let pool = &mut pool.into();
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()) let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?;
.await
.unwrap();
let new_mod = PersonInsertForm::test_form(inserted_instance.id, "the mod"); let new_mod = PersonInsertForm::test_form(inserted_instance.id, "the mod");
let inserted_mod = Person::create(pool, &new_mod).await.unwrap(); let inserted_mod = Person::create(pool, &new_mod).await?;
let new_person = PersonInsertForm::test_form(inserted_instance.id, "jim2"); let new_person = PersonInsertForm::test_form(inserted_instance.id, "jim2");
let inserted_person = Person::create(pool, &new_person).await.unwrap(); let inserted_person = Person::create(pool, &new_person).await?;
let new_community = CommunityInsertForm::new( let new_community = CommunityInsertForm::new(
inserted_instance.id, inserted_instance.id,
@ -527,21 +553,21 @@ mod tests {
"pubkey".to_string(), "pubkey".to_string(),
); );
let inserted_community = Community::create(pool, &new_community).await.unwrap(); let inserted_community = Community::create(pool, &new_community).await?;
let new_post = PostInsertForm::new( let new_post = PostInsertForm::new(
"A test post thweep".into(), "A test post thweep".into(),
inserted_person.id, inserted_person.id,
inserted_community.id, inserted_community.id,
); );
let inserted_post = Post::create(pool, &new_post).await.unwrap(); let inserted_post = Post::create(pool, &new_post).await?;
let comment_form = CommentInsertForm::new( let comment_form = CommentInsertForm::new(
inserted_person.id, inserted_person.id,
inserted_post.id, inserted_post.id,
"A test comment".into(), "A test comment".into(),
); );
let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap(); let inserted_comment = Comment::create(pool, &comment_form, None).await?;
// Now the actual tests // Now the actual tests
@ -552,12 +578,8 @@ mod tests {
reason: None, reason: None,
removed: None, removed: None,
}; };
let inserted_mod_remove_post = ModRemovePost::create(pool, &mod_remove_post_form) let inserted_mod_remove_post = ModRemovePost::create(pool, &mod_remove_post_form).await?;
.await let read_mod_remove_post = ModRemovePost::read(pool, inserted_mod_remove_post.id).await?;
.unwrap();
let read_mod_remove_post = ModRemovePost::read(pool, inserted_mod_remove_post.id)
.await
.unwrap();
let expected_mod_remove_post = ModRemovePost { let expected_mod_remove_post = ModRemovePost {
id: inserted_mod_remove_post.id, id: inserted_mod_remove_post.id,
post_id: inserted_post.id, post_id: inserted_post.id,
@ -574,12 +596,8 @@ mod tests {
post_id: inserted_post.id, post_id: inserted_post.id,
locked: None, locked: None,
}; };
let inserted_mod_lock_post = ModLockPost::create(pool, &mod_lock_post_form) let inserted_mod_lock_post = ModLockPost::create(pool, &mod_lock_post_form).await?;
.await let read_mod_lock_post = ModLockPost::read(pool, inserted_mod_lock_post.id).await?;
.unwrap();
let read_mod_lock_post = ModLockPost::read(pool, inserted_mod_lock_post.id)
.await
.unwrap();
let expected_mod_lock_post = ModLockPost { let expected_mod_lock_post = ModLockPost {
id: inserted_mod_lock_post.id, id: inserted_mod_lock_post.id,
post_id: inserted_post.id, post_id: inserted_post.id,
@ -596,12 +614,8 @@ mod tests {
featured: false, featured: false,
is_featured_community: true, is_featured_community: true,
}; };
let inserted_mod_feature_post = ModFeaturePost::create(pool, &mod_feature_post_form) let inserted_mod_feature_post = ModFeaturePost::create(pool, &mod_feature_post_form).await?;
.await let read_mod_feature_post = ModFeaturePost::read(pool, inserted_mod_feature_post.id).await?;
.unwrap();
let read_mod_feature_post = ModFeaturePost::read(pool, inserted_mod_feature_post.id)
.await
.unwrap();
let expected_mod_feature_post = ModFeaturePost { let expected_mod_feature_post = ModFeaturePost {
id: inserted_mod_feature_post.id, id: inserted_mod_feature_post.id,
post_id: inserted_post.id, post_id: inserted_post.id,
@ -619,12 +633,10 @@ mod tests {
reason: None, reason: None,
removed: None, removed: None,
}; };
let inserted_mod_remove_comment = ModRemoveComment::create(pool, &mod_remove_comment_form) let inserted_mod_remove_comment =
.await ModRemoveComment::create(pool, &mod_remove_comment_form).await?;
.unwrap(); let read_mod_remove_comment =
let read_mod_remove_comment = ModRemoveComment::read(pool, inserted_mod_remove_comment.id) ModRemoveComment::read(pool, inserted_mod_remove_comment.id).await?;
.await
.unwrap();
let expected_mod_remove_comment = ModRemoveComment { let expected_mod_remove_comment = ModRemoveComment {
id: inserted_mod_remove_comment.id, id: inserted_mod_remove_comment.id,
comment_id: inserted_comment.id, comment_id: inserted_comment.id,
@ -643,13 +655,9 @@ mod tests {
removed: None, removed: None,
}; };
let inserted_mod_remove_community = let inserted_mod_remove_community =
ModRemoveCommunity::create(pool, &mod_remove_community_form) ModRemoveCommunity::create(pool, &mod_remove_community_form).await?;
.await
.unwrap();
let read_mod_remove_community = let read_mod_remove_community =
ModRemoveCommunity::read(pool, inserted_mod_remove_community.id) ModRemoveCommunity::read(pool, inserted_mod_remove_community.id).await?;
.await
.unwrap();
let expected_mod_remove_community = ModRemoveCommunity { let expected_mod_remove_community = ModRemoveCommunity {
id: inserted_mod_remove_community.id, id: inserted_mod_remove_community.id,
community_id: inserted_community.id, community_id: inserted_community.id,
@ -670,13 +678,9 @@ mod tests {
expires: None, expires: None,
}; };
let inserted_mod_ban_from_community = let inserted_mod_ban_from_community =
ModBanFromCommunity::create(pool, &mod_ban_from_community_form) ModBanFromCommunity::create(pool, &mod_ban_from_community_form).await?;
.await
.unwrap();
let read_mod_ban_from_community = let read_mod_ban_from_community =
ModBanFromCommunity::read(pool, inserted_mod_ban_from_community.id) ModBanFromCommunity::read(pool, inserted_mod_ban_from_community.id).await?;
.await
.unwrap();
let expected_mod_ban_from_community = ModBanFromCommunity { let expected_mod_ban_from_community = ModBanFromCommunity {
id: inserted_mod_ban_from_community.id, id: inserted_mod_ban_from_community.id,
community_id: inserted_community.id, community_id: inserted_community.id,
@ -697,8 +701,8 @@ mod tests {
banned: None, banned: None,
expires: None, expires: None,
}; };
let inserted_mod_ban = ModBan::create(pool, &mod_ban_form).await.unwrap(); let inserted_mod_ban = ModBan::create(pool, &mod_ban_form).await?;
let read_mod_ban = ModBan::read(pool, inserted_mod_ban.id).await.unwrap(); let read_mod_ban = ModBan::read(pool, inserted_mod_ban.id).await?;
let expected_mod_ban = ModBan { let expected_mod_ban = ModBan {
id: inserted_mod_ban.id, id: inserted_mod_ban.id,
mod_person_id: inserted_mod.id, mod_person_id: inserted_mod.id,
@ -717,12 +721,8 @@ mod tests {
community_id: inserted_community.id, community_id: inserted_community.id,
removed: None, removed: None,
}; };
let inserted_mod_add_community = ModAddCommunity::create(pool, &mod_add_community_form) let inserted_mod_add_community = ModAddCommunity::create(pool, &mod_add_community_form).await?;
.await let read_mod_add_community = ModAddCommunity::read(pool, inserted_mod_add_community.id).await?;
.unwrap();
let read_mod_add_community = ModAddCommunity::read(pool, inserted_mod_add_community.id)
.await
.unwrap();
let expected_mod_add_community = ModAddCommunity { let expected_mod_add_community = ModAddCommunity {
id: inserted_mod_add_community.id, id: inserted_mod_add_community.id,
community_id: inserted_community.id, community_id: inserted_community.id,
@ -739,8 +739,8 @@ mod tests {
other_person_id: inserted_person.id, other_person_id: inserted_person.id,
removed: None, removed: None,
}; };
let inserted_mod_add = ModAdd::create(pool, &mod_add_form).await.unwrap(); let inserted_mod_add = ModAdd::create(pool, &mod_add_form).await?;
let read_mod_add = ModAdd::read(pool, inserted_mod_add.id).await.unwrap(); let read_mod_add = ModAdd::read(pool, inserted_mod_add.id).await?;
let expected_mod_add = ModAdd { let expected_mod_add = ModAdd {
id: inserted_mod_add.id, id: inserted_mod_add.id,
mod_person_id: inserted_mod.id, mod_person_id: inserted_mod.id,
@ -749,14 +749,12 @@ mod tests {
when_: inserted_mod_add.when_, when_: inserted_mod_add.when_,
}; };
Comment::delete(pool, inserted_comment.id).await.unwrap(); Comment::delete(pool, inserted_comment.id).await?;
Post::delete(pool, inserted_post.id).await.unwrap(); Post::delete(pool, inserted_post.id).await?;
Community::delete(pool, inserted_community.id) Community::delete(pool, inserted_community.id).await?;
.await Person::delete(pool, inserted_person.id).await?;
.unwrap(); Person::delete(pool, inserted_mod.id).await?;
Person::delete(pool, inserted_person.id).await.unwrap(); Instance::delete(pool, inserted_instance.id).await?;
Person::delete(pool, inserted_mod.id).await.unwrap();
Instance::delete(pool, inserted_instance.id).await.unwrap();
assert_eq!(expected_mod_remove_post, read_mod_remove_post); assert_eq!(expected_mod_remove_post, read_mod_remove_post);
assert_eq!(expected_mod_lock_post, read_mod_lock_post); assert_eq!(expected_mod_lock_post, read_mod_lock_post);
@ -767,5 +765,7 @@ mod tests {
assert_eq!(expected_mod_ban, read_mod_ban); assert_eq!(expected_mod_ban, read_mod_ban);
assert_eq!(expected_mod_add_community, read_mod_add_community); assert_eq!(expected_mod_add_community, read_mod_add_community);
assert_eq!(expected_mod_add, read_mod_add); assert_eq!(expected_mod_add, read_mod_add);
Ok(())
} }
} }