mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-08 09:24:17 +00:00
* Automatically resolve report when post/comment is removed (#3850) * Automatically resolve report when post/comment is removed * also handle apub removes * Removing auto-resolve report triggers. * Dont allow creating reports for deleted / removed items. * Running pgformat. * Fixing test. * Addressing PR comments. * Forgot comment report. --------- Co-authored-by: Nutomic <me@nutomic.com>
This commit is contained in:
parent
890565ca14
commit
a3bf2f1cf1
|
@ -5,7 +5,11 @@ use lemmy_api_common::{
|
||||||
comment::{CommentReportResponse, CreateCommentReport},
|
comment::{CommentReportResponse, CreateCommentReport},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{check_community_user_action, send_new_report_email_to_admins},
|
utils::{
|
||||||
|
check_comment_deleted_or_removed,
|
||||||
|
check_community_user_action,
|
||||||
|
send_new_report_email_to_admins,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -40,6 +44,9 @@ pub async fn create_comment_report(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
// Don't allow creating reports for removed / deleted comments
|
||||||
|
check_comment_deleted_or_removed(&comment_view.comment)?;
|
||||||
|
|
||||||
let report_form = CommentReportForm {
|
let report_form = CommentReportForm {
|
||||||
creator_id: person_id,
|
creator_id: person_id,
|
||||||
comment_id,
|
comment_id,
|
||||||
|
|
|
@ -5,7 +5,11 @@ use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{CreatePostReport, PostReportResponse},
|
post::{CreatePostReport, PostReportResponse},
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{check_community_user_action, send_new_report_email_to_admins},
|
utils::{
|
||||||
|
check_community_user_action,
|
||||||
|
check_post_deleted_or_removed,
|
||||||
|
send_new_report_email_to_admins,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -40,6 +44,8 @@ pub async fn create_post_report(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
check_post_deleted_or_removed(&post_view.post)?;
|
||||||
|
|
||||||
let report_form = PostReportForm {
|
let report_form = PostReportForm {
|
||||||
creator_id: person_id,
|
creator_id: person_id,
|
||||||
post_id,
|
post_id,
|
||||||
|
|
|
@ -225,6 +225,7 @@ pub async fn check_community_mod_action(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Don't allow creating reports for removed / deleted posts
|
||||||
pub fn check_post_deleted_or_removed(post: &Post) -> Result<(), LemmyError> {
|
pub fn check_post_deleted_or_removed(post: &Post) -> Result<(), LemmyError> {
|
||||||
if post.deleted || post.removed {
|
if post.deleted || post.removed {
|
||||||
Err(LemmyErrorType::Deleted)?
|
Err(LemmyErrorType::Deleted)?
|
||||||
|
@ -233,6 +234,14 @@ pub fn check_post_deleted_or_removed(post: &Post) -> Result<(), LemmyError> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn check_comment_deleted_or_removed(comment: &Comment) -> Result<(), LemmyError> {
|
||||||
|
if comment.deleted || comment.removed {
|
||||||
|
Err(LemmyErrorType::Deleted)?
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Throws an error if a recipient has blocked a person.
|
/// Throws an error if a recipient has blocked a person.
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
pub async fn check_person_block(
|
pub async fn check_person_block(
|
||||||
|
|
|
@ -10,10 +10,11 @@ use lemmy_api_common::{
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
comment::{Comment, CommentUpdateForm},
|
comment::{Comment, CommentUpdateForm},
|
||||||
|
comment_report::CommentReport,
|
||||||
moderator::{ModRemoveComment, ModRemoveCommentForm},
|
moderator::{ModRemoveComment, ModRemoveCommentForm},
|
||||||
post::Post,
|
post::Post,
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::{Crud, Reportable},
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{CommentView, LocalUserView};
|
use lemmy_db_views::structs::{CommentView, LocalUserView};
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||||
|
@ -48,6 +49,9 @@ pub async fn remove_comment(
|
||||||
.await
|
.await
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;
|
.with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;
|
||||||
|
|
||||||
|
CommentReport::resolve_all_for_object(&mut context.pool(), comment_id, local_user_view.person.id)
|
||||||
|
.await?;
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
let form = ModRemoveCommentForm {
|
let form = ModRemoveCommentForm {
|
||||||
mod_person_id: local_user_view.person.id,
|
mod_person_id: local_user_view.person.id,
|
||||||
|
|
|
@ -11,8 +11,9 @@ use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
moderator::{ModRemovePost, ModRemovePostForm},
|
moderator::{ModRemovePost, ModRemovePostForm},
|
||||||
post::{Post, PostUpdateForm},
|
post::{Post, PostUpdateForm},
|
||||||
|
post_report::PostReport,
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::{Crud, Reportable},
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::LocalUserView;
|
use lemmy_db_views::structs::LocalUserView;
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
@ -47,6 +48,9 @@ pub async fn remove_post(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
PostReport::resolve_all_for_object(&mut context.pool(), post_id, local_user_view.person.id)
|
||||||
|
.await?;
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
let form = ModRemovePostForm {
|
let form = ModRemovePostForm {
|
||||||
mod_person_id: local_user_view.person.id,
|
mod_person_id: local_user_view.person.id,
|
||||||
|
|
|
@ -14,7 +14,10 @@ use activitypub_federation::{
|
||||||
kinds::activity::FlagType,
|
kinds::activity::FlagType,
|
||||||
traits::{ActivityHandler, Actor},
|
traits::{ActivityHandler, Actor},
|
||||||
};
|
};
|
||||||
use lemmy_api_common::context::LemmyContext;
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
|
utils::{check_comment_deleted_or_removed, check_post_deleted_or_removed},
|
||||||
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
activity::ActivitySendTargets,
|
activity::ActivitySendTargets,
|
||||||
|
@ -104,6 +107,8 @@ impl ActivityHandler for Report {
|
||||||
let reason = self.reason()?;
|
let reason = self.reason()?;
|
||||||
match self.object.dereference(context).await? {
|
match self.object.dereference(context).await? {
|
||||||
PostOrComment::Post(post) => {
|
PostOrComment::Post(post) => {
|
||||||
|
check_post_deleted_or_removed(&post)?;
|
||||||
|
|
||||||
let report_form = PostReportForm {
|
let report_form = PostReportForm {
|
||||||
creator_id: actor.id,
|
creator_id: actor.id,
|
||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
|
@ -115,6 +120,8 @@ impl ActivityHandler for Report {
|
||||||
PostReport::report(&mut context.pool(), &report_form).await?;
|
PostReport::report(&mut context.pool(), &report_form).await?;
|
||||||
}
|
}
|
||||||
PostOrComment::Comment(comment) => {
|
PostOrComment::Comment(comment) => {
|
||||||
|
check_comment_deleted_or_removed(&comment)?;
|
||||||
|
|
||||||
let report_form = CommentReportForm {
|
let report_form = CommentReportForm {
|
||||||
creator_id: actor.id,
|
creator_id: actor.id,
|
||||||
comment_id: comment.id,
|
comment_id: comment.id,
|
||||||
|
|
|
@ -12,6 +12,7 @@ use lemmy_api_common::context::LemmyContext;
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
comment::{Comment, CommentUpdateForm},
|
comment::{Comment, CommentUpdateForm},
|
||||||
|
comment_report::CommentReport,
|
||||||
community::{Community, CommunityUpdateForm},
|
community::{Community, CommunityUpdateForm},
|
||||||
moderator::{
|
moderator::{
|
||||||
ModRemoveComment,
|
ModRemoveComment,
|
||||||
|
@ -22,8 +23,9 @@ use lemmy_db_schema::{
|
||||||
ModRemovePostForm,
|
ModRemovePostForm,
|
||||||
},
|
},
|
||||||
post::{Post, PostUpdateForm},
|
post::{Post, PostUpdateForm},
|
||||||
|
post_report::PostReport,
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::{Crud, Reportable},
|
||||||
};
|
};
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorType};
|
use lemmy_utils::error::{LemmyError, LemmyErrorType};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -136,6 +138,7 @@ pub(in crate::activities) async fn receive_remove_action(
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
DeletableObjects::Post(post) => {
|
DeletableObjects::Post(post) => {
|
||||||
|
PostReport::resolve_all_for_object(&mut context.pool(), post.id, actor.id).await?;
|
||||||
let form = ModRemovePostForm {
|
let form = ModRemovePostForm {
|
||||||
mod_person_id: actor.id,
|
mod_person_id: actor.id,
|
||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
|
@ -154,6 +157,7 @@ pub(in crate::activities) async fn receive_remove_action(
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
DeletableObjects::Comment(comment) => {
|
DeletableObjects::Comment(comment) => {
|
||||||
|
CommentReport::resolve_all_for_object(&mut context.pool(), comment.id, actor.id).await?;
|
||||||
let form = ModRemoveCommentForm {
|
let form = ModRemoveCommentForm {
|
||||||
mod_person_id: actor.id,
|
mod_person_id: actor.id,
|
||||||
comment_id: comment.id,
|
comment_id: comment.id,
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
newtypes::{CommentReportId, PersonId},
|
newtypes::{CommentId, CommentReportId, PersonId},
|
||||||
schema::comment_report::dsl::{comment_report, resolved, resolver_id, updated},
|
schema::comment_report::{
|
||||||
|
comment_id,
|
||||||
|
dsl::{comment_report, resolved, resolver_id, updated},
|
||||||
|
},
|
||||||
source::comment_report::{CommentReport, CommentReportForm},
|
source::comment_report::{CommentReport, CommentReportForm},
|
||||||
traits::Reportable,
|
traits::Reportable,
|
||||||
utils::{get_conn, naive_now, DbPool},
|
utils::{get_conn, naive_now, DbPool},
|
||||||
|
@ -17,6 +20,7 @@ use diesel_async::RunQueryDsl;
|
||||||
impl Reportable for CommentReport {
|
impl Reportable for CommentReport {
|
||||||
type Form = CommentReportForm;
|
type Form = CommentReportForm;
|
||||||
type IdType = CommentReportId;
|
type IdType = CommentReportId;
|
||||||
|
type ObjectIdType = CommentId;
|
||||||
/// creates a comment report and returns it
|
/// creates a comment report and returns it
|
||||||
///
|
///
|
||||||
/// * `conn` - the postgres connection
|
/// * `conn` - the postgres connection
|
||||||
|
@ -53,6 +57,22 @@ impl Reportable for CommentReport {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn resolve_all_for_object(
|
||||||
|
pool: &mut DbPool<'_>,
|
||||||
|
comment_id_: CommentId,
|
||||||
|
by_resolver_id: PersonId,
|
||||||
|
) -> Result<usize, Error> {
|
||||||
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
update(comment_report.filter(comment_id.eq(comment_id_)))
|
||||||
|
.set((
|
||||||
|
resolved.eq(true),
|
||||||
|
resolver_id.eq(by_resolver_id),
|
||||||
|
updated.eq(naive_now()),
|
||||||
|
))
|
||||||
|
.execute(conn)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
/// unresolve a comment report
|
/// unresolve a comment report
|
||||||
///
|
///
|
||||||
/// * `conn` - the postgres connection
|
/// * `conn` - the postgres connection
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
newtypes::{PersonId, PostReportId},
|
newtypes::{PersonId, PostId, PostReportId},
|
||||||
schema::post_report::dsl::{post_report, resolved, resolver_id, updated},
|
schema::post_report::{
|
||||||
|
dsl::{post_report, resolved, resolver_id, updated},
|
||||||
|
post_id,
|
||||||
|
},
|
||||||
source::post_report::{PostReport, PostReportForm},
|
source::post_report::{PostReport, PostReportForm},
|
||||||
traits::Reportable,
|
traits::Reportable,
|
||||||
utils::{get_conn, naive_now, DbPool},
|
utils::{get_conn, naive_now, DbPool},
|
||||||
|
@ -17,6 +20,7 @@ use diesel_async::RunQueryDsl;
|
||||||
impl Reportable for PostReport {
|
impl Reportable for PostReport {
|
||||||
type Form = PostReportForm;
|
type Form = PostReportForm;
|
||||||
type IdType = PostReportId;
|
type IdType = PostReportId;
|
||||||
|
type ObjectIdType = PostId;
|
||||||
|
|
||||||
async fn report(pool: &mut DbPool<'_>, post_report_form: &PostReportForm) -> Result<Self, Error> {
|
async fn report(pool: &mut DbPool<'_>, post_report_form: &PostReportForm) -> Result<Self, Error> {
|
||||||
let conn = &mut get_conn(pool).await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
@ -42,6 +46,22 @@ impl Reportable for PostReport {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn resolve_all_for_object(
|
||||||
|
pool: &mut DbPool<'_>,
|
||||||
|
post_id_: PostId,
|
||||||
|
by_resolver_id: PersonId,
|
||||||
|
) -> Result<usize, Error> {
|
||||||
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
update(post_report.filter(post_id.eq(post_id_)))
|
||||||
|
.set((
|
||||||
|
resolved.eq(true),
|
||||||
|
resolver_id.eq(by_resolver_id),
|
||||||
|
updated.eq(naive_now()),
|
||||||
|
))
|
||||||
|
.execute(conn)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
async fn unresolve(
|
async fn unresolve(
|
||||||
pool: &mut DbPool<'_>,
|
pool: &mut DbPool<'_>,
|
||||||
report_id: Self::IdType,
|
report_id: Self::IdType,
|
||||||
|
@ -75,7 +95,6 @@ mod tests {
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::build_db_pool_for_tests,
|
utils::build_db_pool_for_tests,
|
||||||
};
|
};
|
||||||
use pretty_assertions::assert_eq;
|
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
async fn init(pool: &mut DbPool<'_>) -> (Person, PostReport) {
|
async fn init(pool: &mut DbPool<'_>) -> (Person, PostReport) {
|
||||||
|
@ -135,4 +154,21 @@ mod tests {
|
||||||
Person::delete(pool, person.id).await.unwrap();
|
Person::delete(pool, person.id).await.unwrap();
|
||||||
Post::delete(pool, report.post_id).await.unwrap();
|
Post::delete(pool, report.post_id).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
#[serial]
|
||||||
|
async fn test_resolve_all_post_reports() {
|
||||||
|
let pool = &build_db_pool_for_tests().await;
|
||||||
|
let pool = &mut pool.into();
|
||||||
|
|
||||||
|
let (person, report) = init(pool).await;
|
||||||
|
|
||||||
|
let resolved_count = PostReport::resolve_all_for_object(pool, report.post_id, person.id)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(resolved_count, 1);
|
||||||
|
|
||||||
|
Person::delete(pool, person.id).await.unwrap();
|
||||||
|
Post::delete(pool, report.post_id).await.unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
newtypes::{PersonId, PrivateMessageReportId},
|
newtypes::{PersonId, PrivateMessageId, PrivateMessageReportId},
|
||||||
schema::private_message_report::dsl::{private_message_report, resolved, resolver_id, updated},
|
schema::private_message_report::dsl::{private_message_report, resolved, resolver_id, updated},
|
||||||
source::private_message_report::{PrivateMessageReport, PrivateMessageReportForm},
|
source::private_message_report::{PrivateMessageReport, PrivateMessageReportForm},
|
||||||
traits::Reportable,
|
traits::Reportable,
|
||||||
|
@ -17,6 +17,7 @@ use diesel_async::RunQueryDsl;
|
||||||
impl Reportable for PrivateMessageReport {
|
impl Reportable for PrivateMessageReport {
|
||||||
type Form = PrivateMessageReportForm;
|
type Form = PrivateMessageReportForm;
|
||||||
type IdType = PrivateMessageReportId;
|
type IdType = PrivateMessageReportId;
|
||||||
|
type ObjectIdType = PrivateMessageId;
|
||||||
|
|
||||||
async fn report(
|
async fn report(
|
||||||
pool: &mut DbPool<'_>,
|
pool: &mut DbPool<'_>,
|
||||||
|
@ -45,6 +46,15 @@ impl Reportable for PrivateMessageReport {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: this is unused because private message doesnt have remove handler
|
||||||
|
async fn resolve_all_for_object(
|
||||||
|
_pool: &mut DbPool<'_>,
|
||||||
|
_pm_id_: PrivateMessageId,
|
||||||
|
_by_resolver_id: PersonId,
|
||||||
|
) -> Result<usize, Error> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
async fn unresolve(
|
async fn unresolve(
|
||||||
pool: &mut DbPool<'_>,
|
pool: &mut DbPool<'_>,
|
||||||
report_id: Self::IdType,
|
report_id: Self::IdType,
|
||||||
|
|
|
@ -144,6 +144,7 @@ pub trait Blockable {
|
||||||
pub trait Reportable {
|
pub trait Reportable {
|
||||||
type Form;
|
type Form;
|
||||||
type IdType;
|
type IdType;
|
||||||
|
type ObjectIdType;
|
||||||
async fn report(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<Self, Error>
|
async fn report(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
|
@ -152,6 +153,13 @@ pub trait Reportable {
|
||||||
report_id: Self::IdType,
|
report_id: Self::IdType,
|
||||||
resolver_id: PersonId,
|
resolver_id: PersonId,
|
||||||
) -> Result<usize, Error>
|
) -> Result<usize, Error>
|
||||||
|
where
|
||||||
|
Self: Sized;
|
||||||
|
async fn resolve_all_for_object(
|
||||||
|
pool: &mut DbPool<'_>,
|
||||||
|
comment_id_: Self::ObjectIdType,
|
||||||
|
by_resolver_id: PersonId,
|
||||||
|
) -> Result<usize, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn unresolve(
|
async fn unresolve(
|
||||||
|
|
|
@ -201,7 +201,6 @@ mod tests {
|
||||||
community::{Community, CommunityInsertForm, CommunityModerator, CommunityModeratorForm},
|
community::{Community, CommunityInsertForm, CommunityModerator, CommunityModeratorForm},
|
||||||
instance::Instance,
|
instance::Instance,
|
||||||
local_user::{LocalUser, LocalUserInsertForm},
|
local_user::{LocalUser, LocalUserInsertForm},
|
||||||
moderator::{ModRemovePost, ModRemovePostForm},
|
|
||||||
person::{Person, PersonInsertForm},
|
person::{Person, PersonInsertForm},
|
||||||
post::{Post, PostInsertForm},
|
post::{Post, PostInsertForm},
|
||||||
post_report::{PostReport, PostReportForm},
|
post_report::{PostReport, PostReportForm},
|
||||||
|
@ -350,14 +349,11 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(2, report_count);
|
assert_eq!(2, report_count);
|
||||||
|
|
||||||
// Writing post removal to mod log should automatically resolve reports
|
// Pretend the post was removed, and resolve all reports for that object.
|
||||||
let remove_form = ModRemovePostForm {
|
// This is called manually in the API for post removals
|
||||||
mod_person_id: inserted_timmy.id,
|
PostReport::resolve_all_for_object(pool, inserted_jessica_report.post_id, inserted_timmy.id)
|
||||||
post_id: inserted_jessica_report.post_id,
|
.await
|
||||||
reason: None,
|
.unwrap();
|
||||||
removed: Some(true),
|
|
||||||
};
|
|
||||||
ModRemovePost::create(pool, &remove_form).await.unwrap();
|
|
||||||
|
|
||||||
let read_jessica_report_view_after_resolve =
|
let read_jessica_report_view_after_resolve =
|
||||||
PostReportView::read(pool, inserted_jessica_report.id, inserted_timmy.id)
|
PostReportView::read(pool, inserted_jessica_report.id, inserted_timmy.id)
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
-- Automatically resolve all reports for a given post once it is marked as removed
|
||||||
|
CREATE OR REPLACE FUNCTION post_removed_resolve_reports ()
|
||||||
|
RETURNS TRIGGER
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $$
|
||||||
|
BEGIN
|
||||||
|
UPDATE
|
||||||
|
post_report
|
||||||
|
SET
|
||||||
|
resolved = TRUE,
|
||||||
|
resolver_id = NEW.mod_person_id,
|
||||||
|
updated = now()
|
||||||
|
WHERE
|
||||||
|
post_report.post_id = NEW.post_id;
|
||||||
|
RETURN NULL;
|
||||||
|
END
|
||||||
|
$$;
|
||||||
|
|
||||||
|
CREATE OR REPLACE TRIGGER post_removed_resolve_reports
|
||||||
|
AFTER INSERT ON mod_remove_post
|
||||||
|
FOR EACH ROW
|
||||||
|
WHEN (NEW.removed)
|
||||||
|
EXECUTE PROCEDURE post_removed_resolve_reports ();
|
||||||
|
|
||||||
|
-- Same when comment is marked as removed
|
||||||
|
CREATE OR REPLACE FUNCTION comment_removed_resolve_reports ()
|
||||||
|
RETURNS TRIGGER
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $$
|
||||||
|
BEGIN
|
||||||
|
UPDATE
|
||||||
|
comment_report
|
||||||
|
SET
|
||||||
|
resolved = TRUE,
|
||||||
|
resolver_id = NEW.mod_person_id,
|
||||||
|
updated = now()
|
||||||
|
WHERE
|
||||||
|
comment_report.comment_id = NEW.comment_id;
|
||||||
|
RETURN NULL;
|
||||||
|
END
|
||||||
|
$$;
|
||||||
|
|
||||||
|
CREATE OR REPLACE TRIGGER comment_removed_resolve_reports
|
||||||
|
AFTER INSERT ON mod_remove_comment
|
||||||
|
FOR EACH ROW
|
||||||
|
WHEN (NEW.removed)
|
||||||
|
EXECUTE PROCEDURE comment_removed_resolve_reports ();
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
DROP TRIGGER IF EXISTS post_removed_resolve_reports ON mod_remove_post;
|
||||||
|
|
||||||
|
DROP FUNCTION IF EXISTS post_removed_resolve_reports;
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS comment_removed_resolve_reports ON mod_remove_comment;
|
||||||
|
|
||||||
|
DROP FUNCTION IF EXISTS comment_removed_resolve_reports;
|
||||||
|
|
Loading…
Reference in a new issue