diff --git a/crates/api/api/src/community/add_mod.rs b/crates/api/api/src/community/add_mod.rs index 73fc2d0ad..b36bd6229 100644 --- a/crates/api/api/src/community/add_mod.rs +++ b/crates/api/api/src/community/add_mod.rs @@ -10,7 +10,7 @@ use lemmy_db_schema::{ source::{ community::{Community, CommunityActions, CommunityModeratorForm}, local_user::LocalUser, - mod_log::moderator::{ModAddCommunity, ModAddCommunityForm}, + mod_log::moderator::{ModAddToCommunity, ModAddToCommunityForm}, }, traits::Crud, utils::get_conn, @@ -68,14 +68,14 @@ pub async fn add_mod_to_community( } // Mod tables - let form = ModAddCommunityForm { + let form = ModAddToCommunityForm { mod_person_id: local_user_view.person.id, other_person_id: tx_data.person_id, community_id: tx_data.community_id, removed: Some(!tx_data.added), }; - ModAddCommunity::create(&mut conn.into(), &form).await?; + ModAddToCommunity::create(&mut conn.into(), &form).await?; Ok(()) } diff --git a/crates/api/api/src/local_user/add_admin.rs b/crates/api/api/src/local_user/add_admin.rs index c59504d68..b56c236b3 100644 --- a/crates/api/api/src/local_user/add_admin.rs +++ b/crates/api/api/src/local_user/add_admin.rs @@ -3,7 +3,7 @@ use lemmy_api_utils::{context::LemmyContext, utils::is_admin}; use lemmy_db_schema::{ source::{ local_user::{LocalUser, LocalUserUpdateForm}, - mod_log::moderator::{ModAdd, ModAddForm}, + mod_log::admin::{AdminAdd, AdminAddForm}, }, traits::Crud, }; @@ -44,13 +44,13 @@ pub async fn add_admin( .await?; // Mod tables - let form = ModAddForm { + let form = AdminAddForm { mod_person_id: my_person_id, other_person_id: added_local_user.person.id, removed: Some(!data.added), }; - ModAdd::create(&mut context.pool(), &form).await?; + AdminAdd::create(&mut context.pool(), &form).await?; let admins = PersonQuery { admins_only: Some(true), diff --git a/crates/api/api/src/local_user/ban_person.rs b/crates/api/api/src/local_user/ban_person.rs index 91706b1ce..9519bcfdd 100644 --- a/crates/api/api/src/local_user/ban_person.rs +++ b/crates/api/api/src/local_user/ban_person.rs @@ -9,7 +9,7 @@ use lemmy_db_schema::{ source::{ instance::{InstanceActions, InstanceBanForm}, local_user::LocalUser, - mod_log::moderator::{ModBan, ModBanForm}, + mod_log::admin::{AdminBan, AdminBanForm}, }, traits::{Bannable, Crud}, }; @@ -65,7 +65,7 @@ pub async fn ban_from_site( }; // Mod tables - let form = ModBanForm { + let form = AdminBanForm { mod_person_id: my_person_id, other_person_id: data.person_id, reason: data.reason.clone(), @@ -74,7 +74,7 @@ pub async fn ban_from_site( instance_id: local_user_view.person.instance_id, }; - ModBan::create(&mut context.pool(), &form).await?; + AdminBan::create(&mut context.pool(), &form).await?; let person_view = PersonView::read( &mut context.pool(), diff --git a/crates/api/api/src/site/leave_admin.rs b/crates/api/api/src/site/leave_admin.rs index ec3f620e8..941edb080 100644 --- a/crates/api/api/src/site/leave_admin.rs +++ b/crates/api/api/src/site/leave_admin.rs @@ -6,7 +6,7 @@ use lemmy_db_schema::{ language::Language, local_site_url_blocklist::LocalSiteUrlBlocklist, local_user::{LocalUser, LocalUserUpdateForm}, - mod_log::moderator::{ModAdd, ModAddForm}, + mod_log::admin::{AdminAdd, AdminAddForm}, oauth_provider::OAuthProvider, tagline::Tagline, }, @@ -57,13 +57,13 @@ pub async fn leave_admin( .await?; // Mod tables - let form = ModAddForm { + let form = AdminAddForm { mod_person_id: my_person_id, other_person_id: my_person_id, removed: Some(true), }; - ModAdd::create(&mut context.pool(), &form).await?; + AdminAdd::create(&mut context.pool(), &form).await?; // Reread site and admins let site_view = SiteView::read_local(&mut context.pool()).await?; diff --git a/crates/api/api_common/src/modlog.rs b/crates/api/api_common/src/modlog.rs index 0bd7bab8c..5e0a3626e 100644 --- a/crates/api/api_common/src/modlog.rs +++ b/crates/api/api_common/src/modlog.rs @@ -1,20 +1,20 @@ pub use lemmy_db_schema::{ newtypes::{ + AdminAddId, AdminAllowInstanceId, + AdminBanId, AdminBlockInstanceId, AdminPurgeCommentId, AdminPurgeCommunityId, AdminPurgePersonId, AdminPurgePostId, - ModAddCommunityId, - ModAddId, + AdminRemoveCommunityId, + ModAddToCommunityId, ModBanFromCommunityId, - ModBanId, ModChangeCommunityVisibilityId, ModFeaturePostId, ModLockPostId, ModRemoveCommentId, - ModRemoveCommunityId, ModRemovePostId, ModTransferCommunityId, ModlogCombinedId, @@ -23,23 +23,23 @@ pub use lemmy_db_schema::{ combined::modlog::ModlogCombined, mod_log::{ admin::{ + AdminAdd, AdminAllowInstance, + AdminBan, AdminBlockInstance, AdminPurgeComment, AdminPurgeCommunity, AdminPurgePerson, AdminPurgePost, + AdminRemoveCommunity, }, moderator::{ - ModAdd, - ModAddCommunity, - ModBan, + ModAddToCommunity, ModBanFromCommunity, ModChangeCommunityVisibility, ModFeaturePost, ModLockPost, ModRemoveComment, - ModRemoveCommunity, ModRemovePost, ModTransferCommunity, }, @@ -49,21 +49,21 @@ pub use lemmy_db_schema::{ }; pub use lemmy_db_views_modlog_combined::{ api::{GetModlog, GetModlogResponse}, + AdminAddView, AdminAllowInstanceView, + AdminBanView, AdminBlockInstanceView, AdminPurgeCommentView, AdminPurgeCommunityView, AdminPurgePersonView, AdminPurgePostView, - ModAddCommunityView, - ModAddView, + AdminRemoveCommunityView, + ModAddToCommunityView, ModBanFromCommunityView, - ModBanView, ModChangeCommunityVisibilityView, ModFeaturePostView, ModLockPostView, ModRemoveCommentView, - ModRemoveCommunityView, ModRemovePostView, ModTransferCommunityView, ModlogCombinedView, diff --git a/crates/api/api_crud/src/community/remove.rs b/crates/api/api_crud/src/community/remove.rs index 34119f2c6..8af15286a 100644 --- a/crates/api/api_crud/src/community/remove.rs +++ b/crates/api/api_crud/src/community/remove.rs @@ -10,7 +10,7 @@ use lemmy_db_schema::{ source::{ community::{Community, CommunityUpdateForm}, community_report::CommunityReport, - mod_log::moderator::{ModRemoveCommunity, ModRemoveCommunityForm}, + mod_log::admin::{AdminRemoveCommunity, AdminRemoveCommunityForm}, }, traits::{Crud, Reportable}, }; @@ -50,13 +50,13 @@ pub async fn remove_community( .await?; // Mod tables - let form = ModRemoveCommunityForm { + let form = AdminRemoveCommunityForm { mod_person_id: local_user_view.person.id, community_id: data.community_id, removed: Some(removed), reason: data.reason.clone(), }; - ModRemoveCommunity::create(&mut context.pool(), &form).await?; + AdminRemoveCommunity::create(&mut context.pool(), &form).await?; ActivityChannel::submit_activity( SendActivityData::RemoveCommunity { diff --git a/crates/apub/src/activities/block/block_user.rs b/crates/apub/src/activities/block/block_user.rs index 72bc6bd57..756d46be9 100644 --- a/crates/apub/src/activities/block/block_user.rs +++ b/crates/apub/src/activities/block/block_user.rs @@ -33,7 +33,10 @@ use lemmy_db_schema::{ activity::ActivitySendTargets, community::{CommunityActions, CommunityPersonBanForm}, instance::{InstanceActions, InstanceBanForm}, - mod_log::moderator::{ModBan, ModBanForm, ModBanFromCommunity, ModBanFromCommunityForm}, + mod_log::{ + admin::{AdminBan, AdminBanForm}, + moderator::{ModBanFromCommunity, ModBanFromCommunityForm}, + }, }, traits::{Bannable, Crud}, }; @@ -149,7 +152,7 @@ impl Activity for BlockUser { } // write mod log - let form = ModBanForm { + let form = AdminBanForm { mod_person_id: mod_person.id, other_person_id: blocked_person.id, reason, @@ -157,7 +160,7 @@ impl Activity for BlockUser { expires_at, instance_id: site.instance_id, }; - ModBan::create(&mut context.pool(), &form).await?; + AdminBan::create(&mut context.pool(), &form).await?; } SiteOrCommunity::Right(community) => { let community_user_ban_form = CommunityPersonBanForm { diff --git a/crates/apub/src/activities/block/undo_block_user.rs b/crates/apub/src/activities/block/undo_block_user.rs index 90ccdd883..3cbf9ef99 100644 --- a/crates/apub/src/activities/block/undo_block_user.rs +++ b/crates/apub/src/activities/block/undo_block_user.rs @@ -28,7 +28,10 @@ use lemmy_db_schema::{ activity::ActivitySendTargets, community::{CommunityActions, CommunityPersonBanForm}, instance::{InstanceActions, InstanceBanForm}, - mod_log::moderator::{ModBan, ModBanForm, ModBanFromCommunity, ModBanFromCommunityForm}, + mod_log::{ + admin::{AdminBan, AdminBanForm}, + moderator::{ModBanFromCommunity, ModBanFromCommunityForm}, + }, }, traits::{Bannable, Crud}, }; @@ -113,7 +116,7 @@ impl Activity for UndoBlockUser { } // write mod log - let form = ModBanForm { + let form = AdminBanForm { mod_person_id: mod_person.id, other_person_id: blocked_person.id, reason: self.object.summary, @@ -121,7 +124,7 @@ impl Activity for UndoBlockUser { expires_at, instance_id: site.instance_id, }; - ModBan::create(&mut context.pool(), &form).await?; + AdminBan::create(&mut context.pool(), &form).await?; } SiteOrCommunity::Right(community) => { verify_visibility(&self.to, &self.cc, &community)?; diff --git a/crates/apub/src/activities/community/collection_add.rs b/crates/apub/src/activities/community/collection_add.rs index 194ec8c5c..2cd7639e6 100644 --- a/crates/apub/src/activities/community/collection_add.rs +++ b/crates/apub/src/activities/community/collection_add.rs @@ -29,7 +29,7 @@ use lemmy_db_schema::{ source::{ activity::ActivitySendTargets, community::{Community, CommunityActions, CommunityModeratorForm}, - mod_log::moderator::{ModAddCommunity, ModAddCommunityForm}, + mod_log::moderator::{ModAddToCommunity, ModAddToCommunityForm}, person::Person, post::{Post, PostUpdateForm}, }, @@ -132,13 +132,13 @@ impl Activity for CollectionAdd { // write mod log let actor = self.actor.dereference(context).await?; - let form = ModAddCommunityForm { + let form = ModAddToCommunityForm { mod_person_id: actor.id, other_person_id: new_mod.id, community_id: community.id, removed: Some(false), }; - ModAddCommunity::create(&mut context.pool(), &form).await?; + ModAddToCommunity::create(&mut context.pool(), &form).await?; } } CollectionType::Featured => { diff --git a/crates/apub/src/activities/community/collection_remove.rs b/crates/apub/src/activities/community/collection_remove.rs index 952ec0ead..0217deba1 100644 --- a/crates/apub/src/activities/community/collection_remove.rs +++ b/crates/apub/src/activities/community/collection_remove.rs @@ -25,7 +25,7 @@ use lemmy_db_schema::{ source::{ activity::ActivitySendTargets, community::{Community, CommunityActions, CommunityModeratorForm}, - mod_log::moderator::{ModAddCommunity, ModAddCommunityForm}, + mod_log::moderator::{ModAddToCommunity, ModAddToCommunityForm}, post::{Post, PostUpdateForm}, }, traits::Crud, @@ -120,13 +120,13 @@ impl Activity for CollectionRemove { // write mod log let actor = self.actor.dereference(context).await?; - let form = ModAddCommunityForm { + let form = ModAddToCommunityForm { mod_person_id: actor.id, other_person_id: remove_mod.id, community_id: community.id, removed: Some(true), }; - ModAddCommunity::create(&mut context.pool(), &form).await?; + ModAddToCommunity::create(&mut context.pool(), &form).await?; // TODO: send websocket notification about removed mod } diff --git a/crates/apub/src/activities/deletion/delete.rs b/crates/apub/src/activities/deletion/delete.rs index 46caf0856..e54451154 100644 --- a/crates/apub/src/activities/deletion/delete.rs +++ b/crates/apub/src/activities/deletion/delete.rs @@ -14,13 +14,9 @@ use lemmy_db_schema::{ comment_report::CommentReport, community::{Community, CommunityUpdateForm}, community_report::CommunityReport, - mod_log::moderator::{ - ModRemoveComment, - ModRemoveCommentForm, - ModRemoveCommunity, - ModRemoveCommunityForm, - ModRemovePost, - ModRemovePostForm, + mod_log::{ + admin::{AdminRemoveCommunity, AdminRemoveCommunityForm}, + moderator::{ModRemoveComment, ModRemoveCommentForm, ModRemovePost, ModRemovePostForm}, }, post::{Post, PostUpdateForm}, post_report::PostReport, @@ -113,13 +109,13 @@ pub(in crate::activities) async fn receive_remove_action( Err(FederationError::OnlyLocalAdminCanRemoveCommunity)? } CommunityReport::resolve_all_for_object(&mut context.pool(), community.id, actor.id).await?; - let form = ModRemoveCommunityForm { + let form = AdminRemoveCommunityForm { mod_person_id: actor.id, community_id: community.id, removed: Some(true), reason, }; - ModRemoveCommunity::create(&mut context.pool(), &form).await?; + AdminRemoveCommunity::create(&mut context.pool(), &form).await?; Community::update( &mut context.pool(), community.id, diff --git a/crates/apub/src/activities/deletion/undo_delete.rs b/crates/apub/src/activities/deletion/undo_delete.rs index e4dae2e4c..227806bbe 100644 --- a/crates/apub/src/activities/deletion/undo_delete.rs +++ b/crates/apub/src/activities/deletion/undo_delete.rs @@ -12,13 +12,9 @@ use lemmy_db_schema::{ source::{ comment::{Comment, CommentUpdateForm}, community::{Community, CommunityUpdateForm}, - mod_log::moderator::{ - ModRemoveComment, - ModRemoveCommentForm, - ModRemoveCommunity, - ModRemoveCommunityForm, - ModRemovePost, - ModRemovePostForm, + mod_log::{ + admin::{AdminRemoveCommunity, AdminRemoveCommunityForm}, + moderator::{ModRemoveComment, ModRemoveCommentForm, ModRemovePost, ModRemovePostForm}, }, post::{Post, PostUpdateForm}, }, @@ -93,13 +89,13 @@ impl UndoDelete { if community.local { Err(FederationError::OnlyLocalAdminCanRestoreCommunity)? } - let form = ModRemoveCommunityForm { + let form = AdminRemoveCommunityForm { mod_person_id: actor.id, community_id: community.id, removed: Some(false), reason: None, }; - ModRemoveCommunity::create(&mut context.pool(), &form).await?; + AdminRemoveCommunity::create(&mut context.pool(), &form).await?; Community::update( &mut context.pool(), community.id, diff --git a/crates/db_schema/src/impls/mod_log/admin.rs b/crates/db_schema/src/impls/mod_log/admin.rs index 3ef56e4c1..4a23fb7fe 100644 --- a/crates/db_schema/src/impls/mod_log/admin.rs +++ b/crates/db_schema/src/impls/mod_log/admin.rs @@ -1,15 +1,22 @@ use crate::{ newtypes::{ + AdminAddId, AdminAllowInstanceId, + AdminBanId, AdminBlockInstanceId, AdminPurgeCommentId, AdminPurgeCommunityId, AdminPurgePersonId, AdminPurgePostId, + AdminRemoveCommunityId, }, source::mod_log::admin::{ + AdminAdd, + AdminAddForm, AdminAllowInstance, AdminAllowInstanceForm, + AdminBan, + AdminBanForm, AdminBlockInstance, AdminBlockInstanceForm, AdminPurgeComment, @@ -20,6 +27,8 @@ use crate::{ AdminPurgePersonForm, AdminPurgePost, AdminPurgePostForm, + AdminRemoveCommunity, + AdminRemoveCommunityForm, }, traits::Crud, utils::{get_conn, DbPool}, @@ -27,12 +36,15 @@ use crate::{ use diesel::{dsl::insert_into, QueryDsl}; use diesel_async::RunQueryDsl; use lemmy_db_schema_file::schema::{ + admin_add, admin_allow_instance, + admin_ban, admin_block_instance, admin_purge_comment, admin_purge_community, admin_purge_person, admin_purge_post, + admin_remove_community, }; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; @@ -203,3 +215,87 @@ impl Crud for AdminBlockInstance { .with_lemmy_type(LemmyErrorType::CouldntUpdateModlog) } } + +impl Crud for AdminRemoveCommunity { + type InsertForm = AdminRemoveCommunityForm; + type UpdateForm = AdminRemoveCommunityForm; + type IdType = AdminRemoveCommunityId; + + async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> LemmyResult { + let conn = &mut get_conn(pool).await?; + insert_into(admin_remove_community::table) + .values(form) + .get_result::(conn) + .await + .with_lemmy_type(LemmyErrorType::CouldntCreateModlog) + } + + async fn update( + pool: &mut DbPool<'_>, + from_id: Self::IdType, + form: &Self::UpdateForm, + ) -> LemmyResult { + let conn = &mut get_conn(pool).await?; + diesel::update(admin_remove_community::table.find(from_id)) + .set(form) + .get_result::(conn) + .await + .with_lemmy_type(LemmyErrorType::CouldntUpdateModlog) + } +} + +impl Crud for AdminBan { + type InsertForm = AdminBanForm; + type UpdateForm = AdminBanForm; + type IdType = AdminBanId; + + async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> LemmyResult { + let conn = &mut get_conn(pool).await?; + insert_into(admin_ban::table) + .values(form) + .get_result::(conn) + .await + .with_lemmy_type(LemmyErrorType::CouldntCreateModlog) + } + + async fn update( + pool: &mut DbPool<'_>, + from_id: Self::IdType, + form: &Self::UpdateForm, + ) -> LemmyResult { + let conn = &mut get_conn(pool).await?; + diesel::update(admin_ban::table.find(from_id)) + .set(form) + .get_result::(conn) + .await + .with_lemmy_type(LemmyErrorType::CouldntUpdateModlog) + } +} + +impl Crud for AdminAdd { + type InsertForm = AdminAddForm; + type UpdateForm = AdminAddForm; + type IdType = AdminAddId; + + async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> LemmyResult { + let conn = &mut get_conn(pool).await?; + insert_into(admin_add::table) + .values(form) + .get_result::(conn) + .await + .with_lemmy_type(LemmyErrorType::CouldntCreateModlog) + } + + async fn update( + pool: &mut DbPool<'_>, + from_id: Self::IdType, + form: &Self::UpdateForm, + ) -> LemmyResult { + let conn = &mut get_conn(pool).await?; + diesel::update(admin_add::table.find(from_id)) + .set(form) + .get_result::(conn) + .await + .with_lemmy_type(LemmyErrorType::CouldntUpdateModlog) + } +} diff --git a/crates/db_schema/src/impls/mod_log/mod.rs b/crates/db_schema/src/impls/mod_log/mod.rs index 54341c69a..acccac72b 100644 --- a/crates/db_schema/src/impls/mod_log/mod.rs +++ b/crates/db_schema/src/impls/mod_log/mod.rs @@ -1,2 +1,267 @@ pub mod admin; pub mod moderator; + +#[cfg(test)] +mod tests { + + use crate::{ + source::{ + comment::{Comment, CommentInsertForm}, + community::{Community, CommunityInsertForm}, + instance::Instance, + mod_log::{admin::*, moderator::*}, + person::{Person, PersonInsertForm}, + post::{Post, PostInsertForm}, + }, + traits::Crud, + utils::build_db_pool_for_tests, + }; + use lemmy_utils::error::LemmyResult; + use pretty_assertions::assert_eq; + use serial_test::serial; + + #[tokio::test] + #[serial] + async fn test_crud() -> LemmyResult<()> { + let pool = &build_db_pool_for_tests(); + let pool = &mut pool.into(); + + let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?; + + let new_mod = PersonInsertForm::test_form(inserted_instance.id, "the mod"); + + let inserted_mod = Person::create(pool, &new_mod).await?; + + let new_person = PersonInsertForm::test_form(inserted_instance.id, "jim2"); + + let inserted_person = Person::create(pool, &new_person).await?; + + let new_community = CommunityInsertForm::new( + inserted_instance.id, + "mod_community".to_string(), + "nada".to_owned(), + "pubkey".to_string(), + ); + + let inserted_community = Community::create(pool, &new_community).await?; + + let new_post = PostInsertForm::new( + "A test post thweep".into(), + inserted_person.id, + inserted_community.id, + ); + let inserted_post = Post::create(pool, &new_post).await?; + + let comment_form = CommentInsertForm::new( + inserted_person.id, + inserted_post.id, + "A test comment".into(), + ); + let inserted_comment = Comment::create(pool, &comment_form, None).await?; + + // Now the actual tests + + // remove post + let mod_remove_post_form = ModRemovePostForm { + mod_person_id: inserted_mod.id, + post_id: inserted_post.id, + reason: None, + removed: None, + }; + let inserted_mod_remove_post = ModRemovePost::create(pool, &mod_remove_post_form).await?; + let read_mod_remove_post = ModRemovePost::read(pool, inserted_mod_remove_post.id).await?; + let expected_mod_remove_post = ModRemovePost { + id: inserted_mod_remove_post.id, + post_id: inserted_post.id, + mod_person_id: inserted_mod.id, + reason: None, + removed: true, + published_at: inserted_mod_remove_post.published_at, + }; + + // lock post + + let mod_lock_post_form = ModLockPostForm { + mod_person_id: inserted_mod.id, + post_id: inserted_post.id, + locked: None, + reason: None, + }; + let inserted_mod_lock_post = ModLockPost::create(pool, &mod_lock_post_form).await?; + let read_mod_lock_post = ModLockPost::read(pool, inserted_mod_lock_post.id).await?; + let expected_mod_lock_post = ModLockPost { + id: inserted_mod_lock_post.id, + post_id: inserted_post.id, + mod_person_id: inserted_mod.id, + locked: true, + reason: None, + published_at: inserted_mod_lock_post.published_at, + }; + + // feature post + + let mod_feature_post_form = ModFeaturePostForm { + mod_person_id: inserted_mod.id, + post_id: inserted_post.id, + featured: Some(false), + is_featured_community: Some(true), + }; + let inserted_mod_feature_post = ModFeaturePost::create(pool, &mod_feature_post_form).await?; + let read_mod_feature_post = ModFeaturePost::read(pool, inserted_mod_feature_post.id).await?; + let expected_mod_feature_post = ModFeaturePost { + id: inserted_mod_feature_post.id, + post_id: inserted_post.id, + mod_person_id: inserted_mod.id, + featured: false, + is_featured_community: true, + published_at: inserted_mod_feature_post.published_at, + }; + + // comment + + let mod_remove_comment_form = ModRemoveCommentForm { + mod_person_id: inserted_mod.id, + comment_id: inserted_comment.id, + reason: None, + removed: None, + }; + let inserted_mod_remove_comment = + ModRemoveComment::create(pool, &mod_remove_comment_form).await?; + let read_mod_remove_comment = + ModRemoveComment::read(pool, inserted_mod_remove_comment.id).await?; + let expected_mod_remove_comment = ModRemoveComment { + id: inserted_mod_remove_comment.id, + comment_id: inserted_comment.id, + mod_person_id: inserted_mod.id, + reason: None, + removed: true, + published_at: inserted_mod_remove_comment.published_at, + }; + + // community + + let admin_remove_community_form = AdminRemoveCommunityForm { + mod_person_id: inserted_mod.id, + community_id: inserted_community.id, + reason: None, + removed: None, + }; + let inserted_admin_remove_community = + AdminRemoveCommunity::create(pool, &admin_remove_community_form).await?; + let read_mod_remove_community = + AdminRemoveCommunity::read(pool, inserted_admin_remove_community.id).await?; + let expected_admin_remove_community = AdminRemoveCommunity { + id: inserted_admin_remove_community.id, + community_id: inserted_community.id, + mod_person_id: inserted_mod.id, + reason: None, + removed: true, + published_at: inserted_admin_remove_community.published_at, + }; + + // ban from community + + let mod_ban_from_community_form = ModBanFromCommunityForm { + mod_person_id: inserted_mod.id, + other_person_id: inserted_person.id, + community_id: inserted_community.id, + reason: None, + banned: None, + expires_at: None, + }; + let inserted_mod_ban_from_community = + ModBanFromCommunity::create(pool, &mod_ban_from_community_form).await?; + let read_mod_ban_from_community = + ModBanFromCommunity::read(pool, inserted_mod_ban_from_community.id).await?; + let expected_mod_ban_from_community = ModBanFromCommunity { + id: inserted_mod_ban_from_community.id, + community_id: inserted_community.id, + mod_person_id: inserted_mod.id, + other_person_id: inserted_person.id, + reason: None, + banned: true, + expires_at: None, + published_at: inserted_mod_ban_from_community.published_at, + }; + + // ban + + let admin_ban_form = AdminBanForm { + mod_person_id: inserted_mod.id, + other_person_id: inserted_person.id, + reason: None, + banned: None, + expires_at: None, + instance_id: inserted_instance.id, + }; + let inserted_admin_ban = AdminBan::create(pool, &admin_ban_form).await?; + let read_mod_ban = AdminBan::read(pool, inserted_admin_ban.id).await?; + let expected_admin_ban = AdminBan { + id: inserted_admin_ban.id, + mod_person_id: inserted_mod.id, + other_person_id: inserted_person.id, + reason: None, + banned: true, + expires_at: None, + published_at: inserted_admin_ban.published_at, + instance_id: inserted_instance.id, + }; + + // mod add community + + let mod_add_to_community_form = ModAddToCommunityForm { + mod_person_id: inserted_mod.id, + other_person_id: inserted_person.id, + community_id: inserted_community.id, + removed: None, + }; + let inserted_mod_add_to_community = + ModAddToCommunity::create(pool, &mod_add_to_community_form).await?; + let read_mod_add_to_community = + ModAddToCommunity::read(pool, inserted_mod_add_to_community.id).await?; + let expected_mod_add_to_community = ModAddToCommunity { + id: inserted_mod_add_to_community.id, + community_id: inserted_community.id, + mod_person_id: inserted_mod.id, + other_person_id: inserted_person.id, + removed: false, + published_at: inserted_mod_add_to_community.published_at, + }; + + // admin add + + let admin_add_form = AdminAddForm { + mod_person_id: inserted_mod.id, + other_person_id: inserted_person.id, + removed: None, + }; + let inserted_admin_add = AdminAdd::create(pool, &admin_add_form).await?; + let read_mod_add = AdminAdd::read(pool, inserted_admin_add.id).await?; + let expected_admin_add = AdminAdd { + id: inserted_admin_add.id, + mod_person_id: inserted_mod.id, + other_person_id: inserted_person.id, + removed: false, + published_at: inserted_admin_add.published_at, + }; + + Comment::delete(pool, inserted_comment.id).await?; + Post::delete(pool, inserted_post.id).await?; + Community::delete(pool, inserted_community.id).await?; + Person::delete(pool, inserted_person.id).await?; + Person::delete(pool, inserted_mod.id).await?; + Instance::delete(pool, inserted_instance.id).await?; + + assert_eq!(expected_mod_remove_post, read_mod_remove_post); + assert_eq!(expected_mod_lock_post, read_mod_lock_post); + assert_eq!(expected_mod_feature_post, read_mod_feature_post); + assert_eq!(expected_mod_remove_comment, read_mod_remove_comment); + assert_eq!(expected_admin_remove_community, read_mod_remove_community); + assert_eq!(expected_mod_ban_from_community, read_mod_ban_from_community); + assert_eq!(expected_admin_ban, read_mod_ban); + assert_eq!(expected_mod_add_to_community, read_mod_add_to_community); + assert_eq!(expected_admin_add, read_mod_add); + + Ok(()) + } +} diff --git a/crates/db_schema/src/impls/mod_log/moderator.rs b/crates/db_schema/src/impls/mod_log/moderator.rs index ef34e5181..8b50cf51b 100644 --- a/crates/db_schema/src/impls/mod_log/moderator.rs +++ b/crates/db_schema/src/impls/mod_log/moderator.rs @@ -1,24 +1,17 @@ use crate::{ newtypes::{ - ModAddCommunityId, - ModAddId, + ModAddToCommunityId, ModBanFromCommunityId, - ModBanId, ModChangeCommunityVisibilityId, ModFeaturePostId, ModLockPostId, ModRemoveCommentId, - ModRemoveCommunityId, ModRemovePostId, ModTransferCommunityId, }, source::mod_log::moderator::{ - ModAdd, - ModAddCommunity, - ModAddCommunityForm, - ModAddForm, - ModBan, - ModBanForm, + ModAddToCommunity, + ModAddToCommunityForm, ModBanFromCommunity, ModBanFromCommunityForm, ModChangeCommunityVisibility, @@ -29,8 +22,6 @@ use crate::{ ModLockPostForm, ModRemoveComment, ModRemoveCommentForm, - ModRemoveCommunity, - ModRemoveCommunityForm, ModRemovePost, ModRemovePostForm, ModTransferCommunity, @@ -42,15 +33,12 @@ use crate::{ use diesel::{dsl::insert_into, QueryDsl}; use diesel_async::RunQueryDsl; use lemmy_db_schema_file::schema::{ - mod_add, - mod_add_community, - mod_ban, + mod_add_to_community, mod_ban_from_community, mod_change_community_visibility, mod_feature_post, mod_lock_post, mod_remove_comment, - mod_remove_community, mod_remove_post, mod_transfer_community, }; @@ -196,34 +184,6 @@ impl ModRemoveComment { } } -impl Crud for ModRemoveCommunity { - type InsertForm = ModRemoveCommunityForm; - type UpdateForm = ModRemoveCommunityForm; - type IdType = ModRemoveCommunityId; - - async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> LemmyResult { - let conn = &mut get_conn(pool).await?; - insert_into(mod_remove_community::table) - .values(form) - .get_result::(conn) - .await - .with_lemmy_type(LemmyErrorType::CouldntCreateModlog) - } - - async fn update( - pool: &mut DbPool<'_>, - from_id: Self::IdType, - form: &Self::UpdateForm, - ) -> LemmyResult { - let conn = &mut get_conn(pool).await?; - diesel::update(mod_remove_community::table.find(from_id)) - .set(form) - .get_result::(conn) - .await - .with_lemmy_type(LemmyErrorType::CouldntUpdateModlog) - } -} - impl Crud for ModBanFromCommunity { type InsertForm = ModBanFromCommunityForm; type UpdateForm = ModBanFromCommunityForm; @@ -252,34 +212,6 @@ impl Crud for ModBanFromCommunity { } } -impl Crud for ModBan { - type InsertForm = ModBanForm; - type UpdateForm = ModBanForm; - type IdType = ModBanId; - - async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> LemmyResult { - let conn = &mut get_conn(pool).await?; - insert_into(mod_ban::table) - .values(form) - .get_result::(conn) - .await - .with_lemmy_type(LemmyErrorType::CouldntCreateModlog) - } - - async fn update( - pool: &mut DbPool<'_>, - from_id: Self::IdType, - form: &Self::UpdateForm, - ) -> LemmyResult { - let conn = &mut get_conn(pool).await?; - diesel::update(mod_ban::table.find(from_id)) - .set(form) - .get_result::(conn) - .await - .with_lemmy_type(LemmyErrorType::CouldntUpdateModlog) - } -} - impl Crud for ModChangeCommunityVisibility { type InsertForm = ModChangeCommunityVisibilityForm; type UpdateForm = ModChangeCommunityVisibilityForm; @@ -308,14 +240,14 @@ impl Crud for ModChangeCommunityVisibility { } } -impl Crud for ModAddCommunity { - type InsertForm = ModAddCommunityForm; - type UpdateForm = ModAddCommunityForm; - type IdType = ModAddCommunityId; +impl Crud for ModAddToCommunity { + type InsertForm = ModAddToCommunityForm; + type UpdateForm = ModAddToCommunityForm; + type IdType = ModAddToCommunityId; async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> LemmyResult { let conn = &mut get_conn(pool).await?; - insert_into(mod_add_community::table) + insert_into(mod_add_to_community::table) .values(form) .get_result::(conn) .await @@ -328,7 +260,7 @@ impl Crud for ModAddCommunity { form: &Self::UpdateForm, ) -> LemmyResult { let conn = &mut get_conn(pool).await?; - diesel::update(mod_add_community::table.find(from_id)) + diesel::update(mod_add_to_community::table.find(from_id)) .set(form) .get_result::(conn) .await @@ -363,293 +295,3 @@ impl Crud for ModTransferCommunity { .with_lemmy_type(LemmyErrorType::CouldntUpdateModlog) } } - -impl Crud for ModAdd { - type InsertForm = ModAddForm; - type UpdateForm = ModAddForm; - type IdType = ModAddId; - - async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> LemmyResult { - let conn = &mut get_conn(pool).await?; - insert_into(mod_add::table) - .values(form) - .get_result::(conn) - .await - .with_lemmy_type(LemmyErrorType::CouldntCreateModlog) - } - - async fn update( - pool: &mut DbPool<'_>, - from_id: Self::IdType, - form: &Self::UpdateForm, - ) -> LemmyResult { - let conn = &mut get_conn(pool).await?; - diesel::update(mod_add::table.find(from_id)) - .set(form) - .get_result::(conn) - .await - .with_lemmy_type(LemmyErrorType::CouldntUpdateModlog) - } -} - -#[cfg(test)] -mod tests { - - use super::*; - use crate::{ - source::{ - comment::{Comment, CommentInsertForm}, - community::{Community, CommunityInsertForm}, - instance::Instance, - person::{Person, PersonInsertForm}, - post::{Post, PostInsertForm}, - }, - utils::build_db_pool_for_tests, - }; - use lemmy_utils::error::LemmyResult; - use pretty_assertions::assert_eq; - use serial_test::serial; - - #[tokio::test] - #[serial] - async fn test_crud() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); - let pool = &mut pool.into(); - - let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?; - - let new_mod = PersonInsertForm::test_form(inserted_instance.id, "the mod"); - - let inserted_mod = Person::create(pool, &new_mod).await?; - - let new_person = PersonInsertForm::test_form(inserted_instance.id, "jim2"); - - let inserted_person = Person::create(pool, &new_person).await?; - - let new_community = CommunityInsertForm::new( - inserted_instance.id, - "mod_community".to_string(), - "nada".to_owned(), - "pubkey".to_string(), - ); - - let inserted_community = Community::create(pool, &new_community).await?; - - let new_post = PostInsertForm::new( - "A test post thweep".into(), - inserted_person.id, - inserted_community.id, - ); - let inserted_post = Post::create(pool, &new_post).await?; - - let comment_form = CommentInsertForm::new( - inserted_person.id, - inserted_post.id, - "A test comment".into(), - ); - let inserted_comment = Comment::create(pool, &comment_form, None).await?; - - // Now the actual tests - - // remove post - let mod_remove_post_form = ModRemovePostForm { - mod_person_id: inserted_mod.id, - post_id: inserted_post.id, - reason: None, - removed: None, - }; - let inserted_mod_remove_post = ModRemovePost::create(pool, &mod_remove_post_form).await?; - let read_mod_remove_post = ModRemovePost::read(pool, inserted_mod_remove_post.id).await?; - let expected_mod_remove_post = ModRemovePost { - id: inserted_mod_remove_post.id, - post_id: inserted_post.id, - mod_person_id: inserted_mod.id, - reason: None, - removed: true, - published_at: inserted_mod_remove_post.published_at, - }; - - // lock post - - let mod_lock_post_form = ModLockPostForm { - mod_person_id: inserted_mod.id, - post_id: inserted_post.id, - locked: None, - reason: None, - }; - let inserted_mod_lock_post = ModLockPost::create(pool, &mod_lock_post_form).await?; - let read_mod_lock_post = ModLockPost::read(pool, inserted_mod_lock_post.id).await?; - let expected_mod_lock_post = ModLockPost { - id: inserted_mod_lock_post.id, - post_id: inserted_post.id, - mod_person_id: inserted_mod.id, - locked: true, - reason: None, - published_at: inserted_mod_lock_post.published_at, - }; - - // feature post - - let mod_feature_post_form = ModFeaturePostForm { - mod_person_id: inserted_mod.id, - post_id: inserted_post.id, - featured: Some(false), - is_featured_community: Some(true), - }; - let inserted_mod_feature_post = ModFeaturePost::create(pool, &mod_feature_post_form).await?; - let read_mod_feature_post = ModFeaturePost::read(pool, inserted_mod_feature_post.id).await?; - let expected_mod_feature_post = ModFeaturePost { - id: inserted_mod_feature_post.id, - post_id: inserted_post.id, - mod_person_id: inserted_mod.id, - featured: false, - is_featured_community: true, - published_at: inserted_mod_feature_post.published_at, - }; - - // comment - - let mod_remove_comment_form = ModRemoveCommentForm { - mod_person_id: inserted_mod.id, - comment_id: inserted_comment.id, - reason: None, - removed: None, - }; - let inserted_mod_remove_comment = - ModRemoveComment::create(pool, &mod_remove_comment_form).await?; - let read_mod_remove_comment = - ModRemoveComment::read(pool, inserted_mod_remove_comment.id).await?; - let expected_mod_remove_comment = ModRemoveComment { - id: inserted_mod_remove_comment.id, - comment_id: inserted_comment.id, - mod_person_id: inserted_mod.id, - reason: None, - removed: true, - published_at: inserted_mod_remove_comment.published_at, - }; - - // community - - let mod_remove_community_form = ModRemoveCommunityForm { - mod_person_id: inserted_mod.id, - community_id: inserted_community.id, - reason: None, - removed: None, - }; - let inserted_mod_remove_community = - ModRemoveCommunity::create(pool, &mod_remove_community_form).await?; - let read_mod_remove_community = - ModRemoveCommunity::read(pool, inserted_mod_remove_community.id).await?; - let expected_mod_remove_community = ModRemoveCommunity { - id: inserted_mod_remove_community.id, - community_id: inserted_community.id, - mod_person_id: inserted_mod.id, - reason: None, - removed: true, - published_at: inserted_mod_remove_community.published_at, - }; - - // ban from community - - let mod_ban_from_community_form = ModBanFromCommunityForm { - mod_person_id: inserted_mod.id, - other_person_id: inserted_person.id, - community_id: inserted_community.id, - reason: None, - banned: None, - expires_at: None, - }; - let inserted_mod_ban_from_community = - ModBanFromCommunity::create(pool, &mod_ban_from_community_form).await?; - let read_mod_ban_from_community = - ModBanFromCommunity::read(pool, inserted_mod_ban_from_community.id).await?; - let expected_mod_ban_from_community = ModBanFromCommunity { - id: inserted_mod_ban_from_community.id, - community_id: inserted_community.id, - mod_person_id: inserted_mod.id, - other_person_id: inserted_person.id, - reason: None, - banned: true, - expires_at: None, - published_at: inserted_mod_ban_from_community.published_at, - }; - - // ban - - let mod_ban_form = ModBanForm { - mod_person_id: inserted_mod.id, - other_person_id: inserted_person.id, - reason: None, - banned: None, - expires_at: None, - instance_id: inserted_instance.id, - }; - let inserted_mod_ban = ModBan::create(pool, &mod_ban_form).await?; - let read_mod_ban = ModBan::read(pool, inserted_mod_ban.id).await?; - let expected_mod_ban = ModBan { - id: inserted_mod_ban.id, - mod_person_id: inserted_mod.id, - other_person_id: inserted_person.id, - reason: None, - banned: true, - expires_at: None, - published_at: inserted_mod_ban.published_at, - instance_id: inserted_instance.id, - }; - - // mod add community - - let mod_add_community_form = ModAddCommunityForm { - mod_person_id: inserted_mod.id, - other_person_id: inserted_person.id, - community_id: inserted_community.id, - removed: None, - }; - let inserted_mod_add_community = ModAddCommunity::create(pool, &mod_add_community_form).await?; - let read_mod_add_community = ModAddCommunity::read(pool, inserted_mod_add_community.id).await?; - let expected_mod_add_community = ModAddCommunity { - id: inserted_mod_add_community.id, - community_id: inserted_community.id, - mod_person_id: inserted_mod.id, - other_person_id: inserted_person.id, - removed: false, - published_at: inserted_mod_add_community.published_at, - }; - - // mod add - - let mod_add_form = ModAddForm { - mod_person_id: inserted_mod.id, - other_person_id: inserted_person.id, - removed: None, - }; - let inserted_mod_add = ModAdd::create(pool, &mod_add_form).await?; - let read_mod_add = ModAdd::read(pool, inserted_mod_add.id).await?; - let expected_mod_add = ModAdd { - id: inserted_mod_add.id, - mod_person_id: inserted_mod.id, - other_person_id: inserted_person.id, - removed: false, - published_at: inserted_mod_add.published_at, - }; - - Comment::delete(pool, inserted_comment.id).await?; - Post::delete(pool, inserted_post.id).await?; - Community::delete(pool, inserted_community.id).await?; - Person::delete(pool, inserted_person.id).await?; - Person::delete(pool, inserted_mod.id).await?; - Instance::delete(pool, inserted_instance.id).await?; - - assert_eq!(expected_mod_remove_post, read_mod_remove_post); - assert_eq!(expected_mod_lock_post, read_mod_lock_post); - assert_eq!(expected_mod_feature_post, read_mod_feature_post); - assert_eq!(expected_mod_remove_comment, read_mod_remove_comment); - assert_eq!(expected_mod_remove_community, read_mod_remove_community); - assert_eq!(expected_mod_ban_from_community, read_mod_ban_from_community); - assert_eq!(expected_mod_ban, read_mod_ban); - assert_eq!(expected_mod_add_community, read_mod_add_community); - assert_eq!(expected_mod_add, read_mod_add); - - Ok(()) - } -} diff --git a/crates/db_schema/src/lib.rs b/crates/db_schema/src/lib.rs index 5e33ef4df..7a2eb435c 100644 --- a/crates/db_schema/src/lib.rs +++ b/crates/db_schema/src/lib.rs @@ -95,12 +95,12 @@ pub enum ModlogActionType { ModLockPost, ModFeaturePost, ModRemoveComment, - ModRemoveCommunity, + AdminRemoveCommunity, ModBanFromCommunity, - ModAddCommunity, + ModAddToCommunity, ModTransferCommunity, - ModAdd, - ModBan, + AdminAdd, + AdminBan, ModChangeCommunityVisibility, AdminPurgePerson, AdminPurgeCommunity, diff --git a/crates/db_schema/src/newtypes.rs b/crates/db_schema/src/newtypes.rs index 5c0de1459..2a651c412 100644 --- a/crates/db_schema/src/newtypes.rs +++ b/crates/db_schema/src/newtypes.rs @@ -284,7 +284,7 @@ pub struct ModRemoveCommentId(pub i32); #[cfg_attr(feature = "full", derive(DieselNewType))] #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))] #[cfg_attr(feature = "ts-rs", ts(optional_fields, export))] -pub struct ModRemoveCommunityId(pub i32); +pub struct AdminRemoveCommunityId(pub i32); #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] #[cfg_attr(feature = "full", derive(DieselNewType))] @@ -308,7 +308,7 @@ pub struct ModBanFromCommunityId(pub i32); #[cfg_attr(feature = "full", derive(DieselNewType))] #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))] #[cfg_attr(feature = "ts-rs", ts(optional_fields, export))] -pub struct ModBanId(pub i32); +pub struct AdminBanId(pub i32); #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] #[cfg_attr(feature = "full", derive(DieselNewType))] @@ -320,7 +320,7 @@ pub struct ModChangeCommunityVisibilityId(pub i32); #[cfg_attr(feature = "full", derive(DieselNewType))] #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))] #[cfg_attr(feature = "ts-rs", ts(optional_fields, export))] -pub struct ModAddCommunityId(pub i32); +pub struct ModAddToCommunityId(pub i32); #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] #[cfg_attr(feature = "full", derive(DieselNewType))] @@ -332,7 +332,7 @@ pub struct ModTransferCommunityId(pub i32); #[cfg_attr(feature = "full", derive(DieselNewType))] #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))] #[cfg_attr(feature = "ts-rs", ts(optional_fields, export))] -pub struct ModAddId(pub i32); +pub struct AdminAddId(pub i32); #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] #[cfg_attr(feature = "full", derive(DieselNewType))] diff --git a/crates/db_schema/src/source/combined/modlog.rs b/crates/db_schema/src/source/combined/modlog.rs index ad8ca6236..eb554864a 100644 --- a/crates/db_schema/src/source/combined/modlog.rs +++ b/crates/db_schema/src/source/combined/modlog.rs @@ -1,19 +1,19 @@ use crate::newtypes::{ + AdminAddId, AdminAllowInstanceId, + AdminBanId, AdminBlockInstanceId, AdminPurgeCommentId, AdminPurgeCommunityId, AdminPurgePersonId, AdminPurgePostId, - ModAddCommunityId, - ModAddId, + AdminRemoveCommunityId, + ModAddToCommunityId, ModBanFromCommunityId, - ModBanId, ModChangeCommunityVisibilityId, ModFeaturePostId, ModLockPostId, ModRemoveCommentId, - ModRemoveCommunityId, ModRemovePostId, ModTransferCommunityId, ModlogCombinedId, @@ -43,15 +43,15 @@ pub struct ModlogCombined { pub admin_purge_community_id: Option, pub admin_purge_person_id: Option, pub admin_purge_post_id: Option, - pub mod_add_id: Option, - pub mod_add_community_id: Option, - pub mod_ban_id: Option, + pub admin_add_id: Option, + pub mod_add_to_community_id: Option, + pub admin_ban_id: Option, pub mod_ban_from_community_id: Option, pub mod_feature_post_id: Option, pub mod_change_community_visibility_id: Option, pub mod_lock_post_id: Option, pub mod_remove_comment_id: Option, - pub mod_remove_community_id: Option, + pub admin_remove_community_id: Option, pub mod_remove_post_id: Option, pub mod_transfer_community_id: Option, } diff --git a/crates/db_schema/src/source/mod_log/admin.rs b/crates/db_schema/src/source/mod_log/admin.rs index 4eb280596..83f9ea32b 100644 --- a/crates/db_schema/src/source/mod_log/admin.rs +++ b/crates/db_schema/src/source/mod_log/admin.rs @@ -1,10 +1,13 @@ use crate::newtypes::{ + AdminAddId, AdminAllowInstanceId, + AdminBanId, AdminBlockInstanceId, AdminPurgeCommentId, AdminPurgeCommunityId, AdminPurgePersonId, AdminPurgePostId, + AdminRemoveCommunityId, CommunityId, InstanceId, PersonId, @@ -13,12 +16,15 @@ use crate::newtypes::{ use chrono::{DateTime, Utc}; #[cfg(feature = "full")] use lemmy_db_schema_file::schema::{ + admin_add, admin_allow_instance, + admin_ban, admin_block_instance, admin_purge_comment, admin_purge_community, admin_purge_person, admin_purge_post, + admin_remove_community, }; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; @@ -181,3 +187,82 @@ pub struct AdminBlockInstanceForm { pub blocked: bool, pub reason: Option, } + +#[skip_serializing_none] +#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "full", derive(Queryable, Selectable, Identifiable))] +#[cfg_attr(feature = "full", diesel(table_name = admin_remove_community))] +#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))] +#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))] +#[cfg_attr(feature = "ts-rs", ts(optional_fields, export))] +/// When a moderator removes a community. +pub struct AdminRemoveCommunity { + pub id: AdminRemoveCommunityId, + pub mod_person_id: PersonId, + pub community_id: CommunityId, + pub reason: Option, + pub removed: bool, + pub published_at: DateTime, +} + +#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] +#[cfg_attr(feature = "full", diesel(table_name = admin_remove_community))] +pub struct AdminRemoveCommunityForm { + pub mod_person_id: PersonId, + pub community_id: CommunityId, + pub reason: Option, + pub removed: Option, +} + +#[skip_serializing_none] +#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "full", derive(Queryable, Selectable, Identifiable))] +#[cfg_attr(feature = "full", diesel(table_name = admin_ban))] +#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))] +#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))] +#[cfg_attr(feature = "ts-rs", ts(optional_fields, export))] +/// When someone is banned from the site. +pub struct AdminBan { + pub id: AdminBanId, + pub mod_person_id: PersonId, + pub other_person_id: PersonId, + pub reason: Option, + pub banned: bool, + pub expires_at: Option>, + pub published_at: DateTime, + pub instance_id: InstanceId, +} + +#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] +#[cfg_attr(feature = "full", diesel(table_name = admin_ban))] +pub struct AdminBanForm { + pub mod_person_id: PersonId, + pub other_person_id: PersonId, + pub reason: Option, + pub banned: Option, + pub expires_at: Option>, + pub instance_id: InstanceId, +} + +#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "full", derive(Queryable, Selectable, Identifiable))] +#[cfg_attr(feature = "full", diesel(table_name = admin_add))] +#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))] +#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))] +#[cfg_attr(feature = "ts-rs", ts(optional_fields, export))] +/// When someone is added as a site admin. +pub struct AdminAdd { + pub id: AdminAddId, + pub mod_person_id: PersonId, + pub other_person_id: PersonId, + pub removed: bool, + pub published_at: DateTime, +} + +#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] +#[cfg_attr(feature = "full", diesel(table_name = admin_add))] +pub struct AdminAddForm { + pub mod_person_id: PersonId, + pub other_person_id: PersonId, + pub removed: Option, +} diff --git a/crates/db_schema/src/source/mod_log/moderator.rs b/crates/db_schema/src/source/mod_log/moderator.rs index 9d2e976b0..499ad2365 100644 --- a/crates/db_schema/src/source/mod_log/moderator.rs +++ b/crates/db_schema/src/source/mod_log/moderator.rs @@ -1,16 +1,12 @@ use crate::newtypes::{ CommentId, CommunityId, - InstanceId, - ModAddCommunityId, - ModAddId, + ModAddToCommunityId, ModBanFromCommunityId, - ModBanId, ModChangeCommunityVisibilityId, ModFeaturePostId, ModLockPostId, ModRemoveCommentId, - ModRemoveCommunityId, ModRemovePostId, ModTransferCommunityId, PersonId, @@ -20,15 +16,12 @@ use chrono::{DateTime, Utc}; use lemmy_db_schema_file::enums::CommunityVisibility; #[cfg(feature = "full")] use lemmy_db_schema_file::schema::{ - mod_add, - mod_add_community, - mod_ban, + mod_add_to_community, mod_ban_from_community, mod_change_community_visibility, mod_feature_post, mod_lock_post, mod_remove_comment, - mod_remove_community, mod_remove_post, mod_transfer_community, }; @@ -137,32 +130,6 @@ pub struct ModRemoveCommentForm { pub removed: Option, } -#[skip_serializing_none] -#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Selectable, Identifiable))] -#[cfg_attr(feature = "full", diesel(table_name = mod_remove_community))] -#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))] -#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))] -#[cfg_attr(feature = "ts-rs", ts(optional_fields, export))] -/// When a moderator removes a community. -pub struct ModRemoveCommunity { - pub id: ModRemoveCommunityId, - pub mod_person_id: PersonId, - pub community_id: CommunityId, - pub reason: Option, - pub removed: bool, - pub published_at: DateTime, -} - -#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] -#[cfg_attr(feature = "full", diesel(table_name = mod_remove_community))] -pub struct ModRemoveCommunityForm { - pub mod_person_id: PersonId, - pub community_id: CommunityId, - pub reason: Option, - pub removed: Option, -} - #[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] #[cfg_attr(feature = "full", derive(Queryable, Selectable, Identifiable))] @@ -193,25 +160,6 @@ pub struct ModBanFromCommunityForm { pub expires_at: Option>, } -#[skip_serializing_none] -#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Selectable, Identifiable))] -#[cfg_attr(feature = "full", diesel(table_name = mod_ban))] -#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))] -#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))] -#[cfg_attr(feature = "ts-rs", ts(optional_fields, export))] -/// When someone is banned from the site. -pub struct ModBan { - pub id: ModBanId, - pub mod_person_id: PersonId, - pub other_person_id: PersonId, - pub reason: Option, - pub banned: bool, - pub expires_at: Option>, - pub published_at: DateTime, - pub instance_id: InstanceId, -} - #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = mod_change_community_visibility))] pub struct ModChangeCommunityVisibilityForm { @@ -235,26 +183,15 @@ pub struct ModChangeCommunityVisibility { pub visibility: CommunityVisibility, } -#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] -#[cfg_attr(feature = "full", diesel(table_name = mod_ban))] -pub struct ModBanForm { - pub mod_person_id: PersonId, - pub other_person_id: PersonId, - pub reason: Option, - pub banned: Option, - pub expires_at: Option>, - pub instance_id: InstanceId, -} - #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] #[cfg_attr(feature = "full", derive(Queryable, Selectable, Identifiable))] -#[cfg_attr(feature = "full", diesel(table_name = mod_add_community))] +#[cfg_attr(feature = "full", diesel(table_name = mod_add_to_community))] #[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))] #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))] #[cfg_attr(feature = "ts-rs", ts(optional_fields, export))] /// When someone is added as a community moderator. -pub struct ModAddCommunity { - pub id: ModAddCommunityId, +pub struct ModAddToCommunity { + pub id: ModAddToCommunityId, pub mod_person_id: PersonId, pub other_person_id: PersonId, pub community_id: CommunityId, @@ -263,8 +200,8 @@ pub struct ModAddCommunity { } #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] -#[cfg_attr(feature = "full", diesel(table_name = mod_add_community))] -pub struct ModAddCommunityForm { +#[cfg_attr(feature = "full", diesel(table_name = mod_add_to_community))] +pub struct ModAddToCommunityForm { pub mod_person_id: PersonId, pub other_person_id: PersonId, pub community_id: CommunityId, @@ -293,26 +230,3 @@ pub struct ModTransferCommunityForm { pub other_person_id: PersonId, pub community_id: CommunityId, } - -#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Selectable, Identifiable))] -#[cfg_attr(feature = "full", diesel(table_name = mod_add))] -#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))] -#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))] -#[cfg_attr(feature = "ts-rs", ts(optional_fields, export))] -/// When someone is added as a site moderator. -pub struct ModAdd { - pub id: ModAddId, - pub mod_person_id: PersonId, - pub other_person_id: PersonId, - pub removed: bool, - pub published_at: DateTime, -} - -#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] -#[cfg_attr(feature = "full", diesel(table_name = mod_add))] -pub struct ModAddForm { - pub mod_person_id: PersonId, - pub other_person_id: PersonId, - pub removed: Option, -} diff --git a/crates/db_schema_file/src/schema.rs b/crates/db_schema_file/src/schema.rs index 0c8eac8ec..65b66f52e 100644 --- a/crates/db_schema_file/src/schema.rs +++ b/crates/db_schema_file/src/schema.rs @@ -58,6 +58,16 @@ pub mod sql_types { pub struct VoteShowEnum; } +diesel::table! { + admin_add (id) { + id -> Int4, + mod_person_id -> Int4, + other_person_id -> Int4, + removed -> Bool, + published_at -> Timestamptz, + } +} + diesel::table! { admin_allow_instance (id) { id -> Int4, @@ -69,6 +79,19 @@ diesel::table! { } } +diesel::table! { + admin_ban (id) { + id -> Int4, + mod_person_id -> Int4, + other_person_id -> Int4, + reason -> Nullable, + banned -> Bool, + expires_at -> Nullable, + published_at -> Timestamptz, + instance_id -> Int4, + } +} + diesel::table! { admin_block_instance (id) { id -> Int4, @@ -119,6 +142,17 @@ diesel::table! { } } +diesel::table! { + admin_remove_community (id) { + id -> Int4, + mod_person_id -> Int4, + community_id -> Int4, + reason -> Nullable, + removed -> Bool, + published_at -> Timestamptz, + } +} + diesel::table! { captcha_answer (uuid) { uuid -> Uuid, @@ -563,17 +597,7 @@ diesel::table! { } diesel::table! { - mod_add (id) { - id -> Int4, - mod_person_id -> Int4, - other_person_id -> Int4, - removed -> Bool, - published_at -> Timestamptz, - } -} - -diesel::table! { - mod_add_community (id) { + mod_add_to_community (id) { id -> Int4, mod_person_id -> Int4, other_person_id -> Int4, @@ -583,19 +607,6 @@ diesel::table! { } } -diesel::table! { - mod_ban (id) { - id -> Int4, - mod_person_id -> Int4, - other_person_id -> Int4, - reason -> Nullable, - banned -> Bool, - expires_at -> Nullable, - published_at -> Timestamptz, - instance_id -> Int4, - } -} - diesel::table! { mod_ban_from_community (id) { id -> Int4, @@ -655,17 +666,6 @@ diesel::table! { } } -diesel::table! { - mod_remove_community (id) { - id -> Int4, - mod_person_id -> Int4, - community_id -> Int4, - reason -> Nullable, - removed -> Bool, - published_at -> Timestamptz, - } -} - diesel::table! { mod_remove_post (id) { id -> Int4, @@ -697,14 +697,14 @@ diesel::table! { admin_purge_community_id -> Nullable, admin_purge_person_id -> Nullable, admin_purge_post_id -> Nullable, - mod_add_id -> Nullable, - mod_add_community_id -> Nullable, - mod_ban_id -> Nullable, + admin_add_id -> Nullable, + mod_add_to_community_id -> Nullable, + admin_ban_id -> Nullable, mod_ban_from_community_id -> Nullable, mod_feature_post_id -> Nullable, mod_lock_post_id -> Nullable, mod_remove_comment_id -> Nullable, - mod_remove_community_id -> Nullable, + admin_remove_community_id -> Nullable, mod_remove_post_id -> Nullable, mod_transfer_community_id -> Nullable, mod_change_community_visibility_id -> Nullable, @@ -1136,6 +1136,7 @@ diesel::table! { diesel::joinable!(admin_allow_instance -> instance (instance_id)); diesel::joinable!(admin_allow_instance -> person (admin_person_id)); +diesel::joinable!(admin_ban -> instance (instance_id)); diesel::joinable!(admin_block_instance -> instance (instance_id)); diesel::joinable!(admin_block_instance -> person (admin_person_id)); diesel::joinable!(admin_purge_comment -> person (admin_person_id)); @@ -1144,6 +1145,8 @@ diesel::joinable!(admin_purge_community -> person (admin_person_id)); diesel::joinable!(admin_purge_person -> person (admin_person_id)); diesel::joinable!(admin_purge_post -> community (community_id)); diesel::joinable!(admin_purge_post -> person (admin_person_id)); +diesel::joinable!(admin_remove_community -> community (community_id)); +diesel::joinable!(admin_remove_community -> person (mod_person_id)); diesel::joinable!(comment -> language (language_id)); diesel::joinable!(comment -> person (creator_id)); diesel::joinable!(comment -> post (post_id)); @@ -1173,8 +1176,7 @@ diesel::joinable!(local_user_keyword_block -> local_user (local_user_id)); diesel::joinable!(local_user_language -> language (language_id)); diesel::joinable!(local_user_language -> local_user (local_user_id)); diesel::joinable!(login_token -> local_user (user_id)); -diesel::joinable!(mod_add_community -> community (community_id)); -diesel::joinable!(mod_ban -> instance (instance_id)); +diesel::joinable!(mod_add_to_community -> community (community_id)); diesel::joinable!(mod_ban_from_community -> community (community_id)); diesel::joinable!(mod_change_community_visibility -> community (community_id)); diesel::joinable!(mod_change_community_visibility -> person (mod_person_id)); @@ -1184,26 +1186,24 @@ diesel::joinable!(mod_lock_post -> person (mod_person_id)); diesel::joinable!(mod_lock_post -> post (post_id)); diesel::joinable!(mod_remove_comment -> comment (comment_id)); diesel::joinable!(mod_remove_comment -> person (mod_person_id)); -diesel::joinable!(mod_remove_community -> community (community_id)); -diesel::joinable!(mod_remove_community -> person (mod_person_id)); diesel::joinable!(mod_remove_post -> person (mod_person_id)); diesel::joinable!(mod_remove_post -> post (post_id)); diesel::joinable!(mod_transfer_community -> community (community_id)); +diesel::joinable!(modlog_combined -> admin_add (admin_add_id)); diesel::joinable!(modlog_combined -> admin_allow_instance (admin_allow_instance_id)); +diesel::joinable!(modlog_combined -> admin_ban (admin_ban_id)); diesel::joinable!(modlog_combined -> admin_block_instance (admin_block_instance_id)); diesel::joinable!(modlog_combined -> admin_purge_comment (admin_purge_comment_id)); diesel::joinable!(modlog_combined -> admin_purge_community (admin_purge_community_id)); diesel::joinable!(modlog_combined -> admin_purge_person (admin_purge_person_id)); diesel::joinable!(modlog_combined -> admin_purge_post (admin_purge_post_id)); -diesel::joinable!(modlog_combined -> mod_add (mod_add_id)); -diesel::joinable!(modlog_combined -> mod_add_community (mod_add_community_id)); -diesel::joinable!(modlog_combined -> mod_ban (mod_ban_id)); +diesel::joinable!(modlog_combined -> admin_remove_community (admin_remove_community_id)); +diesel::joinable!(modlog_combined -> mod_add_to_community (mod_add_to_community_id)); diesel::joinable!(modlog_combined -> mod_ban_from_community (mod_ban_from_community_id)); diesel::joinable!(modlog_combined -> mod_change_community_visibility (mod_change_community_visibility_id)); diesel::joinable!(modlog_combined -> mod_feature_post (mod_feature_post_id)); diesel::joinable!(modlog_combined -> mod_lock_post (mod_lock_post_id)); diesel::joinable!(modlog_combined -> mod_remove_comment (mod_remove_comment_id)); -diesel::joinable!(modlog_combined -> mod_remove_community (mod_remove_community_id)); diesel::joinable!(modlog_combined -> mod_remove_post (mod_remove_post_id)); diesel::joinable!(modlog_combined -> mod_transfer_community (mod_transfer_community_id)); diesel::joinable!(multi_community -> instance (instance_id)); @@ -1254,12 +1254,15 @@ diesel::joinable!(site_language -> site (site_id)); diesel::joinable!(tag -> community (community_id)); diesel::allow_tables_to_appear_in_same_query!( + admin_add, admin_allow_instance, + admin_ban, admin_block_instance, admin_purge_comment, admin_purge_community, admin_purge_person, admin_purge_post, + admin_remove_community, captcha_answer, comment, comment_actions, @@ -1287,15 +1290,12 @@ diesel::allow_tables_to_appear_in_same_query!( local_user_keyword_block, local_user_language, login_token, - mod_add, - mod_add_community, - mod_ban, + mod_add_to_community, mod_ban_from_community, mod_change_community_visibility, mod_feature_post, mod_lock_post, mod_remove_comment, - mod_remove_community, mod_remove_post, mod_transfer_community, modlog_combined, diff --git a/crates/db_schema_setup/replaceable_schema/triggers.sql b/crates/db_schema_setup/replaceable_schema/triggers.sql index 3e8aa1b9d..6963192e0 100644 --- a/crates/db_schema_setup/replaceable_schema/triggers.sql +++ b/crates/db_schema_setup/replaceable_schema/triggers.sql @@ -602,15 +602,15 @@ CALL r.create_modlog_combined_trigger ('admin_purge_comment'); CALL r.create_modlog_combined_trigger ('admin_purge_community'); CALL r.create_modlog_combined_trigger ('admin_purge_person'); CALL r.create_modlog_combined_trigger ('admin_purge_post'); -CALL r.create_modlog_combined_trigger ('mod_add'); -CALL r.create_modlog_combined_trigger ('mod_add_community'); -CALL r.create_modlog_combined_trigger ('mod_ban'); +CALL r.create_modlog_combined_trigger ('admin_add'); +CALL r.create_modlog_combined_trigger ('mod_add_to_community'); +CALL r.create_modlog_combined_trigger ('admin_ban'); CALL r.create_modlog_combined_trigger ('mod_ban_from_community'); CALL r.create_modlog_combined_trigger ('mod_feature_post'); CALL r.create_modlog_combined_trigger ('mod_change_community_visibility'); CALL r.create_modlog_combined_trigger ('mod_lock_post'); CALL r.create_modlog_combined_trigger ('mod_remove_comment'); -CALL r.create_modlog_combined_trigger ('mod_remove_community'); +CALL r.create_modlog_combined_trigger ('admin_remove_community'); CALL r.create_modlog_combined_trigger ('mod_remove_post'); CALL r.create_modlog_combined_trigger ('mod_transfer_community'); -- Prevent using delete instead of uplete on action tables diff --git a/crates/db_views/modlog_combined/src/impls.rs b/crates/db_views/modlog_combined/src/impls.rs index 4f8c5289c..fb897e69b 100644 --- a/crates/db_views/modlog_combined/src/impls.rs +++ b/crates/db_views/modlog_combined/src/impls.rs @@ -1,19 +1,19 @@ use crate::{ + AdminAddView, AdminAllowInstanceView, + AdminBanView, AdminBlockInstanceView, AdminPurgeCommentView, AdminPurgeCommunityView, AdminPurgePersonView, AdminPurgePostView, - ModAddCommunityView, - ModAddView, + AdminRemoveCommunityView, + ModAddToCommunityView, ModBanFromCommunityView, - ModBanView, ModChangeCommunityVisibilityView, ModFeaturePostView, ModLockPostView, ModRemoveCommentView, - ModRemoveCommunityView, ModRemovePostView, ModTransferCommunityView, ModlogCombinedView, @@ -50,25 +50,25 @@ use lemmy_db_schema::{ use lemmy_db_schema_file::{ enums::ListingType, schema::{ + admin_add, admin_allow_instance, + admin_ban, admin_block_instance, admin_purge_comment, admin_purge_community, admin_purge_person, admin_purge_post, + admin_remove_community, comment, community, community_actions, instance, - mod_add, - mod_add_community, - mod_ban, + mod_add_to_community, mod_ban_from_community, mod_change_community_visibility, mod_feature_post, mod_lock_post, mod_remove_comment, - mod_remove_community, mod_remove_post, mod_transfer_community, modlog_combined, @@ -95,24 +95,24 @@ impl ModlogCombinedViewInternal { .or(admin_purge_community::admin_person_id.eq(person::id)) .or(admin_purge_person::admin_person_id.eq(person::id)) .or(admin_purge_post::admin_person_id.eq(person::id)) - .or(mod_add::mod_person_id.eq(person::id)) - .or(mod_add_community::mod_person_id.eq(person::id)) - .or(mod_ban::mod_person_id.eq(person::id)) + .or(admin_add::mod_person_id.eq(person::id)) + .or(mod_add_to_community::mod_person_id.eq(person::id)) + .or(admin_ban::mod_person_id.eq(person::id)) .or(mod_ban_from_community::mod_person_id.eq(person::id)) .or(mod_feature_post::mod_person_id.eq(person::id)) .or(mod_change_community_visibility::mod_person_id.eq(person::id)) .or(mod_lock_post::mod_person_id.eq(person::id)) .or(mod_remove_comment::mod_person_id.eq(person::id)) - .or(mod_remove_community::mod_person_id.eq(person::id)) + .or(admin_remove_community::mod_person_id.eq(person::id)) .or(mod_remove_post::mod_person_id.eq(person::id)) .or(mod_transfer_community::mod_person_id.eq(person::id)), ); let other_person_join = aliases::person1.on( - mod_add::other_person_id + admin_add::other_person_id .eq(other_person) - .or(mod_add_community::other_person_id.eq(other_person)) - .or(mod_ban::other_person_id.eq(other_person)) + .or(mod_add_to_community::other_person_id.eq(other_person)) + .or(admin_ban::other_person_id.eq(other_person)) .or(mod_ban_from_community::other_person_id.eq(other_person)) // Some tables don't have the other_person_id directly, so you need to join .or( @@ -156,7 +156,7 @@ impl ModlogCombinedViewInternal { let community_join = community::table.on( admin_purge_post::community_id .eq(community::id) - .or(mod_add_community::community_id.eq(community::id)) + .or(mod_add_to_community::community_id.eq(community::id)) .or(mod_ban_from_community::community_id.eq(community::id)) .or( mod_feature_post::id @@ -174,7 +174,7 @@ impl ModlogCombinedViewInternal { .is_not_null() .and(post::community_id.eq(community::id)), ) - .or(mod_remove_community::community_id.eq(community::id)) + .or(admin_remove_community::community_id.eq(community::id)) .or( mod_remove_post::id .is_not_null() @@ -202,15 +202,15 @@ impl ModlogCombinedViewInternal { .left_join(admin_purge_community::table) .left_join(admin_purge_person::table) .left_join(admin_purge_post::table) - .left_join(mod_add::table) - .left_join(mod_add_community::table) - .left_join(mod_ban::table) + .left_join(admin_add::table) + .left_join(mod_add_to_community::table) + .left_join(admin_ban::table) .left_join(mod_ban_from_community::table) .left_join(mod_feature_post::table) .left_join(mod_change_community_visibility::table) .left_join(mod_lock_post::table) .left_join(mod_remove_comment::table) - .left_join(mod_remove_community::table) + .left_join(admin_remove_community::table) .left_join(mod_remove_post::table) .left_join(mod_transfer_community::table) .left_join(moderator_join) @@ -234,15 +234,15 @@ impl PaginationCursorBuilder for ModlogCombinedView { AdminPurgeCommunity(v) => ('D', v.admin_purge_community.id.0), AdminPurgePerson(v) => ('E', v.admin_purge_person.id.0), AdminPurgePost(v) => ('F', v.admin_purge_post.id.0), - ModAdd(v) => ('G', v.mod_add.id.0), - ModAddCommunity(v) => ('H', v.mod_add_community.id.0), - ModBan(v) => ('I', v.mod_ban.id.0), + AdminAdd(v) => ('G', v.admin_add.id.0), + ModAddToCommunity(v) => ('H', v.mod_add_to_community.id.0), + AdminBan(v) => ('I', v.admin_ban.id.0), ModBanFromCommunity(v) => ('J', v.mod_ban_from_community.id.0), ModFeaturePost(v) => ('K', v.mod_feature_post.id.0), ModChangeCommunityVisibility(v) => ('L', v.mod_change_community_visibility.id.0), ModLockPost(v) => ('M', v.mod_lock_post.id.0), ModRemoveComment(v) => ('N', v.mod_remove_comment.id.0), - ModRemoveCommunity(v) => ('O', v.mod_remove_community.id.0), + AdminRemoveCommunity(v) => ('O', v.admin_remove_community.id.0), ModRemovePost(v) => ('P', v.mod_remove_post.id.0), ModTransferCommunity(v) => ('Q', v.mod_transfer_community.id.0), }; @@ -271,15 +271,15 @@ impl PaginationCursorBuilder for ModlogCombinedView { 'D' => query.filter(modlog_combined::admin_purge_community_id.eq(id)), 'E' => query.filter(modlog_combined::admin_purge_person_id.eq(id)), 'F' => query.filter(modlog_combined::admin_purge_post_id.eq(id)), - 'G' => query.filter(modlog_combined::mod_add_id.eq(id)), - 'H' => query.filter(modlog_combined::mod_add_community_id.eq(id)), - 'I' => query.filter(modlog_combined::mod_ban_id.eq(id)), + 'G' => query.filter(modlog_combined::admin_add_id.eq(id)), + 'H' => query.filter(modlog_combined::mod_add_to_community_id.eq(id)), + 'I' => query.filter(modlog_combined::admin_ban_id.eq(id)), 'J' => query.filter(modlog_combined::mod_ban_from_community_id.eq(id)), 'K' => query.filter(modlog_combined::mod_feature_post_id.eq(id)), 'L' => query.filter(modlog_combined::mod_change_community_visibility_id.eq(id)), 'M' => query.filter(modlog_combined::mod_lock_post_id.eq(id)), 'N' => query.filter(modlog_combined::mod_remove_comment_id.eq(id)), - 'O' => query.filter(modlog_combined::mod_remove_community_id.eq(id)), + 'O' => query.filter(modlog_combined::admin_remove_community_id.eq(id)), 'P' => query.filter(modlog_combined::mod_remove_post_id.eq(id)), 'Q' => query.filter(modlog_combined::mod_transfer_community_id.eq(id)), _ => return Err(LemmyErrorType::CouldntParsePaginationToken.into()), @@ -349,16 +349,18 @@ impl ModlogCombinedQuery<'_> { ModLockPost => query.filter(modlog_combined::mod_lock_post_id.is_not_null()), ModFeaturePost => query.filter(modlog_combined::mod_feature_post_id.is_not_null()), ModRemoveComment => query.filter(modlog_combined::mod_remove_comment_id.is_not_null()), - ModRemoveCommunity => query.filter(modlog_combined::mod_remove_community_id.is_not_null()), + AdminRemoveCommunity => { + query.filter(modlog_combined::admin_remove_community_id.is_not_null()) + } ModBanFromCommunity => { query.filter(modlog_combined::mod_ban_from_community_id.is_not_null()) } - ModAddCommunity => query.filter(modlog_combined::mod_add_community_id.is_not_null()), + ModAddToCommunity => query.filter(modlog_combined::mod_add_to_community_id.is_not_null()), ModTransferCommunity => { query.filter(modlog_combined::mod_transfer_community_id.is_not_null()) } - ModAdd => query.filter(modlog_combined::mod_add_id.is_not_null()), - ModBan => query.filter(modlog_combined::mod_ban_id.is_not_null()), + AdminAdd => query.filter(modlog_combined::admin_add_id.is_not_null()), + AdminBan => query.filter(modlog_combined::admin_ban_id.is_not_null()), ModChangeCommunityVisibility => { query.filter(modlog_combined::mod_change_community_visibility_id.is_not_null()) } @@ -484,26 +486,28 @@ impl InternalToCombinedView for ModlogCombinedViewInternal { admin: v.moderator, community, })) - } else if let (Some(mod_add), Some(other_person)) = (v.mod_add, v.other_person.clone()) { - Some(ModlogCombinedView::ModAdd(ModAddView { - mod_add, + } else if let (Some(admin_add), Some(other_person)) = (v.admin_add, v.other_person.clone()) { + Some(ModlogCombinedView::AdminAdd(AdminAddView { + admin_add, moderator: v.moderator, other_person, })) - } else if let (Some(mod_add_community), Some(other_person), Some(community)) = ( - v.mod_add_community, + } else if let (Some(mod_add_to_community), Some(other_person), Some(community)) = ( + v.mod_add_to_community, v.other_person.clone(), v.community.clone(), ) { - Some(ModlogCombinedView::ModAddCommunity(ModAddCommunityView { - mod_add_community, - moderator: v.moderator, - other_person, - community, - })) - } else if let (Some(mod_ban), Some(other_person)) = (v.mod_ban, v.other_person.clone()) { - Some(ModlogCombinedView::ModBan(ModBanView { - mod_ban, + Some(ModlogCombinedView::ModAddToCommunity( + ModAddToCommunityView { + mod_add_to_community, + moderator: v.moderator, + other_person, + community, + }, + )) + } else if let (Some(admin_ban), Some(other_person)) = (v.admin_ban, v.other_person.clone()) { + Some(ModlogCombinedView::AdminBan(AdminBanView { + admin_ban, moderator: v.moderator, other_person, })) @@ -577,12 +581,12 @@ impl InternalToCombinedView for ModlogCombinedViewInternal { post, comment, })) - } else if let (Some(mod_remove_community), Some(community)) = - (v.mod_remove_community, v.community.clone()) + } else if let (Some(admin_remove_community), Some(community)) = + (v.admin_remove_community, v.community.clone()) { - Some(ModlogCombinedView::ModRemoveCommunity( - ModRemoveCommunityView { - mod_remove_community, + Some(ModlogCombinedView::AdminRemoveCommunity( + AdminRemoveCommunityView { + admin_remove_community, moderator: v.moderator, community, }, @@ -622,8 +626,8 @@ impl InternalToCombinedView for ModlogCombinedViewInternal { #[cfg(test)] #[expect(clippy::indexing_slicing)] mod tests { - - use crate::{impls::ModlogCombinedQuery, ModlogCombinedView}; + use super::*; + use crate::AdminAllowInstance; use lemmy_db_schema::{ newtypes::PersonId, source::{ @@ -632,8 +636,11 @@ mod tests { instance::Instance, mod_log::{ admin::{ - AdminAllowInstance, + AdminAdd, + AdminAddForm, AdminAllowInstanceForm, + AdminBan, + AdminBanForm, AdminBlockInstance, AdminBlockInstanceForm, AdminPurgeComment, @@ -644,14 +651,12 @@ mod tests { AdminPurgePersonForm, AdminPurgePost, AdminPurgePostForm, + AdminRemoveCommunity, + AdminRemoveCommunityForm, }, moderator::{ - ModAdd, - ModAddCommunity, - ModAddCommunityForm, - ModAddForm, - ModBan, - ModBanForm, + ModAddToCommunity, + ModAddToCommunityForm, ModBanFromCommunity, ModBanFromCommunityForm, ModChangeCommunityVisibility, @@ -662,8 +667,6 @@ mod tests { ModLockPostForm, ModRemoveComment, ModRemoveCommentForm, - ModRemoveCommunity, - ModRemoveCommunityForm, ModRemovePost, ModRemovePostForm, ModTransferCommunity, @@ -988,22 +991,22 @@ mod tests { let pool = &mut pool.into(); let data = init_data(pool).await?; - let form = ModAddForm { + let form = AdminAddForm { mod_person_id: data.timmy.id, other_person_id: data.jessica.id, removed: Some(false), }; - ModAdd::create(pool, &form).await?; + AdminAdd::create(pool, &form).await?; - let form = ModAddCommunityForm { + let form = ModAddToCommunityForm { mod_person_id: data.timmy.id, other_person_id: data.jessica.id, community_id: data.community.id, removed: Some(false), }; - ModAddCommunity::create(pool, &form).await?; + ModAddToCommunity::create(pool, &form).await?; - let form = ModBanForm { + let form = AdminBanForm { mod_person_id: data.timmy.id, other_person_id: data.jessica.id, banned: Some(true), @@ -1011,7 +1014,7 @@ mod tests { expires_at: None, instance_id: data.instance.id, }; - ModBan::create(pool, &form).await?; + AdminBan::create(pool, &form).await?; let form = ModBanFromCommunityForm { mod_person_id: data.timmy.id, @@ -1047,13 +1050,13 @@ mod tests { }; ModRemoveComment::create(pool, &form).await?; - let form = ModRemoveCommunityForm { + let form = AdminRemoveCommunityForm { mod_person_id: data.timmy.id, community_id: data.community.id, removed: Some(true), reason: None, }; - ModRemoveCommunity::create(pool, &form).await?; + AdminRemoveCommunity::create(pool, &form).await?; let form = ModRemovePostForm { mod_person_id: data.timmy.id, @@ -1164,8 +1167,8 @@ mod tests { panic!("wrong type"); } - if let ModlogCombinedView::ModRemoveCommunity(v) = &modlog[5] { - assert_eq!(data.community.id, v.mod_remove_community.community_id); + if let ModlogCombinedView::AdminRemoveCommunity(v) = &modlog[5] { + assert_eq!(data.community.id, v.admin_remove_community.community_id); assert_eq!(data.community.id, v.community.id); assert_eq!( data.timmy.id, @@ -1231,7 +1234,7 @@ mod tests { panic!("wrong type"); } - if let ModlogCombinedView::ModBan(v) = &modlog[10] { + if let ModlogCombinedView::AdminBan(v) = &modlog[10] { assert_eq!( data.timmy.id, v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1)) @@ -1241,8 +1244,8 @@ mod tests { panic!("wrong type"); } - if let ModlogCombinedView::ModAddCommunity(v) = &modlog[11] { - assert_eq!(data.community.id, v.mod_add_community.community_id); + if let ModlogCombinedView::ModAddToCommunity(v) = &modlog[11] { + assert_eq!(data.community.id, v.mod_add_to_community.community_id); assert_eq!(data.community.id, v.community.id); assert_eq!( data.timmy.id, @@ -1253,7 +1256,7 @@ mod tests { panic!("wrong type"); } - if let ModlogCombinedView::ModAdd(v) = &modlog[12] { + if let ModlogCombinedView::AdminAdd(v) = &modlog[12] { assert_eq!( data.timmy.id, v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1)) diff --git a/crates/db_views/modlog_combined/src/lib.rs b/crates/db_views/modlog_combined/src/lib.rs index 5f1acdf80..6d1a45abf 100644 --- a/crates/db_views/modlog_combined/src/lib.rs +++ b/crates/db_views/modlog_combined/src/lib.rs @@ -4,23 +4,23 @@ use lemmy_db_schema::source::{ instance::Instance, mod_log::{ admin::{ + AdminAdd, AdminAllowInstance, + AdminBan, AdminBlockInstance, AdminPurgeComment, AdminPurgeCommunity, AdminPurgePerson, AdminPurgePost, + AdminRemoveCommunity, }, moderator::{ - ModAdd, - ModAddCommunity, - ModBan, + ModAddToCommunity, ModBanFromCommunity, ModChangeCommunityVisibility, ModFeaturePost, ModLockPost, ModRemoveComment, - ModRemoveCommunity, ModRemovePost, ModTransferCommunity, }, @@ -47,8 +47,8 @@ pub mod impls; #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))] #[cfg_attr(feature = "ts-rs", ts(optional_fields, export))] /// When someone is added as a community moderator. -pub struct ModAddCommunityView { - pub mod_add_community: ModAddCommunity, +pub struct ModAddToCommunityView { + pub mod_add_to_community: ModAddToCommunity, pub moderator: Option, pub community: Community, pub other_person: Person, @@ -61,8 +61,8 @@ pub struct ModAddCommunityView { #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))] #[cfg_attr(feature = "ts-rs", ts(optional_fields, export))] /// When someone is added as a site moderator. -pub struct ModAddView { - pub mod_add: ModAdd, +pub struct AdminAddView { + pub admin_add: AdminAdd, pub moderator: Option, pub other_person: Person, } @@ -88,8 +88,8 @@ pub struct ModBanFromCommunityView { #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))] #[cfg_attr(feature = "ts-rs", ts(optional_fields, export))] /// When someone is banned from the site. -pub struct ModBanView { - pub mod_ban: ModBan, +pub struct AdminBanView { + pub admin_ban: AdminBan, pub moderator: Option, pub other_person: Person, } @@ -144,9 +144,9 @@ pub struct ModRemoveCommentView { #[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))] #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))] #[cfg_attr(feature = "ts-rs", ts(optional_fields, export))] -/// When a moderator removes a community. -pub struct ModRemoveCommunityView { - pub mod_remove_community: ModRemoveCommunity, +/// When an admin removes a community. +pub struct AdminRemoveCommunityView { + pub admin_remove_community: AdminRemoveCommunity, pub moderator: Option, pub community: Community, } @@ -290,11 +290,11 @@ pub(crate) struct ModlogCombinedViewInternal { #[cfg_attr(feature = "full", diesel(embed))] pub admin_purge_post: Option, #[cfg_attr(feature = "full", diesel(embed))] - pub mod_add: Option, + pub admin_add: Option, #[cfg_attr(feature = "full", diesel(embed))] - pub mod_add_community: Option, + pub mod_add_to_community: Option, #[cfg_attr(feature = "full", diesel(embed))] - pub mod_ban: Option, + pub admin_ban: Option, #[cfg_attr(feature = "full", diesel(embed))] pub mod_ban_from_community: Option, #[cfg_attr(feature = "full", diesel(embed))] @@ -306,7 +306,7 @@ pub(crate) struct ModlogCombinedViewInternal { #[cfg_attr(feature = "full", diesel(embed))] pub mod_remove_comment: Option, #[cfg_attr(feature = "full", diesel(embed))] - pub mod_remove_community: Option, + pub admin_remove_community: Option, #[cfg_attr(feature = "full", diesel(embed))] pub mod_remove_post: Option, #[cfg_attr(feature = "full", diesel(embed))] @@ -345,15 +345,15 @@ pub enum ModlogCombinedView { AdminPurgeCommunity(AdminPurgeCommunityView), AdminPurgePerson(AdminPurgePersonView), AdminPurgePost(AdminPurgePostView), - ModAdd(ModAddView), - ModAddCommunity(ModAddCommunityView), - ModBan(ModBanView), + AdminAdd(AdminAddView), + ModAddToCommunity(ModAddToCommunityView), + AdminBan(AdminBanView), ModBanFromCommunity(ModBanFromCommunityView), ModFeaturePost(ModFeaturePostView), ModChangeCommunityVisibility(ModChangeCommunityVisibilityView), ModLockPost(ModLockPostView), ModRemoveComment(ModRemoveCommentView), - ModRemoveCommunity(ModRemoveCommunityView), + AdminRemoveCommunity(AdminRemoveCommunityView), ModRemovePost(ModRemovePostView), ModTransferCommunity(ModTransferCommunityView), } diff --git a/crates/routes/src/feeds.rs b/crates/routes/src/feeds.rs index 4c87a2add..1e0f7e6fd 100644 --- a/crates/routes/src/feeds.rs +++ b/crates/routes/src/feeds.rs @@ -504,41 +504,41 @@ fn create_modlog_items( &v.admin_purge_post.reason, settings, ), - ModlogCombinedView::ModAdd(v) => build_modlog_item( + ModlogCombinedView::AdminAdd(v) => build_modlog_item( &v.moderator, - &v.mod_add.published_at, + &v.admin_add.published_at, &modlog_url, &format!( "{} admin {}", - removed_added_str(v.mod_add.removed), + removed_added_str(v.admin_add.removed), &v.other_person.name ), &None, settings, ), - ModlogCombinedView::ModAddCommunity(v) => build_modlog_item( + ModlogCombinedView::ModAddToCommunity(v) => build_modlog_item( &v.moderator, - &v.mod_add_community.published_at, + &v.mod_add_to_community.published_at, &modlog_url, &format!( "{} mod {} to /c/{}", - removed_added_str(v.mod_add_community.removed), + removed_added_str(v.mod_add_to_community.removed), &v.other_person.name, &v.community.name ), &None, settings, ), - ModlogCombinedView::ModBan(v) => build_modlog_item( + ModlogCombinedView::AdminBan(v) => build_modlog_item( &v.moderator, - &v.mod_ban.published_at, + &v.admin_ban.published_at, &modlog_url, &format!( "{} {}", - banned_unbanned_str(v.mod_ban.banned), + banned_unbanned_str(v.admin_ban.banned), &v.other_person.name ), - &v.mod_ban.reason, + &v.admin_ban.reason, settings, ), ModlogCombinedView::ModBanFromCommunity(v) => build_modlog_item( @@ -609,16 +609,16 @@ fn create_modlog_items( &v.mod_remove_comment.reason, settings, ), - ModlogCombinedView::ModRemoveCommunity(v) => build_modlog_item( + ModlogCombinedView::AdminRemoveCommunity(v) => build_modlog_item( &v.moderator, - &v.mod_remove_community.published_at, + &v.admin_remove_community.published_at, &modlog_url, &format!( "{} community /c/{}", - removed_restored_str(v.mod_remove_community.removed), + removed_restored_str(v.admin_remove_community.removed), &v.community.name ), - &v.mod_remove_community.reason, + &v.admin_remove_community.reason, settings, ), ModlogCombinedView::ModRemovePost(v) => build_modlog_item( diff --git a/migrations/2025-07-24-092826_modlog-rename/down.sql b/migrations/2025-07-24-092826_modlog-rename/down.sql new file mode 100644 index 000000000..ef67ddae2 --- /dev/null +++ b/migrations/2025-07-24-092826_modlog-rename/down.sql @@ -0,0 +1,16 @@ +ALTER TABLE admin_ban RENAME TO mod_ban; + +ALTER TABLE admin_add RENAME TO mod_add; + +ALTER TABLE admin_remove_community RENAME TO mod_remove_community; + +ALTER TABLE mod_add_to_community RENAME TO mod_add_community; + +ALTER TABLE modlog_combined RENAME COLUMN admin_ban_id TO mod_ban_id; + +ALTER TABLE modlog_combined RENAME COLUMN admin_add_id TO mod_add_id; + +ALTER TABLE modlog_combined RENAME COLUMN admin_remove_community_id TO mod_remove_community_id; + +ALTER TABLE modlog_combined RENAME COLUMN mod_add_to_community_id TO mod_add_community_id; + diff --git a/migrations/2025-07-24-092826_modlog-rename/up.sql b/migrations/2025-07-24-092826_modlog-rename/up.sql new file mode 100644 index 000000000..ce65e36d1 --- /dev/null +++ b/migrations/2025-07-24-092826_modlog-rename/up.sql @@ -0,0 +1,16 @@ +ALTER TABLE mod_ban RENAME TO admin_ban; + +ALTER TABLE mod_add RENAME TO admin_add; + +ALTER TABLE mod_remove_community RENAME TO admin_remove_community; + +ALTER TABLE mod_add_community RENAME TO mod_add_to_community; + +ALTER TABLE modlog_combined RENAME COLUMN mod_ban_id TO admin_ban_id; + +ALTER TABLE modlog_combined RENAME COLUMN mod_add_id TO admin_add_id; + +ALTER TABLE modlog_combined RENAME COLUMN mod_remove_community_id TO admin_remove_community_id; + +ALTER TABLE modlog_combined RENAME COLUMN mod_add_community_id TO mod_add_to_community_id; +