mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-22 19:01:32 +00:00
Adding types, fixing allow and blocklist crud.
This commit is contained in:
parent
58e62d55d9
commit
15d1faad72
14 changed files with 627 additions and 195 deletions
|
@ -7,10 +7,13 @@ use lemmy_api_common::{
|
|||
LemmyErrorType,
|
||||
SuccessResponse,
|
||||
};
|
||||
use lemmy_db_schema::source::{
|
||||
federation_allowlist::{FederationAllowList, FederationAllowListForm},
|
||||
instance::Instance,
|
||||
mod_log::admin::{AdminAllowInstance, AdminAllowInstanceForm},
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
federation_allowlist::{FederationAllowList, FederationAllowListForm},
|
||||
instance::Instance,
|
||||
mod_log::admin::{AdminAllowInstance, AdminAllowInstanceForm},
|
||||
},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_db_views::structs::LocalUserView;
|
||||
use lemmy_utils::error::LemmyResult;
|
||||
|
@ -47,7 +50,7 @@ pub async fn admin_allow_instance(
|
|||
reason: data.reason.clone(),
|
||||
allowed: data.allow,
|
||||
};
|
||||
AdminAllowInstance::insert(&mut context.pool(), &mod_log_form).await?;
|
||||
AdminAllowInstance::create(&mut context.pool(), &mod_log_form).await?;
|
||||
|
||||
Ok(Json(SuccessResponse::default()))
|
||||
}
|
||||
|
|
|
@ -7,10 +7,13 @@ use lemmy_api_common::{
|
|||
LemmyErrorType,
|
||||
SuccessResponse,
|
||||
};
|
||||
use lemmy_db_schema::source::{
|
||||
federation_blocklist::{FederationBlockList, FederationBlockListForm},
|
||||
instance::Instance,
|
||||
mod_log::admin::{AdminBlockInstance, AdminBlockInstanceForm},
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
federation_blocklist::{FederationBlockList, FederationBlockListForm},
|
||||
instance::Instance,
|
||||
mod_log::admin::{AdminBlockInstance, AdminBlockInstanceForm},
|
||||
},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_db_views::structs::LocalUserView;
|
||||
use lemmy_utils::error::LemmyResult;
|
||||
|
@ -50,7 +53,7 @@ pub async fn admin_block_instance(
|
|||
reason: data.reason.clone(),
|
||||
when_: data.expires,
|
||||
};
|
||||
AdminBlockInstance::insert(&mut context.pool(), &mod_log_form).await?;
|
||||
AdminBlockInstance::create(&mut context.pool(), &mod_log_form).await?;
|
||||
|
||||
Ok(Json(SuccessResponse::default()))
|
||||
}
|
||||
|
|
|
@ -1,43 +1,25 @@
|
|||
use crate::{
|
||||
newtypes::InstanceId,
|
||||
schema::{admin_allow_instance, federation_allowlist},
|
||||
source::{
|
||||
federation_allowlist::{FederationAllowList, FederationAllowListForm},
|
||||
mod_log::admin::{AdminAllowInstance, AdminAllowInstanceForm},
|
||||
},
|
||||
schema::federation_allowlist,
|
||||
source::federation_allowlist::{FederationAllowList, FederationAllowListForm},
|
||||
utils::{get_conn, DbPool},
|
||||
};
|
||||
use diesel::{delete, dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||
use diesel_async::RunQueryDsl;
|
||||
|
||||
impl AdminAllowInstance {
|
||||
pub async fn insert(pool: &mut DbPool<'_>, form: &AdminAllowInstanceForm) -> Result<(), Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(admin_allow_instance::table)
|
||||
.values(form)
|
||||
.execute(conn)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl FederationAllowList {
|
||||
pub async fn allow(pool: &mut DbPool<'_>, form: &FederationAllowListForm) -> Result<(), Error> {
|
||||
pub async fn allow(pool: &mut DbPool<'_>, form: &FederationAllowListForm) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(federation_allowlist::table)
|
||||
.values(form)
|
||||
.execute(conn)
|
||||
.await?;
|
||||
Ok(())
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
}
|
||||
pub async fn unallow(pool: &mut DbPool<'_>, instance_id_: InstanceId) -> Result<(), Error> {
|
||||
use federation_allowlist::dsl::instance_id;
|
||||
pub async fn unallow(pool: &mut DbPool<'_>, instance_id_: InstanceId) -> Result<usize, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
delete(federation_allowlist::table.filter(instance_id.eq(instance_id_)))
|
||||
delete(federation_allowlist::table.filter(federation_allowlist::instance_id.eq(instance_id_)))
|
||||
.execute(conn)
|
||||
.await?;
|
||||
Ok(())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,42 +1,24 @@
|
|||
use crate::{
|
||||
newtypes::InstanceId,
|
||||
schema::{admin_block_instance, federation_blocklist},
|
||||
source::{
|
||||
federation_blocklist::{FederationBlockList, FederationBlockListForm},
|
||||
mod_log::admin::{AdminBlockInstance, AdminBlockInstanceForm},
|
||||
},
|
||||
schema::federation_blocklist,
|
||||
source::federation_blocklist::{FederationBlockList, FederationBlockListForm},
|
||||
utils::{get_conn, DbPool},
|
||||
};
|
||||
use diesel::{delete, dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||
use diesel_async::RunQueryDsl;
|
||||
|
||||
impl AdminBlockInstance {
|
||||
pub async fn insert(pool: &mut DbPool<'_>, form: &AdminBlockInstanceForm) -> Result<(), Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(admin_block_instance::table)
|
||||
.values(form)
|
||||
.execute(conn)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl FederationBlockList {
|
||||
pub async fn block(pool: &mut DbPool<'_>, form: &FederationBlockListForm) -> Result<(), Error> {
|
||||
pub async fn block(pool: &mut DbPool<'_>, form: &FederationBlockListForm) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(federation_blocklist::table)
|
||||
.values(form)
|
||||
.execute(conn)
|
||||
.await?;
|
||||
Ok(())
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
}
|
||||
pub async fn unblock(pool: &mut DbPool<'_>, instance_id_: InstanceId) -> Result<(), Error> {
|
||||
use federation_blocklist::dsl::instance_id;
|
||||
pub async fn unblock(pool: &mut DbPool<'_>, instance_id_: InstanceId) -> Result<usize, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
delete(federation_blocklist::table.filter(instance_id.eq(instance_id_)))
|
||||
delete(federation_blocklist::table.filter(federation_blocklist::instance_id.eq(instance_id_)))
|
||||
.execute(conn)
|
||||
.await?;
|
||||
Ok(())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,25 @@
|
|||
use crate::{
|
||||
newtypes::{
|
||||
AdminAllowInstanceId,
|
||||
AdminBlockInstanceId,
|
||||
AdminPurgeCommentId,
|
||||
AdminPurgeCommunityId,
|
||||
AdminPurgePersonId,
|
||||
AdminPurgePostId,
|
||||
},
|
||||
schema::{
|
||||
admin_allow_instance,
|
||||
admin_block_instance,
|
||||
admin_purge_comment,
|
||||
admin_purge_community,
|
||||
admin_purge_person,
|
||||
admin_purge_post,
|
||||
},
|
||||
source::mod_log::admin::{
|
||||
AdminAllowInstance,
|
||||
AdminAllowInstanceForm,
|
||||
AdminBlockInstance,
|
||||
AdminBlockInstanceForm,
|
||||
AdminPurgeComment,
|
||||
AdminPurgeCommentForm,
|
||||
AdminPurgeCommunity,
|
||||
|
@ -19,12 +39,11 @@ use diesel_async::RunQueryDsl;
|
|||
impl Crud for AdminPurgePerson {
|
||||
type InsertForm = AdminPurgePersonForm;
|
||||
type UpdateForm = AdminPurgePersonForm;
|
||||
type IdType = i32;
|
||||
type IdType = AdminPurgePersonId;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||
use crate::schema::admin_purge_person::dsl::admin_purge_person;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(admin_purge_person)
|
||||
insert_into(admin_purge_person::table)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -32,12 +51,11 @@ impl Crud for AdminPurgePerson {
|
|||
|
||||
async fn update(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
from_id: Self::IdType,
|
||||
form: &Self::InsertForm,
|
||||
) -> Result<Self, Error> {
|
||||
use crate::schema::admin_purge_person::dsl::admin_purge_person;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(admin_purge_person.find(from_id))
|
||||
diesel::update(admin_purge_person::table.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -48,12 +66,11 @@ impl Crud for AdminPurgePerson {
|
|||
impl Crud for AdminPurgeCommunity {
|
||||
type InsertForm = AdminPurgeCommunityForm;
|
||||
type UpdateForm = AdminPurgeCommunityForm;
|
||||
type IdType = i32;
|
||||
type IdType = AdminPurgeCommunityId;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||
use crate::schema::admin_purge_community::dsl::admin_purge_community;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(admin_purge_community)
|
||||
insert_into(admin_purge_community::table)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -61,12 +78,11 @@ impl Crud for AdminPurgeCommunity {
|
|||
|
||||
async fn update(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
from_id: Self::IdType,
|
||||
form: &Self::InsertForm,
|
||||
) -> Result<Self, Error> {
|
||||
use crate::schema::admin_purge_community::dsl::admin_purge_community;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(admin_purge_community.find(from_id))
|
||||
diesel::update(admin_purge_community::table.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -77,12 +93,11 @@ impl Crud for AdminPurgeCommunity {
|
|||
impl Crud for AdminPurgePost {
|
||||
type InsertForm = AdminPurgePostForm;
|
||||
type UpdateForm = AdminPurgePostForm;
|
||||
type IdType = i32;
|
||||
type IdType = AdminPurgePostId;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||
use crate::schema::admin_purge_post::dsl::admin_purge_post;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(admin_purge_post)
|
||||
insert_into(admin_purge_post::table)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -90,12 +105,11 @@ impl Crud for AdminPurgePost {
|
|||
|
||||
async fn update(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
from_id: Self::IdType,
|
||||
form: &Self::InsertForm,
|
||||
) -> Result<Self, Error> {
|
||||
use crate::schema::admin_purge_post::dsl::admin_purge_post;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(admin_purge_post.find(from_id))
|
||||
diesel::update(admin_purge_post::table.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -106,12 +120,11 @@ impl Crud for AdminPurgePost {
|
|||
impl Crud for AdminPurgeComment {
|
||||
type InsertForm = AdminPurgeCommentForm;
|
||||
type UpdateForm = AdminPurgeCommentForm;
|
||||
type IdType = i32;
|
||||
type IdType = AdminPurgeCommentId;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||
use crate::schema::admin_purge_comment::dsl::admin_purge_comment;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(admin_purge_comment)
|
||||
insert_into(admin_purge_comment::table)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -119,12 +132,65 @@ impl Crud for AdminPurgeComment {
|
|||
|
||||
async fn update(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
from_id: Self::IdType,
|
||||
form: &Self::InsertForm,
|
||||
) -> Result<Self, Error> {
|
||||
use crate::schema::admin_purge_comment::dsl::admin_purge_comment;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(admin_purge_comment.find(from_id))
|
||||
diesel::update(admin_purge_comment::table.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Crud for AdminAllowInstance {
|
||||
type InsertForm = AdminAllowInstanceForm;
|
||||
type UpdateForm = AdminAllowInstanceForm;
|
||||
type IdType = AdminAllowInstanceId;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(admin_allow_instance::table)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn update(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: Self::IdType,
|
||||
form: &Self::InsertForm,
|
||||
) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(admin_allow_instance::table.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Crud for AdminBlockInstance {
|
||||
type InsertForm = AdminBlockInstanceForm;
|
||||
type UpdateForm = AdminBlockInstanceForm;
|
||||
type IdType = AdminBlockInstanceId;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(admin_block_instance::table)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn update(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: Self::IdType,
|
||||
form: &Self::InsertForm,
|
||||
) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(admin_block_instance::table.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
|
|
@ -1,4 +1,30 @@
|
|||
use crate::{
|
||||
newtypes::{
|
||||
ModAddCommunityId,
|
||||
ModAddId,
|
||||
ModBanFromCommunityId,
|
||||
ModBanId,
|
||||
ModFeaturePostId,
|
||||
ModHideCommunityId,
|
||||
ModLockPostId,
|
||||
ModRemoveCommentId,
|
||||
ModRemoveCommunityId,
|
||||
ModRemovePostId,
|
||||
ModTransferCommunityId,
|
||||
},
|
||||
schema::{
|
||||
mod_add,
|
||||
mod_add_community,
|
||||
mod_ban,
|
||||
mod_ban_from_community,
|
||||
mod_feature_post,
|
||||
mod_hide_community,
|
||||
mod_lock_post,
|
||||
mod_remove_comment,
|
||||
mod_remove_community,
|
||||
mod_remove_post,
|
||||
mod_transfer_community,
|
||||
},
|
||||
source::mod_log::moderator::{
|
||||
ModAdd,
|
||||
ModAddCommunity,
|
||||
|
@ -33,12 +59,11 @@ use diesel_async::RunQueryDsl;
|
|||
impl Crud for ModRemovePost {
|
||||
type InsertForm = ModRemovePostForm;
|
||||
type UpdateForm = ModRemovePostForm;
|
||||
type IdType = i32;
|
||||
type IdType = ModRemovePostId;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &ModRemovePostForm) -> Result<Self, Error> {
|
||||
use crate::schema::mod_remove_post::dsl::mod_remove_post;
|
||||
async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(mod_remove_post)
|
||||
insert_into(mod_remove_post::table)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -46,12 +71,11 @@ impl Crud for ModRemovePost {
|
|||
|
||||
async fn update(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
form: &ModRemovePostForm,
|
||||
from_id: Self::IdType,
|
||||
form: &Self::UpdateForm,
|
||||
) -> Result<Self, Error> {
|
||||
use crate::schema::mod_remove_post::dsl::mod_remove_post;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(mod_remove_post.find(from_id))
|
||||
diesel::update(mod_remove_post::table.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -63,9 +87,8 @@ impl ModRemovePost {
|
|||
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)
|
||||
insert_into(mod_remove_post::table)
|
||||
.values(forms)
|
||||
.execute(conn)
|
||||
.await
|
||||
|
@ -76,12 +99,11 @@ impl ModRemovePost {
|
|||
impl Crud for ModLockPost {
|
||||
type InsertForm = ModLockPostForm;
|
||||
type UpdateForm = ModLockPostForm;
|
||||
type IdType = i32;
|
||||
type IdType = ModLockPostId;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &ModLockPostForm) -> Result<Self, Error> {
|
||||
use crate::schema::mod_lock_post::dsl::mod_lock_post;
|
||||
async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(mod_lock_post)
|
||||
insert_into(mod_lock_post::table)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -89,12 +111,11 @@ impl Crud for ModLockPost {
|
|||
|
||||
async fn update(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
form: &ModLockPostForm,
|
||||
from_id: Self::IdType,
|
||||
form: &Self::UpdateForm,
|
||||
) -> Result<Self, Error> {
|
||||
use crate::schema::mod_lock_post::dsl::mod_lock_post;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(mod_lock_post.find(from_id))
|
||||
diesel::update(mod_lock_post::table.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -105,12 +126,11 @@ impl Crud for ModLockPost {
|
|||
impl Crud for ModFeaturePost {
|
||||
type InsertForm = ModFeaturePostForm;
|
||||
type UpdateForm = ModFeaturePostForm;
|
||||
type IdType = i32;
|
||||
type IdType = ModFeaturePostId;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &ModFeaturePostForm) -> Result<Self, Error> {
|
||||
use crate::schema::mod_feature_post::dsl::mod_feature_post;
|
||||
async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(mod_feature_post)
|
||||
insert_into(mod_feature_post::table)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -118,12 +138,11 @@ impl Crud for ModFeaturePost {
|
|||
|
||||
async fn update(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
form: &ModFeaturePostForm,
|
||||
from_id: Self::IdType,
|
||||
form: &Self::UpdateForm,
|
||||
) -> Result<Self, Error> {
|
||||
use crate::schema::mod_feature_post::dsl::mod_feature_post;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(mod_feature_post.find(from_id))
|
||||
diesel::update(mod_feature_post::table.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -134,12 +153,11 @@ impl Crud for ModFeaturePost {
|
|||
impl Crud for ModRemoveComment {
|
||||
type InsertForm = ModRemoveCommentForm;
|
||||
type UpdateForm = ModRemoveCommentForm;
|
||||
type IdType = i32;
|
||||
type IdType = ModRemoveCommentId;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &ModRemoveCommentForm) -> Result<Self, Error> {
|
||||
use crate::schema::mod_remove_comment::dsl::mod_remove_comment;
|
||||
async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(mod_remove_comment)
|
||||
insert_into(mod_remove_comment::table)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -147,12 +165,11 @@ impl Crud for ModRemoveComment {
|
|||
|
||||
async fn update(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
form: &ModRemoveCommentForm,
|
||||
from_id: Self::IdType,
|
||||
form: &Self::UpdateForm,
|
||||
) -> Result<Self, Error> {
|
||||
use crate::schema::mod_remove_comment::dsl::mod_remove_comment;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(mod_remove_comment.find(from_id))
|
||||
diesel::update(mod_remove_comment::table.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -164,9 +181,8 @@ impl ModRemoveComment {
|
|||
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)
|
||||
insert_into(mod_remove_comment::table)
|
||||
.values(forms)
|
||||
.execute(conn)
|
||||
.await
|
||||
|
@ -177,12 +193,11 @@ impl ModRemoveComment {
|
|||
impl Crud for ModRemoveCommunity {
|
||||
type InsertForm = ModRemoveCommunityForm;
|
||||
type UpdateForm = ModRemoveCommunityForm;
|
||||
type IdType = i32;
|
||||
type IdType = ModRemoveCommunityId;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
|
||||
use crate::schema::mod_remove_community::dsl::mod_remove_community;
|
||||
async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(mod_remove_community)
|
||||
insert_into(mod_remove_community::table)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -190,12 +205,11 @@ impl Crud for ModRemoveCommunity {
|
|||
|
||||
async fn update(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
form: &ModRemoveCommunityForm,
|
||||
from_id: Self::IdType,
|
||||
form: &Self::UpdateForm,
|
||||
) -> Result<Self, Error> {
|
||||
use crate::schema::mod_remove_community::dsl::mod_remove_community;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(mod_remove_community.find(from_id))
|
||||
diesel::update(mod_remove_community::table.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -206,12 +220,11 @@ impl Crud for ModRemoveCommunity {
|
|||
impl Crud for ModBanFromCommunity {
|
||||
type InsertForm = ModBanFromCommunityForm;
|
||||
type UpdateForm = ModBanFromCommunityForm;
|
||||
type IdType = i32;
|
||||
type IdType = ModBanFromCommunityId;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
|
||||
use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community;
|
||||
async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(mod_ban_from_community)
|
||||
insert_into(mod_ban_from_community::table)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -219,12 +232,11 @@ impl Crud for ModBanFromCommunity {
|
|||
|
||||
async fn update(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
form: &ModBanFromCommunityForm,
|
||||
from_id: Self::IdType,
|
||||
form: &Self::UpdateForm,
|
||||
) -> Result<Self, Error> {
|
||||
use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(mod_ban_from_community.find(from_id))
|
||||
diesel::update(mod_ban_from_community::table.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -235,21 +247,23 @@ impl Crud for ModBanFromCommunity {
|
|||
impl Crud for ModBan {
|
||||
type InsertForm = ModBanForm;
|
||||
type UpdateForm = ModBanForm;
|
||||
type IdType = i32;
|
||||
type IdType = ModBanId;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &ModBanForm) -> Result<Self, Error> {
|
||||
use crate::schema::mod_ban::dsl::mod_ban;
|
||||
async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(mod_ban)
|
||||
insert_into(mod_ban::table)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn update(pool: &mut DbPool<'_>, from_id: i32, form: &ModBanForm) -> Result<Self, Error> {
|
||||
use crate::schema::mod_ban::dsl::mod_ban;
|
||||
async fn update(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: Self::IdType,
|
||||
form: &Self::UpdateForm,
|
||||
) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(mod_ban.find(from_id))
|
||||
diesel::update(mod_ban::table.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -260,12 +274,11 @@ impl Crud for ModBan {
|
|||
impl Crud for ModHideCommunity {
|
||||
type InsertForm = ModHideCommunityForm;
|
||||
type UpdateForm = ModHideCommunityForm;
|
||||
type IdType = i32;
|
||||
type IdType = ModHideCommunityId;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &ModHideCommunityForm) -> Result<Self, Error> {
|
||||
use crate::schema::mod_hide_community::dsl::mod_hide_community;
|
||||
async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(mod_hide_community)
|
||||
insert_into(mod_hide_community::table)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -273,12 +286,11 @@ impl Crud for ModHideCommunity {
|
|||
|
||||
async fn update(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
form: &ModHideCommunityForm,
|
||||
from_id: Self::IdType,
|
||||
form: &Self::UpdateForm,
|
||||
) -> Result<Self, Error> {
|
||||
use crate::schema::mod_hide_community::dsl::mod_hide_community;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(mod_hide_community.find(from_id))
|
||||
diesel::update(mod_hide_community::table.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -289,12 +301,11 @@ impl Crud for ModHideCommunity {
|
|||
impl Crud for ModAddCommunity {
|
||||
type InsertForm = ModAddCommunityForm;
|
||||
type UpdateForm = ModAddCommunityForm;
|
||||
type IdType = i32;
|
||||
type IdType = ModAddCommunityId;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &ModAddCommunityForm) -> Result<Self, Error> {
|
||||
use crate::schema::mod_add_community::dsl::mod_add_community;
|
||||
async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(mod_add_community)
|
||||
insert_into(mod_add_community::table)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -302,12 +313,11 @@ impl Crud for ModAddCommunity {
|
|||
|
||||
async fn update(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
form: &ModAddCommunityForm,
|
||||
from_id: Self::IdType,
|
||||
form: &Self::UpdateForm,
|
||||
) -> Result<Self, Error> {
|
||||
use crate::schema::mod_add_community::dsl::mod_add_community;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(mod_add_community.find(from_id))
|
||||
diesel::update(mod_add_community::table.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -318,12 +328,11 @@ impl Crud for ModAddCommunity {
|
|||
impl Crud for ModTransferCommunity {
|
||||
type InsertForm = ModTransferCommunityForm;
|
||||
type UpdateForm = ModTransferCommunityForm;
|
||||
type IdType = i32;
|
||||
type IdType = ModTransferCommunityId;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &ModTransferCommunityForm) -> Result<Self, Error> {
|
||||
use crate::schema::mod_transfer_community::dsl::mod_transfer_community;
|
||||
async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(mod_transfer_community)
|
||||
insert_into(mod_transfer_community::table)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -331,12 +340,11 @@ impl Crud for ModTransferCommunity {
|
|||
|
||||
async fn update(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
form: &ModTransferCommunityForm,
|
||||
from_id: Self::IdType,
|
||||
form: &Self::UpdateForm,
|
||||
) -> Result<Self, Error> {
|
||||
use crate::schema::mod_transfer_community::dsl::mod_transfer_community;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(mod_transfer_community.find(from_id))
|
||||
diesel::update(mod_transfer_community::table.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -347,21 +355,23 @@ impl Crud for ModTransferCommunity {
|
|||
impl Crud for ModAdd {
|
||||
type InsertForm = ModAddForm;
|
||||
type UpdateForm = ModAddForm;
|
||||
type IdType = i32;
|
||||
type IdType = ModAddId;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &ModAddForm) -> Result<Self, Error> {
|
||||
use crate::schema::mod_add::dsl::mod_add;
|
||||
async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(mod_add)
|
||||
insert_into(mod_add::table)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn update(pool: &mut DbPool<'_>, from_id: i32, form: &ModAddForm) -> Result<Self, Error> {
|
||||
use crate::schema::mod_add::dsl::mod_add;
|
||||
async fn update(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: Self::IdType,
|
||||
form: &Self::UpdateForm,
|
||||
) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(mod_add.find(from_id))
|
||||
diesel::update(mod_add::table.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
|
|
@ -196,6 +196,95 @@ pub struct PersonContentCombinedId(i32);
|
|||
/// The person saved combined id
|
||||
pub struct PersonSavedCombinedId(i32);
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
||||
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
||||
pub struct ModlogCombinedId(i32);
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
||||
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
pub struct AdminAllowInstanceId(i32);
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
||||
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
pub struct AdminBlockInstanceId(i32);
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
||||
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
pub struct AdminPurgePersonId(i32);
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
||||
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
pub struct AdminPurgeCommunityId(i32);
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
||||
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
pub struct AdminPurgeCommentId(i32);
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
||||
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
pub struct AdminPurgePostId(i32);
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
||||
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
pub struct ModRemovePostId(i32);
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
||||
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
pub struct ModRemoveCommentId(i32);
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
||||
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
pub struct ModRemoveCommunityId(i32);
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
||||
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
pub struct ModLockPostId(i32);
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
||||
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
pub struct ModFeaturePostId(i32);
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
||||
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
pub struct ModBanFromCommunityId(i32);
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
||||
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
pub struct ModBanId(i32);
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
||||
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
pub struct ModHideCommunityId(i32);
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
||||
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
pub struct ModAddCommunityId(i32);
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
||||
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
pub struct ModTransferCommunityId(i32);
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
||||
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
pub struct ModAddId(i32);
|
||||
|
||||
impl DbUrl {
|
||||
pub fn inner(&self) -> &Url {
|
||||
&self.0
|
||||
|
|
|
@ -633,6 +633,30 @@ diesel::table! {
|
|||
}
|
||||
}
|
||||
|
||||
diesel::table! {
|
||||
modlog_combined (id) {
|
||||
id -> Int4,
|
||||
published -> Timestamptz,
|
||||
admin_allow_instance_id -> Nullable<Int4>,
|
||||
admin_block_instance_id -> Nullable<Int4>,
|
||||
admin_purge_comment_id -> Nullable<Int4>,
|
||||
admin_purge_community_id -> Nullable<Int4>,
|
||||
admin_purge_person_id -> Nullable<Int4>,
|
||||
admin_purge_post_id -> Nullable<Int4>,
|
||||
mod_add_id -> Nullable<Int4>,
|
||||
mod_add_community_id -> Nullable<Int4>,
|
||||
mod_ban_id -> Nullable<Int4>,
|
||||
mod_ban_from_community_id -> Nullable<Int4>,
|
||||
mod_feature_post_id -> Nullable<Int4>,
|
||||
mod_hide_community_id -> Nullable<Int4>,
|
||||
mod_lock_post_id -> Nullable<Int4>,
|
||||
mod_remove_comment_id -> Nullable<Int4>,
|
||||
mod_remove_community_id -> Nullable<Int4>,
|
||||
mod_remove_post_id -> Nullable<Int4>,
|
||||
mod_transfer_community_id -> Nullable<Int4>,
|
||||
}
|
||||
}
|
||||
|
||||
diesel::table! {
|
||||
oauth_account (oauth_provider_id, local_user_id) {
|
||||
local_user_id -> Int4,
|
||||
|
@ -1043,6 +1067,23 @@ 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_allow_instance (admin_allow_instance_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 -> mod_ban_from_community (mod_ban_from_community_id));
|
||||
diesel::joinable!(modlog_combined -> mod_feature_post (mod_feature_post_id));
|
||||
diesel::joinable!(modlog_combined -> mod_hide_community (mod_hide_community_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!(oauth_account -> local_user (local_user_id));
|
||||
diesel::joinable!(oauth_account -> oauth_provider (oauth_provider_id));
|
||||
diesel::joinable!(password_reset_request -> local_user (local_user_id));
|
||||
|
@ -1123,6 +1164,7 @@ diesel::allow_tables_to_appear_in_same_query!(
|
|||
mod_remove_community,
|
||||
mod_remove_post,
|
||||
mod_transfer_community,
|
||||
modlog_combined,
|
||||
oauth_account,
|
||||
oauth_provider,
|
||||
password_reset_request,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
pub mod modlog;
|
||||
pub mod person_content;
|
||||
pub mod person_saved;
|
||||
pub mod report;
|
||||
|
|
57
crates/db_schema/src/source/combined/modlog.rs
Normal file
57
crates/db_schema/src/source/combined/modlog.rs
Normal file
|
@ -0,0 +1,57 @@
|
|||
use crate::newtypes::{
|
||||
AdminAllowInstanceId,
|
||||
AdminBlockInstanceId,
|
||||
AdminPurgeCommentId,
|
||||
AdminPurgeCommunityId,
|
||||
AdminPurgePersonId,
|
||||
AdminPurgePostId,
|
||||
ModAddCommunityId,
|
||||
ModAddId,
|
||||
ModBanFromCommunityId,
|
||||
ModBanId,
|
||||
ModFeaturePostId,
|
||||
ModHideCommunityId,
|
||||
ModLockPostId,
|
||||
ModRemoveCommentId,
|
||||
ModRemoveCommunityId,
|
||||
ModRemovePostId,
|
||||
ModTransferCommunityId,
|
||||
ModlogCombinedId,
|
||||
};
|
||||
#[cfg(feature = "full")]
|
||||
use crate::schema::modlog_combined;
|
||||
use chrono::{DateTime, Utc};
|
||||
#[cfg(feature = "full")]
|
||||
use i_love_jesus::CursorKeysModule;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(PartialEq, Eq, Serialize, Deserialize, Debug, Clone)]
|
||||
#[cfg_attr(
|
||||
feature = "full",
|
||||
derive(Identifiable, Queryable, Selectable, CursorKeysModule)
|
||||
)]
|
||||
#[cfg_attr(feature = "full", diesel(table_name = modlog_combined))]
|
||||
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
|
||||
#[cfg_attr(feature = "full", cursor_keys_module(name = modlog_combined_keys))]
|
||||
/// A combined modlog table.
|
||||
pub struct ModlogCombined {
|
||||
pub id: ModlogCombinedId,
|
||||
pub published: DateTime<Utc>,
|
||||
pub admin_allow_instance_id: Option<AdminAllowInstanceId>,
|
||||
pub admin_block_instance_id: Option<AdminBlockInstanceId>,
|
||||
pub admin_purge_comment_id: Option<AdminPurgeCommentId>,
|
||||
pub admin_purge_community_id: Option<AdminPurgeCommunityId>,
|
||||
pub admin_purge_person_id: Option<AdminPurgePersonId>,
|
||||
pub admin_purge_post_id: Option<AdminPurgePostId>,
|
||||
pub mod_add_id: Option<ModAddId>,
|
||||
pub mod_add_community_id: Option<ModAddCommunityId>,
|
||||
pub mod_ban_id: Option<ModBanId>,
|
||||
pub mod_ban_from_community_id: Option<ModBanFromCommunityId>,
|
||||
pub mod_feature_post_id: Option<ModFeaturePostId>,
|
||||
pub mod_hide_community_id: Option<ModHideCommunityId>,
|
||||
pub mod_lock_post_id: Option<ModLockPostId>,
|
||||
pub mod_remove_comment_id: Option<ModRemoveCommentId>,
|
||||
pub mod_remove_community_id: Option<ModRemoveCommunityId>,
|
||||
pub mod_remove_post_id: Option<ModRemovePostId>,
|
||||
pub mod_transfer_community_id: Option<ModTransferCommunityId>,
|
||||
}
|
|
@ -1,4 +1,15 @@
|
|||
use crate::newtypes::{CommunityId, InstanceId, PersonId, PostId};
|
||||
use crate::newtypes::{
|
||||
AdminAllowInstanceId,
|
||||
AdminBlockInstanceId,
|
||||
AdminPurgeCommentId,
|
||||
AdminPurgeCommunityId,
|
||||
AdminPurgePersonId,
|
||||
AdminPurgePostId,
|
||||
CommunityId,
|
||||
InstanceId,
|
||||
PersonId,
|
||||
PostId,
|
||||
};
|
||||
#[cfg(feature = "full")]
|
||||
use crate::schema::{
|
||||
admin_allow_instance,
|
||||
|
@ -22,7 +33,7 @@ use ts_rs::TS;
|
|||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// When an admin purges a person.
|
||||
pub struct AdminPurgePerson {
|
||||
pub id: i32,
|
||||
pub id: AdminPurgePersonId,
|
||||
pub admin_person_id: PersonId,
|
||||
#[cfg_attr(feature = "full", ts(optional))]
|
||||
pub reason: Option<String>,
|
||||
|
@ -44,7 +55,7 @@ pub struct AdminPurgePersonForm {
|
|||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// When an admin purges a community.
|
||||
pub struct AdminPurgeCommunity {
|
||||
pub id: i32,
|
||||
pub id: AdminPurgeCommunityId,
|
||||
pub admin_person_id: PersonId,
|
||||
#[cfg_attr(feature = "full", ts(optional))]
|
||||
pub reason: Option<String>,
|
||||
|
@ -66,7 +77,7 @@ pub struct AdminPurgeCommunityForm {
|
|||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// When an admin purges a post.
|
||||
pub struct AdminPurgePost {
|
||||
pub id: i32,
|
||||
pub id: AdminPurgePostId,
|
||||
pub admin_person_id: PersonId,
|
||||
pub community_id: CommunityId,
|
||||
#[cfg_attr(feature = "full", ts(optional))]
|
||||
|
@ -90,7 +101,7 @@ pub struct AdminPurgePostForm {
|
|||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// When an admin purges a comment.
|
||||
pub struct AdminPurgeComment {
|
||||
pub id: i32,
|
||||
pub id: AdminPurgeCommentId,
|
||||
pub admin_person_id: PersonId,
|
||||
pub post_id: PostId,
|
||||
#[cfg_attr(feature = "full", ts(optional))]
|
||||
|
@ -120,7 +131,7 @@ pub struct AdminPurgeCommentForm {
|
|||
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
pub struct AdminAllowInstance {
|
||||
pub id: i32,
|
||||
pub id: AdminAllowInstanceId,
|
||||
pub instance_id: InstanceId,
|
||||
pub admin_person_id: PersonId,
|
||||
pub allowed: bool,
|
||||
|
@ -153,7 +164,7 @@ pub struct AdminAllowInstanceForm {
|
|||
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
pub struct AdminBlockInstance {
|
||||
pub id: i32,
|
||||
pub id: AdminBlockInstanceId,
|
||||
pub instance_id: InstanceId,
|
||||
pub admin_person_id: PersonId,
|
||||
pub blocked: bool,
|
||||
|
|
|
@ -1,4 +1,20 @@
|
|||
use crate::newtypes::{CommentId, CommunityId, PersonId, PostId};
|
||||
use crate::newtypes::{
|
||||
CommentId,
|
||||
CommunityId,
|
||||
ModAddCommunityId,
|
||||
ModAddId,
|
||||
ModBanFromCommunityId,
|
||||
ModBanId,
|
||||
ModFeaturePostId,
|
||||
ModHideCommunityId,
|
||||
ModLockPostId,
|
||||
ModRemoveCommentId,
|
||||
ModRemoveCommunityId,
|
||||
ModRemovePostId,
|
||||
ModTransferCommunityId,
|
||||
PersonId,
|
||||
PostId,
|
||||
};
|
||||
#[cfg(feature = "full")]
|
||||
use crate::schema::{
|
||||
mod_add,
|
||||
|
@ -27,7 +43,7 @@ use ts_rs::TS;
|
|||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// When a moderator removes a post.
|
||||
pub struct ModRemovePost {
|
||||
pub id: i32,
|
||||
pub id: ModRemovePostId,
|
||||
pub mod_person_id: PersonId,
|
||||
pub post_id: PostId,
|
||||
#[cfg_attr(feature = "full", ts(optional))]
|
||||
|
@ -52,7 +68,7 @@ pub struct ModRemovePostForm {
|
|||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// When a moderator locks a post (prevents new comments being made).
|
||||
pub struct ModLockPost {
|
||||
pub id: i32,
|
||||
pub id: ModLockPostId,
|
||||
pub mod_person_id: PersonId,
|
||||
pub post_id: PostId,
|
||||
pub locked: bool,
|
||||
|
@ -74,7 +90,7 @@ pub struct ModLockPostForm {
|
|||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// When a moderator features a post on a community (pins it to the top).
|
||||
pub struct ModFeaturePost {
|
||||
pub id: i32,
|
||||
pub id: ModFeaturePostId,
|
||||
pub mod_person_id: PersonId,
|
||||
pub post_id: PostId,
|
||||
pub featured: bool,
|
||||
|
@ -99,7 +115,7 @@ pub struct ModFeaturePostForm {
|
|||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// When a moderator removes a comment.
|
||||
pub struct ModRemoveComment {
|
||||
pub id: i32,
|
||||
pub id: ModRemoveCommentId,
|
||||
pub mod_person_id: PersonId,
|
||||
pub comment_id: CommentId,
|
||||
#[cfg_attr(feature = "full", ts(optional))]
|
||||
|
@ -125,7 +141,7 @@ pub struct ModRemoveCommentForm {
|
|||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// When a moderator removes a community.
|
||||
pub struct ModRemoveCommunity {
|
||||
pub id: i32,
|
||||
pub id: ModRemoveCommunityId,
|
||||
pub mod_person_id: PersonId,
|
||||
pub community_id: CommunityId,
|
||||
#[cfg_attr(feature = "full", ts(optional))]
|
||||
|
@ -151,7 +167,7 @@ pub struct ModRemoveCommunityForm {
|
|||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// When someone is banned from a community.
|
||||
pub struct ModBanFromCommunity {
|
||||
pub id: i32,
|
||||
pub id: ModBanFromCommunityId,
|
||||
pub mod_person_id: PersonId,
|
||||
pub other_person_id: PersonId,
|
||||
pub community_id: CommunityId,
|
||||
|
@ -182,7 +198,7 @@ pub struct ModBanFromCommunityForm {
|
|||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// When someone is banned from the site.
|
||||
pub struct ModBan {
|
||||
pub id: i32,
|
||||
pub id: ModBanId,
|
||||
pub mod_person_id: PersonId,
|
||||
pub other_person_id: PersonId,
|
||||
#[cfg_attr(feature = "full", ts(optional))]
|
||||
|
@ -210,7 +226,7 @@ pub struct ModHideCommunityForm {
|
|||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// When a community is hidden from public view.
|
||||
pub struct ModHideCommunity {
|
||||
pub id: i32,
|
||||
pub id: ModHideCommunityId,
|
||||
pub community_id: CommunityId,
|
||||
pub mod_person_id: PersonId,
|
||||
pub when_: DateTime<Utc>,
|
||||
|
@ -236,7 +252,7 @@ pub struct ModBanForm {
|
|||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// When someone is added as a community moderator.
|
||||
pub struct ModAddCommunity {
|
||||
pub id: i32,
|
||||
pub id: ModAddCommunityId,
|
||||
pub mod_person_id: PersonId,
|
||||
pub other_person_id: PersonId,
|
||||
pub community_id: CommunityId,
|
||||
|
@ -260,7 +276,7 @@ pub struct ModAddCommunityForm {
|
|||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// When a moderator transfers a community to a new owner.
|
||||
pub struct ModTransferCommunity {
|
||||
pub id: i32,
|
||||
pub id: ModTransferCommunityId,
|
||||
pub mod_person_id: PersonId,
|
||||
pub other_person_id: PersonId,
|
||||
pub community_id: CommunityId,
|
||||
|
@ -282,7 +298,7 @@ pub struct ModTransferCommunityForm {
|
|||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// When someone is added as a site moderator.
|
||||
pub struct ModAdd {
|
||||
pub id: i32,
|
||||
pub id: ModAddId,
|
||||
pub mod_person_id: PersonId,
|
||||
pub other_person_id: PersonId,
|
||||
pub removed: bool,
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
DROP TABLE modlog_combined;
|
169
migrations/2024-12-08-165614_add_modlog_combined_table/up.sql
Normal file
169
migrations/2024-12-08-165614_add_modlog_combined_table/up.sql
Normal file
|
@ -0,0 +1,169 @@
|
|||
-- Creates combined tables for
|
||||
-- modlog: (17 tables)
|
||||
-- admin_allow_instance
|
||||
-- admin_block_instance
|
||||
-- admin_purge_comment
|
||||
-- admin_purge_community
|
||||
-- admin_purge_person
|
||||
-- admin_purge_post
|
||||
-- mod_add
|
||||
-- mod_add_community
|
||||
-- mod_ban
|
||||
-- mod_ban_from_community
|
||||
-- mod_feature_post
|
||||
-- mod_hide_community
|
||||
-- mod_lock_post
|
||||
-- mod_remove_comment
|
||||
-- mod_remove_community
|
||||
-- mod_remove_post
|
||||
-- mod_transfer_community
|
||||
CREATE TABLE modlog_combined (
|
||||
id serial PRIMARY KEY,
|
||||
published timestamptz NOT NULL,
|
||||
admin_allow_instance_id int UNIQUE REFERENCES admin_allow_instance ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
admin_block_instance_id int UNIQUE REFERENCES admin_block_instance ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
admin_purge_comment_id int UNIQUE REFERENCES admin_purge_comment ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
admin_purge_community_id int UNIQUE REFERENCES admin_purge_community ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
admin_purge_person_id int UNIQUE REFERENCES admin_purge_person ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
admin_purge_post_id int UNIQUE REFERENCES admin_purge_post ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
mod_add_id int UNIQUE REFERENCES mod_add ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
mod_add_community_id int UNIQUE REFERENCES mod_add_community ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
mod_ban_id int UNIQUE REFERENCES mod_ban ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
mod_ban_from_community_id int UNIQUE REFERENCES mod_ban_from_community ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
mod_feature_post_id int UNIQUE REFERENCES mod_feature_post ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
mod_hide_community_id int UNIQUE REFERENCES mod_hide_community ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
mod_lock_post_id int UNIQUE REFERENCES mod_lock_post ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
mod_remove_comment_id int UNIQUE REFERENCES mod_remove_comment ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
mod_remove_community_id int UNIQUE REFERENCES mod_remove_community ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
mod_remove_post_id int UNIQUE REFERENCES mod_remove_post ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
mod_transfer_community_id int UNIQUE REFERENCES mod_transfer_community ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
-- Make sure only one of the columns is not null
|
||||
CHECK (num_nonnulls (admin_allow_instance_id, admin_block_instance_id, admin_purge_comment_id, admin_purge_community_id, admin_purge_person_id, admin_purge_post_id, mod_add_id, mod_add_community_id, mod_ban_id, mod_ban_from_community_id, mod_feature_post_id, mod_hide_community_id, mod_lock_post_id, mod_remove_comment_id, mod_remove_community_id, mod_remove_post_id, mod_transfer_community_id) = 1)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_modlog_combined_published ON modlog_combined (published DESC, id DESC);
|
||||
|
||||
CREATE INDEX idx_modlog_combined_published_asc ON modlog_combined (reverse_timestamp_sort (published) DESC, id DESC);
|
||||
|
||||
-- Updating the history
|
||||
-- Not doing a union all here, because there's way too many null columns
|
||||
INSERT INTO modlog_combined (published, admin_allow_instance_id)
|
||||
SELECT
|
||||
when_,
|
||||
id
|
||||
FROM
|
||||
admin_allow_instance;
|
||||
|
||||
INSERT INTO modlog_combined (published, admin_block_instance_id)
|
||||
SELECT
|
||||
when_,
|
||||
id
|
||||
FROM
|
||||
admin_block_instance;
|
||||
|
||||
INSERT INTO modlog_combined (published, admin_purge_comment_id)
|
||||
SELECT
|
||||
when_,
|
||||
id
|
||||
FROM
|
||||
admin_purge_comment;
|
||||
|
||||
INSERT INTO modlog_combined (published, admin_purge_community_id)
|
||||
SELECT
|
||||
when_,
|
||||
id
|
||||
FROM
|
||||
admin_purge_community;
|
||||
|
||||
INSERT INTO modlog_combined (published, admin_purge_person_id)
|
||||
SELECT
|
||||
when_,
|
||||
id
|
||||
FROM
|
||||
admin_purge_person;
|
||||
|
||||
INSERT INTO modlog_combined (published, admin_purge_post_id)
|
||||
SELECT
|
||||
when_,
|
||||
id
|
||||
FROM
|
||||
admin_purge_post;
|
||||
|
||||
INSERT INTO modlog_combined (published, mod_add_id)
|
||||
SELECT
|
||||
when_,
|
||||
id
|
||||
FROM
|
||||
mod_add;
|
||||
|
||||
INSERT INTO modlog_combined (published, mod_add_community_id)
|
||||
SELECT
|
||||
when_,
|
||||
id
|
||||
FROM
|
||||
mod_add_community;
|
||||
|
||||
INSERT INTO modlog_combined (published, mod_ban_id)
|
||||
SELECT
|
||||
when_,
|
||||
id
|
||||
FROM
|
||||
mod_ban;
|
||||
|
||||
INSERT INTO modlog_combined (published, mod_ban_from_community_id)
|
||||
SELECT
|
||||
when_,
|
||||
id
|
||||
FROM
|
||||
mod_ban_from_community;
|
||||
|
||||
INSERT INTO modlog_combined (published, mod_feature_post_id)
|
||||
SELECT
|
||||
when_,
|
||||
id
|
||||
FROM
|
||||
mod_feature_post;
|
||||
|
||||
INSERT INTO modlog_combined (published, mod_hide_community_id)
|
||||
SELECT
|
||||
when_,
|
||||
id
|
||||
FROM
|
||||
mod_hide_community;
|
||||
|
||||
INSERT INTO modlog_combined (published, mod_lock_post_id)
|
||||
SELECT
|
||||
when_,
|
||||
id
|
||||
FROM
|
||||
mod_lock_post;
|
||||
|
||||
INSERT INTO modlog_combined (published, mod_remove_comment_id)
|
||||
SELECT
|
||||
when_,
|
||||
id
|
||||
FROM
|
||||
mod_remove_comment;
|
||||
|
||||
INSERT INTO modlog_combined (published, mod_remove_community_id)
|
||||
SELECT
|
||||
when_,
|
||||
id
|
||||
FROM
|
||||
mod_remove_community;
|
||||
|
||||
INSERT INTO modlog_combined (published, mod_remove_post_id)
|
||||
SELECT
|
||||
when_,
|
||||
id
|
||||
FROM
|
||||
mod_remove_post;
|
||||
|
||||
INSERT INTO modlog_combined (published, mod_transfer_community_id)
|
||||
SELECT
|
||||
when_,
|
||||
id
|
||||
FROM
|
||||
mod_transfer_community;
|
||||
|
||||
|
Loading…
Reference in a new issue