mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-26 22:31:20 +00:00
Admins can view all reports. Fixes #1810
This commit is contained in:
parent
b96ce81f89
commit
61f22cc670
5 changed files with 51 additions and 47 deletions
|
@ -155,13 +155,14 @@ impl Perform for ListCommentReports {
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
let admin = local_user_view.person.admin;
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let unresolved_only = data.unresolved_only;
|
let unresolved_only = data.unresolved_only;
|
||||||
|
|
||||||
let page = data.page;
|
let page = data.page;
|
||||||
let limit = data.limit;
|
let limit = data.limit;
|
||||||
let comment_reports = blocking(context.pool(), move |conn| {
|
let comment_reports = blocking(context.pool(), move |conn| {
|
||||||
CommentReportQueryBuilder::create(conn, person_id)
|
CommentReportQueryBuilder::create(conn, person_id, admin)
|
||||||
.community_id(community_id)
|
.community_id(community_id)
|
||||||
.unresolved_only(unresolved_only)
|
.unresolved_only(unresolved_only)
|
||||||
.page(page)
|
.page(page)
|
||||||
|
|
|
@ -822,15 +822,16 @@ impl Perform for GetReportCount {
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
let admin = local_user_view.person.admin;
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
|
|
||||||
let comment_reports = blocking(context.pool(), move |conn| {
|
let comment_reports = blocking(context.pool(), move |conn| {
|
||||||
CommentReportView::get_report_count(conn, person_id, community_id)
|
CommentReportView::get_report_count(conn, person_id, admin, community_id)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
let post_reports = blocking(context.pool(), move |conn| {
|
let post_reports = blocking(context.pool(), move |conn| {
|
||||||
PostReportView::get_report_count(conn, person_id, community_id)
|
PostReportView::get_report_count(conn, person_id, admin, community_id)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
|
|
|
@ -158,13 +158,14 @@ impl Perform for ListPostReports {
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
let admin = local_user_view.person.admin;
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let unresolved_only = data.unresolved_only;
|
let unresolved_only = data.unresolved_only;
|
||||||
|
|
||||||
let page = data.page;
|
let page = data.page;
|
||||||
let limit = data.limit;
|
let limit = data.limit;
|
||||||
let post_reports = blocking(context.pool(), move |conn| {
|
let post_reports = blocking(context.pool(), move |conn| {
|
||||||
PostReportQueryBuilder::create(conn, person_id)
|
PostReportQueryBuilder::create(conn, person_id, admin)
|
||||||
.community_id(community_id)
|
.community_id(community_id)
|
||||||
.unresolved_only(unresolved_only)
|
.unresolved_only(unresolved_only)
|
||||||
.page(page)
|
.page(page)
|
||||||
|
|
|
@ -141,15 +141,11 @@ impl CommentReportView {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// returns the current unresolved post report count for the supplied community ids
|
/// Returns the current unresolved post report count for the communities you mod
|
||||||
///
|
|
||||||
/// * `community_ids` - a Vec<i32> of community_ids to get a count for
|
|
||||||
/// TODO this eq_any is a bad way to do this, would be better to join to communitymoderator
|
|
||||||
/// TODO FIX THIS NOW
|
|
||||||
/// for a person id
|
|
||||||
pub fn get_report_count(
|
pub fn get_report_count(
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
my_person_id: PersonId,
|
my_person_id: PersonId,
|
||||||
|
admin: bool,
|
||||||
community_id: Option<CommunityId>,
|
community_id: Option<CommunityId>,
|
||||||
) -> Result<i64, Error> {
|
) -> Result<i64, Error> {
|
||||||
use diesel::dsl::*;
|
use diesel::dsl::*;
|
||||||
|
@ -157,17 +153,17 @@ impl CommentReportView {
|
||||||
let mut query = comment_report::table
|
let mut query = comment_report::table
|
||||||
.inner_join(comment::table)
|
.inner_join(comment::table)
|
||||||
.inner_join(post::table.on(comment::post_id.eq(post::id)))
|
.inner_join(post::table.on(comment::post_id.eq(post::id)))
|
||||||
// Test this join
|
|
||||||
.inner_join(
|
.inner_join(
|
||||||
community_moderator::table.on(
|
community_moderator::table.on(community_moderator::community_id.eq(post::community_id)),
|
||||||
community_moderator::community_id
|
|
||||||
.eq(post::community_id)
|
|
||||||
.and(community_moderator::person_id.eq(my_person_id)),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.filter(comment_report::resolved.eq(false))
|
.filter(comment_report::resolved.eq(false))
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
|
|
||||||
|
// If its not an admin, get only the ones you mod
|
||||||
|
if !admin {
|
||||||
|
query = query.filter(community_moderator::person_id.eq(my_person_id));
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(community_id) = community_id {
|
if let Some(community_id) = community_id {
|
||||||
query = query.filter(post::community_id.eq(community_id))
|
query = query.filter(post::community_id.eq(community_id))
|
||||||
}
|
}
|
||||||
|
@ -179,6 +175,7 @@ impl CommentReportView {
|
||||||
pub struct CommentReportQueryBuilder<'a> {
|
pub struct CommentReportQueryBuilder<'a> {
|
||||||
conn: &'a PgConnection,
|
conn: &'a PgConnection,
|
||||||
my_person_id: PersonId,
|
my_person_id: PersonId,
|
||||||
|
admin: bool,
|
||||||
community_id: Option<CommunityId>,
|
community_id: Option<CommunityId>,
|
||||||
page: Option<i64>,
|
page: Option<i64>,
|
||||||
limit: Option<i64>,
|
limit: Option<i64>,
|
||||||
|
@ -186,10 +183,11 @@ pub struct CommentReportQueryBuilder<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> CommentReportQueryBuilder<'a> {
|
impl<'a> CommentReportQueryBuilder<'a> {
|
||||||
pub fn create(conn: &'a PgConnection, my_person_id: PersonId) -> Self {
|
pub fn create(conn: &'a PgConnection, my_person_id: PersonId, admin: bool) -> Self {
|
||||||
CommentReportQueryBuilder {
|
CommentReportQueryBuilder {
|
||||||
conn,
|
conn,
|
||||||
my_person_id,
|
my_person_id,
|
||||||
|
admin,
|
||||||
community_id: None,
|
community_id: None,
|
||||||
page: None,
|
page: None,
|
||||||
limit: None,
|
limit: None,
|
||||||
|
@ -226,11 +224,7 @@ impl<'a> CommentReportQueryBuilder<'a> {
|
||||||
.inner_join(person_alias_1::table.on(post::creator_id.eq(person_alias_1::id)))
|
.inner_join(person_alias_1::table.on(post::creator_id.eq(person_alias_1::id)))
|
||||||
// Test this join
|
// Test this join
|
||||||
.inner_join(
|
.inner_join(
|
||||||
community_moderator::table.on(
|
community_moderator::table.on(community_moderator::community_id.eq(post::community_id)),
|
||||||
community_moderator::community_id
|
|
||||||
.eq(post::community_id)
|
|
||||||
.and(community_moderator::person_id.eq(self.my_person_id)),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.inner_join(
|
.inner_join(
|
||||||
comment_aggregates::table.on(comment_report::comment_id.eq(comment_aggregates::comment_id)),
|
comment_aggregates::table.on(comment_report::comment_id.eq(comment_aggregates::comment_id)),
|
||||||
|
@ -266,6 +260,11 @@ impl<'a> CommentReportQueryBuilder<'a> {
|
||||||
))
|
))
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
|
|
||||||
|
// If its not an admin, get only the ones you mod
|
||||||
|
if !self.admin {
|
||||||
|
query = query.filter(community_moderator::person_id.eq(self.my_person_id));
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(community_id) = self.community_id {
|
if let Some(community_id) = self.community_id {
|
||||||
query = query.filter(post::community_id.eq(community_id));
|
query = query.filter(post::community_id.eq(community_id));
|
||||||
}
|
}
|
||||||
|
@ -500,7 +499,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Do a batch read of timmys reports
|
// Do a batch read of timmys reports
|
||||||
let reports = CommentReportQueryBuilder::create(&conn, inserted_timmy.id)
|
let reports = CommentReportQueryBuilder::create(&conn, inserted_timmy.id, false)
|
||||||
.list()
|
.list()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -513,7 +512,8 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Make sure the counts are correct
|
// Make sure the counts are correct
|
||||||
let report_count = CommentReportView::get_report_count(&conn, inserted_timmy.id, None).unwrap();
|
let report_count =
|
||||||
|
CommentReportView::get_report_count(&conn, inserted_timmy.id, false, None).unwrap();
|
||||||
assert_eq!(2, report_count);
|
assert_eq!(2, report_count);
|
||||||
|
|
||||||
// Try to resolve the report
|
// Try to resolve the report
|
||||||
|
@ -560,14 +560,14 @@ mod tests {
|
||||||
|
|
||||||
// Do a batch read of timmys reports
|
// Do a batch read of timmys reports
|
||||||
// It should only show saras, which is unresolved
|
// It should only show saras, which is unresolved
|
||||||
let reports_after_resolve = CommentReportQueryBuilder::create(&conn, inserted_timmy.id)
|
let reports_after_resolve = CommentReportQueryBuilder::create(&conn, inserted_timmy.id, false)
|
||||||
.list()
|
.list()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(reports_after_resolve[0], expected_sara_report_view);
|
assert_eq!(reports_after_resolve[0], expected_sara_report_view);
|
||||||
|
|
||||||
// Make sure the counts are correct
|
// Make sure the counts are correct
|
||||||
let report_count_after_resolved =
|
let report_count_after_resolved =
|
||||||
CommentReportView::get_report_count(&conn, inserted_timmy.id, None).unwrap();
|
CommentReportView::get_report_count(&conn, inserted_timmy.id, false, None).unwrap();
|
||||||
assert_eq!(1, report_count_after_resolved);
|
assert_eq!(1, report_count_after_resolved);
|
||||||
|
|
||||||
Person::delete(&conn, inserted_timmy.id).unwrap();
|
Person::delete(&conn, inserted_timmy.id).unwrap();
|
||||||
|
|
|
@ -127,14 +127,11 @@ impl PostReportView {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// returns the current unresolved post report count for the supplied community ids
|
/// returns the current unresolved post report count for the communities you mod
|
||||||
///
|
|
||||||
/// * `community_ids` - a Vec<i32> of community_ids to get a count for
|
|
||||||
/// TODO this eq_any is a bad way to do this, would be better to join to communitymoderator
|
|
||||||
/// for a person id
|
|
||||||
pub fn get_report_count(
|
pub fn get_report_count(
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
my_person_id: PersonId,
|
my_person_id: PersonId,
|
||||||
|
admin: bool,
|
||||||
community_id: Option<CommunityId>,
|
community_id: Option<CommunityId>,
|
||||||
) -> Result<i64, Error> {
|
) -> Result<i64, Error> {
|
||||||
use diesel::dsl::*;
|
use diesel::dsl::*;
|
||||||
|
@ -142,15 +139,16 @@ impl PostReportView {
|
||||||
.inner_join(post::table)
|
.inner_join(post::table)
|
||||||
// Test this join
|
// Test this join
|
||||||
.inner_join(
|
.inner_join(
|
||||||
community_moderator::table.on(
|
community_moderator::table.on(community_moderator::community_id.eq(post::community_id)),
|
||||||
community_moderator::community_id
|
|
||||||
.eq(post::community_id)
|
|
||||||
.and(community_moderator::person_id.eq(my_person_id)),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.filter(post_report::resolved.eq(false))
|
.filter(post_report::resolved.eq(false))
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
|
|
||||||
|
// If its not an admin, get only the ones you mod
|
||||||
|
if !admin {
|
||||||
|
query = query.filter(community_moderator::person_id.eq(my_person_id));
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(community_id) = community_id {
|
if let Some(community_id) = community_id {
|
||||||
query = query.filter(post::community_id.eq(community_id))
|
query = query.filter(post::community_id.eq(community_id))
|
||||||
}
|
}
|
||||||
|
@ -162,6 +160,7 @@ impl PostReportView {
|
||||||
pub struct PostReportQueryBuilder<'a> {
|
pub struct PostReportQueryBuilder<'a> {
|
||||||
conn: &'a PgConnection,
|
conn: &'a PgConnection,
|
||||||
my_person_id: PersonId,
|
my_person_id: PersonId,
|
||||||
|
admin: bool,
|
||||||
community_id: Option<CommunityId>,
|
community_id: Option<CommunityId>,
|
||||||
page: Option<i64>,
|
page: Option<i64>,
|
||||||
limit: Option<i64>,
|
limit: Option<i64>,
|
||||||
|
@ -169,10 +168,11 @@ pub struct PostReportQueryBuilder<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> PostReportQueryBuilder<'a> {
|
impl<'a> PostReportQueryBuilder<'a> {
|
||||||
pub fn create(conn: &'a PgConnection, my_person_id: PersonId) -> Self {
|
pub fn create(conn: &'a PgConnection, my_person_id: PersonId, admin: bool) -> Self {
|
||||||
PostReportQueryBuilder {
|
PostReportQueryBuilder {
|
||||||
conn,
|
conn,
|
||||||
my_person_id,
|
my_person_id,
|
||||||
|
admin,
|
||||||
community_id: None,
|
community_id: None,
|
||||||
page: None,
|
page: None,
|
||||||
limit: None,
|
limit: None,
|
||||||
|
@ -206,13 +206,8 @@ impl<'a> PostReportQueryBuilder<'a> {
|
||||||
.inner_join(community::table.on(post::community_id.eq(community::id)))
|
.inner_join(community::table.on(post::community_id.eq(community::id)))
|
||||||
.inner_join(person::table.on(post_report::creator_id.eq(person::id)))
|
.inner_join(person::table.on(post_report::creator_id.eq(person::id)))
|
||||||
.inner_join(person_alias_1::table.on(post::creator_id.eq(person_alias_1::id)))
|
.inner_join(person_alias_1::table.on(post::creator_id.eq(person_alias_1::id)))
|
||||||
// Test this join
|
|
||||||
.inner_join(
|
.inner_join(
|
||||||
community_moderator::table.on(
|
community_moderator::table.on(community_moderator::community_id.eq(post::community_id)),
|
||||||
community_moderator::community_id
|
|
||||||
.eq(post::community_id)
|
|
||||||
.and(community_moderator::person_id.eq(self.my_person_id)),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.left_join(
|
.left_join(
|
||||||
community_person_ban::table.on(
|
community_person_ban::table.on(
|
||||||
|
@ -245,6 +240,11 @@ impl<'a> PostReportQueryBuilder<'a> {
|
||||||
))
|
))
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
|
|
||||||
|
// If its not an admin, get only the ones you mod
|
||||||
|
if !self.admin {
|
||||||
|
query = query.filter(community_moderator::person_id.eq(self.my_person_id));
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(community_id) = self.community_id {
|
if let Some(community_id) = self.community_id {
|
||||||
query = query.filter(post::community_id.eq(community_id));
|
query = query.filter(post::community_id.eq(community_id));
|
||||||
}
|
}
|
||||||
|
@ -482,7 +482,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Do a batch read of timmys reports
|
// Do a batch read of timmys reports
|
||||||
let reports = PostReportQueryBuilder::create(&conn, inserted_timmy.id)
|
let reports = PostReportQueryBuilder::create(&conn, inserted_timmy.id, false)
|
||||||
.list()
|
.list()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -495,7 +495,8 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Make sure the counts are correct
|
// Make sure the counts are correct
|
||||||
let report_count = PostReportView::get_report_count(&conn, inserted_timmy.id, None).unwrap();
|
let report_count =
|
||||||
|
PostReportView::get_report_count(&conn, inserted_timmy.id, false, None).unwrap();
|
||||||
assert_eq!(2, report_count);
|
assert_eq!(2, report_count);
|
||||||
|
|
||||||
// Try to resolve the report
|
// Try to resolve the report
|
||||||
|
@ -540,14 +541,14 @@ mod tests {
|
||||||
|
|
||||||
// Do a batch read of timmys reports
|
// Do a batch read of timmys reports
|
||||||
// It should only show saras, which is unresolved
|
// It should only show saras, which is unresolved
|
||||||
let reports_after_resolve = PostReportQueryBuilder::create(&conn, inserted_timmy.id)
|
let reports_after_resolve = PostReportQueryBuilder::create(&conn, inserted_timmy.id, false)
|
||||||
.list()
|
.list()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(reports_after_resolve[0], expected_sara_report_view);
|
assert_eq!(reports_after_resolve[0], expected_sara_report_view);
|
||||||
|
|
||||||
// Make sure the counts are correct
|
// Make sure the counts are correct
|
||||||
let report_count_after_resolved =
|
let report_count_after_resolved =
|
||||||
PostReportView::get_report_count(&conn, inserted_timmy.id, None).unwrap();
|
PostReportView::get_report_count(&conn, inserted_timmy.id, false, None).unwrap();
|
||||||
assert_eq!(1, report_count_after_resolved);
|
assert_eq!(1, report_count_after_resolved);
|
||||||
|
|
||||||
Person::delete(&conn, inserted_timmy.id).unwrap();
|
Person::delete(&conn, inserted_timmy.id).unwrap();
|
||||||
|
|
Loading…
Reference in a new issue