|
|
|
@ -141,15 +141,11 @@ impl CommentReportView {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// returns the current unresolved post report count for the supplied community ids
|
|
|
|
|
///
|
|
|
|
|
/// * `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
|
|
|
|
|
/// Returns the current unresolved post report count for the communities you mod
|
|
|
|
|
pub fn get_report_count(
|
|
|
|
|
conn: &PgConnection,
|
|
|
|
|
my_person_id: PersonId,
|
|
|
|
|
admin: bool,
|
|
|
|
|
community_id: Option<CommunityId>,
|
|
|
|
|
) -> Result<i64, Error> {
|
|
|
|
|
use diesel::dsl::*;
|
|
|
|
@ -157,17 +153,17 @@ impl CommentReportView {
|
|
|
|
|
let mut query = comment_report::table
|
|
|
|
|
.inner_join(comment::table)
|
|
|
|
|
.inner_join(post::table.on(comment::post_id.eq(post::id)))
|
|
|
|
|
// Test this join
|
|
|
|
|
.inner_join(
|
|
|
|
|
community_moderator::table.on(
|
|
|
|
|
community_moderator::community_id
|
|
|
|
|
.eq(post::community_id)
|
|
|
|
|
.and(community_moderator::person_id.eq(my_person_id)),
|
|
|
|
|
),
|
|
|
|
|
community_moderator::table.on(community_moderator::community_id.eq(post::community_id)),
|
|
|
|
|
)
|
|
|
|
|
.filter(comment_report::resolved.eq(false))
|
|
|
|
|
.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 {
|
|
|
|
|
query = query.filter(post::community_id.eq(community_id))
|
|
|
|
|
}
|
|
|
|
@ -179,6 +175,7 @@ impl CommentReportView {
|
|
|
|
|
pub struct CommentReportQueryBuilder<'a> {
|
|
|
|
|
conn: &'a PgConnection,
|
|
|
|
|
my_person_id: PersonId,
|
|
|
|
|
admin: bool,
|
|
|
|
|
community_id: Option<CommunityId>,
|
|
|
|
|
page: Option<i64>,
|
|
|
|
|
limit: Option<i64>,
|
|
|
|
@ -186,10 +183,11 @@ pub struct 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 {
|
|
|
|
|
conn,
|
|
|
|
|
my_person_id,
|
|
|
|
|
admin,
|
|
|
|
|
community_id: None,
|
|
|
|
|
page: 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)))
|
|
|
|
|
// Test this join
|
|
|
|
|
.inner_join(
|
|
|
|
|
community_moderator::table.on(
|
|
|
|
|
community_moderator::community_id
|
|
|
|
|
.eq(post::community_id)
|
|
|
|
|
.and(community_moderator::person_id.eq(self.my_person_id)),
|
|
|
|
|
),
|
|
|
|
|
community_moderator::table.on(community_moderator::community_id.eq(post::community_id)),
|
|
|
|
|
)
|
|
|
|
|
.inner_join(
|
|
|
|
|
comment_aggregates::table.on(comment_report::comment_id.eq(comment_aggregates::comment_id)),
|
|
|
|
@ -266,6 +260,11 @@ impl<'a> CommentReportQueryBuilder<'a> {
|
|
|
|
|
))
|
|
|
|
|
.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 {
|
|
|
|
|
query = query.filter(post::community_id.eq(community_id));
|
|
|
|
|
}
|
|
|
|
@ -500,7 +499,7 @@ mod tests {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 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()
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
@ -513,7 +512,8 @@ mod tests {
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
|
|
// Try to resolve the report
|
|
|
|
@ -560,14 +560,14 @@ mod tests {
|
|
|
|
|
|
|
|
|
|
// Do a batch read of timmys reports
|
|
|
|
|
// 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()
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert_eq!(reports_after_resolve[0], expected_sara_report_view);
|
|
|
|
|
|
|
|
|
|
// Make sure the counts are correct
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
Person::delete(&conn, inserted_timmy.id).unwrap();
|
|
|
|
|