Changing modded_person to other_person.

This commit is contained in:
Dessalines 2025-01-08 18:26:25 -05:00
parent 43179177a0
commit 0723ef2055
4 changed files with 71 additions and 70 deletions

View file

@ -36,7 +36,7 @@ pub async fn get_mod_log(
} else { } else {
data.mod_person_id data.mod_person_id
}; };
let modded_person_id = data.modded_person_id; let other_person_id = data.other_person_id;
let post_id = data.post_id; let post_id = data.post_id;
let comment_id = data.comment_id; let comment_id = data.comment_id;
@ -52,7 +52,7 @@ pub async fn get_mod_log(
type_, type_,
community_id, community_id,
mod_person_id, mod_person_id,
modded_person_id, other_person_id,
post_id, post_id,
comment_id, comment_id,
hide_modlog_names: Some(hide_modlog_names), hide_modlog_names: Some(hide_modlog_names),

View file

@ -133,7 +133,7 @@ pub struct GetModlog {
#[cfg_attr(feature = "full", ts(optional))] #[cfg_attr(feature = "full", ts(optional))]
pub type_: Option<ModlogActionType>, pub type_: Option<ModlogActionType>,
#[cfg_attr(feature = "full", ts(optional))] #[cfg_attr(feature = "full", ts(optional))]
pub modded_person_id: Option<PersonId>, pub other_person_id: Option<PersonId>,
#[cfg_attr(feature = "full", ts(optional))] #[cfg_attr(feature = "full", ts(optional))]
pub post_id: Option<PostId>, pub post_id: Option<PostId>,
#[cfg_attr(feature = "full", ts(optional))] #[cfg_attr(feature = "full", ts(optional))]

View file

@ -142,7 +142,7 @@ pub struct ModlogCombinedQuery {
pub community_id: Option<CommunityId>, pub community_id: Option<CommunityId>,
pub hide_modlog_names: Option<bool>, pub hide_modlog_names: Option<bool>,
pub mod_person_id: Option<PersonId>, pub mod_person_id: Option<PersonId>,
pub modded_person_id: Option<PersonId>, pub other_person_id: Option<PersonId>,
pub page_after: Option<PaginationCursorData>, pub page_after: Option<PaginationCursorData>,
pub page_back: Option<bool>, pub page_back: Option<bool>,
} }
@ -155,7 +155,8 @@ impl ModlogCombinedQuery {
let show_mod_names = !(self.hide_modlog_names.unwrap_or_default()); let show_mod_names = !(self.hide_modlog_names.unwrap_or_default());
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>(); let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
let modded_person = aliases::person1.field(person::id); // The modded / other person
let other_person = aliases::person1.field(person::id);
// The query for the admin / mod person // The query for the admin / mod person
// It needs an OR condition to every mod table // It needs an OR condition to every mod table
@ -181,33 +182,33 @@ impl ModlogCombinedQuery {
.or(mod_transfer_community::mod_person_id.eq(person::id)), .or(mod_transfer_community::mod_person_id.eq(person::id)),
); );
let modded_person_join = mod_add::other_person_id let other_person_join = mod_add::other_person_id
.eq(modded_person) .eq(other_person)
.or(mod_add_community::other_person_id.eq(modded_person)) .or(mod_add_community::other_person_id.eq(other_person))
.or(mod_ban::other_person_id.eq(modded_person)) .or(mod_ban::other_person_id.eq(other_person))
.or(mod_ban_from_community::other_person_id.eq(modded_person)) .or(mod_ban_from_community::other_person_id.eq(other_person))
// Some tables don't have the modded_person_id directly, so you need to join // Some tables don't have the other_person_id directly, so you need to join
.or( .or(
mod_feature_post::id mod_feature_post::id
.is_not_null() .is_not_null()
.and(post::creator_id.eq(modded_person)), .and(post::creator_id.eq(other_person)),
) )
.or( .or(
mod_lock_post::id mod_lock_post::id
.is_not_null() .is_not_null()
.and(post::creator_id.eq(modded_person)), .and(post::creator_id.eq(other_person)),
) )
.or( .or(
mod_remove_comment::id mod_remove_comment::id
.is_not_null() .is_not_null()
.and(comment::creator_id.eq(modded_person)), .and(comment::creator_id.eq(other_person)),
) )
.or( .or(
mod_remove_post::id mod_remove_post::id
.is_not_null() .is_not_null()
.and(post::creator_id.eq(modded_person)), .and(post::creator_id.eq(other_person)),
) )
.or(mod_transfer_community::other_person_id.eq(modded_person)); .or(mod_transfer_community::other_person_id.eq(other_person));
let comment_join = mod_remove_comment::comment_id.eq(comment::id); let comment_join = mod_remove_comment::comment_id.eq(comment::id);
@ -282,8 +283,8 @@ impl ModlogCombinedQuery {
.left_join(community::table.on(community_join)) .left_join(community::table.on(community_join))
// The instance // The instance
.left_join(instance::table.on(instance_join)) .left_join(instance::table.on(instance_join))
// The modded person // The other / modded person
.left_join(aliases::person1.on(modded_person_join)) .left_join(aliases::person1.on(other_person_join))
.select(( .select((
admin_allow_instance::all_columns.nullable(), admin_allow_instance::all_columns.nullable(),
admin_block_instance::all_columns.nullable(), admin_block_instance::all_columns.nullable(),
@ -316,8 +317,8 @@ impl ModlogCombinedQuery {
query = query.filter(person::id.eq(mod_person_id)); query = query.filter(person::id.eq(mod_person_id));
}; };
if let Some(modded_person_id) = self.modded_person_id { if let Some(other_person_id) = self.other_person_id {
query = query.filter(modded_person.eq(modded_person_id)); query = query.filter(other_person.eq(other_person_id));
}; };
if let Some(community_id) = self.community_id { if let Some(community_id) = self.community_id {
@ -443,52 +444,52 @@ impl InternalToCombinedView for ModlogCombinedViewInternal {
admin: v.moderator, admin: v.moderator,
community, community,
})) }))
} else if let (Some(mod_add), Some(modded_person)) = (v.mod_add, v.modded_person.clone()) { } else if let (Some(mod_add), Some(other_person)) = (v.mod_add, v.other_person.clone()) {
Some(ModlogCombinedView::ModAdd(ModAddView { Some(ModlogCombinedView::ModAdd(ModAddView {
mod_add, mod_add,
moderator: v.moderator, moderator: v.moderator,
modded_person, other_person,
})) }))
} else if let (Some(mod_add_community), Some(modded_person), Some(community)) = ( } else if let (Some(mod_add_community), Some(other_person), Some(community)) = (
v.mod_add_community, v.mod_add_community,
v.modded_person.clone(), v.other_person.clone(),
v.community.clone(), v.community.clone(),
) { ) {
Some(ModlogCombinedView::ModAddCommunity(ModAddCommunityView { Some(ModlogCombinedView::ModAddCommunity(ModAddCommunityView {
mod_add_community, mod_add_community,
moderator: v.moderator, moderator: v.moderator,
modded_person, other_person,
community, community,
})) }))
} else if let (Some(mod_ban), Some(modded_person)) = (v.mod_ban, v.modded_person.clone()) { } else if let (Some(mod_ban), Some(other_person)) = (v.mod_ban, v.other_person.clone()) {
Some(ModlogCombinedView::ModBan(ModBanView { Some(ModlogCombinedView::ModBan(ModBanView {
mod_ban, mod_ban,
moderator: v.moderator, moderator: v.moderator,
modded_person, other_person,
})) }))
} else if let (Some(mod_ban_from_community), Some(modded_person), Some(community)) = ( } else if let (Some(mod_ban_from_community), Some(other_person), Some(community)) = (
v.mod_ban_from_community, v.mod_ban_from_community,
v.modded_person.clone(), v.other_person.clone(),
v.community.clone(), v.community.clone(),
) { ) {
Some(ModlogCombinedView::ModBanFromCommunity( Some(ModlogCombinedView::ModBanFromCommunity(
ModBanFromCommunityView { ModBanFromCommunityView {
mod_ban_from_community, mod_ban_from_community,
moderator: v.moderator, moderator: v.moderator,
modded_person, other_person,
community, community,
}, },
)) ))
} else if let (Some(mod_feature_post), Some(modded_person), Some(community), Some(post)) = ( } else if let (Some(mod_feature_post), Some(other_person), Some(community), Some(post)) = (
v.mod_feature_post, v.mod_feature_post,
v.modded_person.clone(), v.other_person.clone(),
v.community.clone(), v.community.clone(),
v.post.clone(), v.post.clone(),
) { ) {
Some(ModlogCombinedView::ModFeaturePost(ModFeaturePostView { Some(ModlogCombinedView::ModFeaturePost(ModFeaturePostView {
mod_feature_post, mod_feature_post,
moderator: v.moderator, moderator: v.moderator,
modded_person, other_person,
community, community,
post, post,
})) }))
@ -500,28 +501,28 @@ impl InternalToCombinedView for ModlogCombinedViewInternal {
admin: v.moderator, admin: v.moderator,
community, community,
})) }))
} else if let (Some(mod_lock_post), Some(modded_person), Some(community), Some(post)) = ( } else if let (Some(mod_lock_post), Some(other_person), Some(community), Some(post)) = (
v.mod_lock_post, v.mod_lock_post,
v.modded_person.clone(), v.other_person.clone(),
v.community.clone(), v.community.clone(),
v.post.clone(), v.post.clone(),
) { ) {
Some(ModlogCombinedView::ModLockPost(ModLockPostView { Some(ModlogCombinedView::ModLockPost(ModLockPostView {
mod_lock_post, mod_lock_post,
moderator: v.moderator, moderator: v.moderator,
modded_person, other_person,
community, community,
post, post,
})) }))
} else if let ( } else if let (
Some(mod_remove_comment), Some(mod_remove_comment),
Some(modded_person), Some(other_person),
Some(community), Some(community),
Some(post), Some(post),
Some(comment), Some(comment),
) = ( ) = (
v.mod_remove_comment, v.mod_remove_comment,
v.modded_person.clone(), v.other_person.clone(),
v.community.clone(), v.community.clone(),
v.post.clone(), v.post.clone(),
v.comment, v.comment,
@ -529,7 +530,7 @@ impl InternalToCombinedView for ModlogCombinedViewInternal {
Some(ModlogCombinedView::ModRemoveComment(ModRemoveCommentView { Some(ModlogCombinedView::ModRemoveComment(ModRemoveCommentView {
mod_remove_comment, mod_remove_comment,
moderator: v.moderator, moderator: v.moderator,
modded_person, other_person,
community, community,
post, post,
comment, comment,
@ -544,29 +545,29 @@ impl InternalToCombinedView for ModlogCombinedViewInternal {
community, community,
}, },
)) ))
} else if let (Some(mod_remove_post), Some(modded_person), Some(community), Some(post)) = ( } else if let (Some(mod_remove_post), Some(other_person), Some(community), Some(post)) = (
v.mod_remove_post, v.mod_remove_post,
v.modded_person.clone(), v.other_person.clone(),
v.community.clone(), v.community.clone(),
v.post.clone(), v.post.clone(),
) { ) {
Some(ModlogCombinedView::ModRemovePost(ModRemovePostView { Some(ModlogCombinedView::ModRemovePost(ModRemovePostView {
mod_remove_post, mod_remove_post,
moderator: v.moderator, moderator: v.moderator,
modded_person, other_person,
community, community,
post, post,
})) }))
} else if let (Some(mod_transfer_community), Some(modded_person), Some(community)) = ( } else if let (Some(mod_transfer_community), Some(other_person), Some(community)) = (
v.mod_transfer_community, v.mod_transfer_community,
v.modded_person.clone(), v.other_person.clone(),
v.community.clone(), v.community.clone(),
) { ) {
Some(ModlogCombinedView::ModTransferCommunity( Some(ModlogCombinedView::ModTransferCommunity(
ModTransferCommunityView { ModTransferCommunityView {
mod_transfer_community, mod_transfer_community,
moderator: v.moderator, moderator: v.moderator,
modded_person, other_person,
community, community,
}, },
)) ))
@ -1051,7 +1052,7 @@ mod tests {
data.jessica.id, data.jessica.id,
v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1)) v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1))
); );
assert_eq!(data.jessica.id, v.modded_person.id); assert_eq!(data.jessica.id, v.other_person.id);
} else { } else {
panic!("wrong type"); panic!("wrong type");
} }
@ -1065,7 +1066,7 @@ mod tests {
data.jessica.id, data.jessica.id,
v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1)) v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1))
); );
assert_eq!(data.sara.id, v.modded_person.id); assert_eq!(data.sara.id, v.other_person.id);
} else { } else {
panic!("wrong type"); panic!("wrong type");
} }
@ -1077,7 +1078,7 @@ mod tests {
data.jessica.id, data.jessica.id,
v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1)) v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1))
); );
assert_eq!(data.sara.id, v.modded_person.id); assert_eq!(data.sara.id, v.other_person.id);
} else { } else {
panic!("wrong type"); panic!("wrong type");
} }
@ -1089,7 +1090,7 @@ mod tests {
data.timmy.id, data.timmy.id,
v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1)) v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1))
); );
assert_eq!(data.jessica.id, v.modded_person.id); assert_eq!(data.jessica.id, v.other_person.id);
} else { } else {
panic!("wrong type"); panic!("wrong type");
} }
@ -1103,7 +1104,7 @@ mod tests {
data.timmy.id, data.timmy.id,
v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1)) v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1))
); );
assert_eq!(data.timmy.id, v.modded_person.id); assert_eq!(data.timmy.id, v.other_person.id);
} else { } else {
panic!("wrong type"); panic!("wrong type");
} }
@ -1128,7 +1129,7 @@ mod tests {
data.timmy.id, data.timmy.id,
v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1)) v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1))
); );
assert_eq!(data.timmy.id, v.modded_person.id); assert_eq!(data.timmy.id, v.other_person.id);
} else { } else {
panic!("wrong type"); panic!("wrong type");
} }
@ -1143,7 +1144,7 @@ mod tests {
data.timmy.id, data.timmy.id,
v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1)) v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1))
); );
assert_eq!(data.timmy.id, v.modded_person.id); assert_eq!(data.timmy.id, v.other_person.id);
} else { } else {
panic!("wrong type"); panic!("wrong type");
} }
@ -1158,7 +1159,7 @@ mod tests {
data.timmy.id, data.timmy.id,
v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1)) v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1))
); );
assert_eq!(data.timmy.id, v.modded_person.id); assert_eq!(data.timmy.id, v.other_person.id);
} else { } else {
panic!("wrong type"); panic!("wrong type");
} }
@ -1170,7 +1171,7 @@ mod tests {
data.timmy.id, data.timmy.id,
v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1)) v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1))
); );
assert_eq!(data.jessica.id, v.modded_person.id); assert_eq!(data.jessica.id, v.other_person.id);
} else { } else {
panic!("wrong type"); panic!("wrong type");
} }
@ -1180,7 +1181,7 @@ mod tests {
data.timmy.id, data.timmy.id,
v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1)) v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1))
); );
assert_eq!(data.jessica.id, v.modded_person.id); assert_eq!(data.jessica.id, v.other_person.id);
} else { } else {
panic!("wrong type"); panic!("wrong type");
} }
@ -1192,7 +1193,7 @@ mod tests {
data.timmy.id, data.timmy.id,
v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1)) v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1))
); );
assert_eq!(data.jessica.id, v.modded_person.id); assert_eq!(data.jessica.id, v.other_person.id);
} else { } else {
panic!("wrong type"); panic!("wrong type");
} }
@ -1202,7 +1203,7 @@ mod tests {
data.timmy.id, data.timmy.id,
v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1)) v.moderator.as_ref().map(|a| a.id).unwrap_or(PersonId(-1))
); );
assert_eq!(data.jessica.id, v.modded_person.id); assert_eq!(data.jessica.id, v.other_person.id);
} else { } else {
panic!("wrong type"); panic!("wrong type");
} }
@ -1229,7 +1230,7 @@ mod tests {
// you have to go into the item to see who created it. // you have to go into the item to see who created it.
let modlog_modded_timmy_filter = ModlogCombinedQuery { let modlog_modded_timmy_filter = ModlogCombinedQuery {
modded_person_id: Some(data.timmy.id), other_person_id: Some(data.timmy.id),
..Default::default() ..Default::default()
} }
.list(pool) .list(pool)
@ -1237,7 +1238,7 @@ mod tests {
assert_eq!(4, modlog_modded_timmy_filter.len()); assert_eq!(4, modlog_modded_timmy_filter.len());
let modlog_modded_jessica_filter = ModlogCombinedQuery { let modlog_modded_jessica_filter = ModlogCombinedQuery {
modded_person_id: Some(data.jessica.id), other_person_id: Some(data.jessica.id),
..Default::default() ..Default::default()
} }
.list(pool) .list(pool)
@ -1245,7 +1246,7 @@ mod tests {
assert_eq!(6, modlog_modded_jessica_filter.len()); assert_eq!(6, modlog_modded_jessica_filter.len());
let modlog_modded_sara_filter = ModlogCombinedQuery { let modlog_modded_sara_filter = ModlogCombinedQuery {
modded_person_id: Some(data.sara.id), other_person_id: Some(data.sara.id),
..Default::default() ..Default::default()
} }
.list(pool) .list(pool)

View file

@ -47,7 +47,7 @@ pub struct ModAddCommunityView {
#[cfg_attr(feature = "full", ts(optional))] #[cfg_attr(feature = "full", ts(optional))]
pub moderator: Option<Person>, pub moderator: Option<Person>,
pub community: Community, pub community: Community,
pub modded_person: Person, pub other_person: Person,
} }
#[skip_serializing_none] #[skip_serializing_none]
@ -60,7 +60,7 @@ pub struct ModAddView {
pub mod_add: ModAdd, pub mod_add: ModAdd,
#[cfg_attr(feature = "full", ts(optional))] #[cfg_attr(feature = "full", ts(optional))]
pub moderator: Option<Person>, pub moderator: Option<Person>,
pub modded_person: Person, pub other_person: Person,
} }
#[skip_serializing_none] #[skip_serializing_none]
@ -74,7 +74,7 @@ pub struct ModBanFromCommunityView {
#[cfg_attr(feature = "full", ts(optional))] #[cfg_attr(feature = "full", ts(optional))]
pub moderator: Option<Person>, pub moderator: Option<Person>,
pub community: Community, pub community: Community,
pub modded_person: Person, pub other_person: Person,
} }
#[skip_serializing_none] #[skip_serializing_none]
@ -87,7 +87,7 @@ pub struct ModBanView {
pub mod_ban: ModBan, pub mod_ban: ModBan,
#[cfg_attr(feature = "full", ts(optional))] #[cfg_attr(feature = "full", ts(optional))]
pub moderator: Option<Person>, pub moderator: Option<Person>,
pub modded_person: Person, pub other_person: Person,
} }
#[skip_serializing_none] #[skip_serializing_none]
@ -113,7 +113,7 @@ pub struct ModLockPostView {
pub mod_lock_post: ModLockPost, pub mod_lock_post: ModLockPost,
#[cfg_attr(feature = "full", ts(optional))] #[cfg_attr(feature = "full", ts(optional))]
pub moderator: Option<Person>, pub moderator: Option<Person>,
pub modded_person: Person, pub other_person: Person,
pub post: Post, pub post: Post,
pub community: Community, pub community: Community,
} }
@ -128,7 +128,7 @@ pub struct ModRemoveCommentView {
pub mod_remove_comment: ModRemoveComment, pub mod_remove_comment: ModRemoveComment,
#[cfg_attr(feature = "full", ts(optional))] #[cfg_attr(feature = "full", ts(optional))]
pub moderator: Option<Person>, pub moderator: Option<Person>,
pub modded_person: Person, pub other_person: Person,
pub comment: Comment, pub comment: Comment,
pub post: Post, pub post: Post,
pub community: Community, pub community: Community,
@ -157,7 +157,7 @@ pub struct ModRemovePostView {
pub mod_remove_post: ModRemovePost, pub mod_remove_post: ModRemovePost,
#[cfg_attr(feature = "full", ts(optional))] #[cfg_attr(feature = "full", ts(optional))]
pub moderator: Option<Person>, pub moderator: Option<Person>,
pub modded_person: Person, pub other_person: Person,
pub post: Post, pub post: Post,
pub community: Community, pub community: Community,
} }
@ -172,7 +172,7 @@ pub struct ModFeaturePostView {
pub mod_feature_post: ModFeaturePost, pub mod_feature_post: ModFeaturePost,
#[cfg_attr(feature = "full", ts(optional))] #[cfg_attr(feature = "full", ts(optional))]
pub moderator: Option<Person>, pub moderator: Option<Person>,
pub modded_person: Person, pub other_person: Person,
pub post: Post, pub post: Post,
pub community: Community, pub community: Community,
} }
@ -188,7 +188,7 @@ pub struct ModTransferCommunityView {
#[cfg_attr(feature = "full", ts(optional))] #[cfg_attr(feature = "full", ts(optional))]
pub moderator: Option<Person>, pub moderator: Option<Person>,
pub community: Community, pub community: Community,
pub modded_person: Person, pub other_person: Person,
} }
#[skip_serializing_none] #[skip_serializing_none]
@ -300,7 +300,7 @@ pub struct ModlogCombinedViewInternal {
// Shared // Shared
pub moderator: Option<Person>, pub moderator: Option<Person>,
pub modded_person: Option<Person>, pub other_person: Option<Person>,
pub instance: Option<Instance>, pub instance: Option<Instance>,
pub community: Option<Community>, pub community: Option<Community>,
pub post: Option<Post>, pub post: Option<Post>,