mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-09-02 19:23:49 +00:00
parent
d1eff9084b
commit
806f541fe5
3 changed files with 72 additions and 7 deletions
|
@ -14,7 +14,12 @@ pub async fn list_reports(
|
|||
context: Data<LemmyContext>,
|
||||
local_user_view: LocalUserView,
|
||||
) -> LemmyResult<Json<ListReportsResponse>> {
|
||||
check_community_mod_of_any_or_admin_action(&local_user_view, &mut context.pool()).await?;
|
||||
let my_reports_only = data.my_reports_only;
|
||||
|
||||
// Only check mod or admin status when not viewing my reports
|
||||
if !my_reports_only.unwrap_or_default() {
|
||||
check_community_mod_of_any_or_admin_action(&local_user_view, &mut context.pool()).await?;
|
||||
}
|
||||
|
||||
// parse pagination token
|
||||
let page_after = if let Some(pa) = &data.page_cursor {
|
||||
|
@ -32,6 +37,7 @@ pub async fn list_reports(
|
|||
page_after,
|
||||
page_back,
|
||||
show_community_rule_violations: data.show_community_rule_violations,
|
||||
my_reports_only,
|
||||
}
|
||||
.list(&mut context.pool(), &local_user_view)
|
||||
.await?;
|
||||
|
|
|
@ -33,6 +33,9 @@ pub struct ListReports {
|
|||
/// Only for admins: also show reports with `violates_instance_rules=false`
|
||||
#[cfg_attr(feature = "full", ts(optional))]
|
||||
pub show_community_rule_violations: Option<bool>,
|
||||
/// If true, view all your created reports. Works for non-admins/mods also.
|
||||
#[cfg_attr(feature = "full", ts(optional))]
|
||||
pub my_reports_only: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
|
|
|
@ -255,6 +255,7 @@ pub struct ReportCombinedQuery {
|
|||
pub unresolved_only: Option<bool>,
|
||||
/// For admins, also show reports with `violates_instance_rules=false`
|
||||
pub show_community_rule_violations: Option<bool>,
|
||||
pub my_reports_only: Option<bool>,
|
||||
pub page_after: Option<PaginationCursorData>,
|
||||
pub page_back: Option<bool>,
|
||||
}
|
||||
|
@ -335,6 +336,10 @@ impl ReportCombinedQuery {
|
|||
query = query.filter(post::id.eq(post_id));
|
||||
}
|
||||
|
||||
if self.my_reports_only.unwrap_or_default() {
|
||||
query = query.filter(person::id.eq(my_person_id));
|
||||
}
|
||||
|
||||
let mut query = PaginatedQueryBuilder::new(query);
|
||||
|
||||
let page_after = self.page_after.map(|c| c.0);
|
||||
|
@ -674,7 +679,7 @@ mod tests {
|
|||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn test_combined() -> LemmyResult<()> {
|
||||
async fn combined() -> LemmyResult<()> {
|
||||
let pool = &build_db_pool_for_tests();
|
||||
let pool = &mut pool.into();
|
||||
let data = init_data(pool).await?;
|
||||
|
@ -845,7 +850,7 @@ mod tests {
|
|||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn test_private_message_reports() -> LemmyResult<()> {
|
||||
async fn private_message_reports() -> LemmyResult<()> {
|
||||
let pool = &build_db_pool_for_tests();
|
||||
let pool = &mut pool.into();
|
||||
let data = init_data(pool).await?;
|
||||
|
@ -909,7 +914,7 @@ mod tests {
|
|||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn test_post_reports() -> LemmyResult<()> {
|
||||
async fn post_reports() -> LemmyResult<()> {
|
||||
let pool = &build_db_pool_for_tests();
|
||||
let pool = &mut pool.into();
|
||||
let data = init_data(pool).await?;
|
||||
|
@ -1042,7 +1047,7 @@ mod tests {
|
|||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn test_comment_reports() -> LemmyResult<()> {
|
||||
async fn comment_reports() -> LemmyResult<()> {
|
||||
let pool = &build_db_pool_for_tests();
|
||||
let pool = &mut pool.into();
|
||||
let data = init_data(pool).await?;
|
||||
|
@ -1158,7 +1163,7 @@ mod tests {
|
|||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn test_community_reports() -> LemmyResult<()> {
|
||||
async fn community_reports() -> LemmyResult<()> {
|
||||
let pool = &build_db_pool_for_tests();
|
||||
let pool = &mut pool.into();
|
||||
let data = init_data(pool).await?;
|
||||
|
@ -1222,7 +1227,7 @@ mod tests {
|
|||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn test_violates_instance_rules() -> LemmyResult<()> {
|
||||
async fn violates_instance_rules() -> LemmyResult<()> {
|
||||
let pool = &build_db_pool_for_tests();
|
||||
let pool = &mut pool.into();
|
||||
let data = init_data(pool).await?;
|
||||
|
@ -1309,4 +1314,55 @@ mod tests {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn my_reports_only() -> LemmyResult<()> {
|
||||
let pool = &build_db_pool_for_tests();
|
||||
let pool = &mut pool.into();
|
||||
let data = init_data(pool).await?;
|
||||
|
||||
// sara reports
|
||||
let sara_report_form = CommentReportForm {
|
||||
creator_id: data.sara.id,
|
||||
comment_id: data.comment.id,
|
||||
original_comment_text: "this was it at time of creation".into(),
|
||||
reason: "from sara".into(),
|
||||
violates_instance_rules: false,
|
||||
};
|
||||
CommentReport::report(pool, &sara_report_form).await?;
|
||||
|
||||
// timmy reports
|
||||
let timmy_report_form = CommentReportForm {
|
||||
creator_id: data.timmy.id,
|
||||
comment_id: data.comment.id,
|
||||
original_comment_text: "this was it at time of creation".into(),
|
||||
reason: "from timmy".into(),
|
||||
violates_instance_rules: false,
|
||||
};
|
||||
CommentReport::report(pool, &timmy_report_form).await?;
|
||||
|
||||
let agg = CommentAggregates::read(pool, data.comment.id).await?;
|
||||
assert_eq!(agg.report_count, 2);
|
||||
|
||||
// Do a batch read of timmys reports, it should only show his own
|
||||
let reports = ReportCombinedQuery {
|
||||
my_reports_only: Some(true),
|
||||
..Default::default()
|
||||
}
|
||||
.list(pool, &data.timmy_view)
|
||||
.await?;
|
||||
|
||||
assert_length!(1, reports);
|
||||
|
||||
if let ReportCombinedView::Comment(v) = &reports[0] {
|
||||
assert_eq!(v.creator.id, data.timmy.id);
|
||||
} else {
|
||||
panic!("wrong type");
|
||||
}
|
||||
|
||||
cleanup(data, pool).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue