@ -1,4 +1,4 @@
use crate ::structs ::CommentReportView ;
use crate ::structs ::{ CommentReportView , LocalUserView } ;
use diesel ::{
dsl ::now ,
pg ::Pg ,
@ -38,7 +38,7 @@ use lemmy_db_schema::{
fn queries < ' a > ( ) -> Queries <
impl ReadFn < ' a , CommentReportView , ( CommentReportId , PersonId ) > ,
impl ListFn < ' a , CommentReportView , ( CommentReportQuery , & ' a Person ) > ,
impl ListFn < ' a , CommentReportView , ( CommentReportQuery , & ' a LocalUserView ) > ,
> {
let all_joins = | query : comment_report ::BoxedQuery < ' a , Pg > , my_person_id : PersonId | {
query
@ -93,8 +93,9 @@ fn queries<'a>() -> Queries<
. await
} ;
let list = move | mut conn : DbConn < ' a > , ( options , my_person ) : ( CommentReportQuery , & ' a Person ) | async move {
let mut query = all_joins ( comment_report ::table . into_boxed ( ) , my_person . id )
let list = move | mut conn : DbConn < ' a > ,
( options , user ) : ( CommentReportQuery , & ' a LocalUserView ) | async move {
let mut query = all_joins ( comment_report ::table . into_boxed ( ) , user . person . id )
. left_join (
community_person_ban ::table . on (
community ::id
@ -125,13 +126,13 @@ fn queries<'a>() -> Queries<
. offset ( offset ) ;
// If its not an admin, get only the ones you mod
if ! my_person . admin {
if ! user. local_user . admin {
query
. inner_join (
community_moderator ::table . on (
community_moderator ::community_id
. eq ( post ::community_id )
. and ( community_moderator ::person_id . eq ( my_ person. id ) ) ,
. and ( community_moderator ::person_id . eq ( user. person. id ) ) ,
) ,
)
. load ::< < CommentReportView as JoinView > ::JoinTuple > ( & mut conn )
@ -213,9 +214,9 @@ impl CommentReportQuery {
pub async fn list (
self ,
pool : & mut DbPool < ' _ > ,
my_person: & Person ,
user: & LocalUserView ,
) -> Result < Vec < CommentReportView > , Error > {
queries ( ) . list ( pool , ( self , my_person ) ) . await
queries ( ) . list ( pool , ( self , user ) ) . await
}
}
@ -254,7 +255,10 @@ mod tests {
#![ allow(clippy::unwrap_used) ]
#![ allow(clippy::indexing_slicing) ]
use crate ::comment_report_view ::{ CommentReportQuery , CommentReportView } ;
use crate ::{
comment_report_view ::{ CommentReportQuery , CommentReportView } ,
structs ::LocalUserView ,
} ;
use lemmy_db_schema ::{
aggregates ::structs ::CommentAggregates ,
source ::{
@ -262,6 +266,7 @@ mod tests {
comment_report ::{ CommentReport , CommentReportForm } ,
community ::{ Community , CommunityInsertForm , CommunityModerator , CommunityModeratorForm } ,
instance ::Instance ,
local_user ::{ LocalUser , LocalUserInsertForm } ,
person ::{ Person , PersonInsertForm } ,
post ::{ Post , PostInsertForm } ,
} ,
@ -288,6 +293,17 @@ mod tests {
let inserted_timmy = Person ::create ( pool , & new_person ) . await . unwrap ( ) ;
let new_local_user = LocalUserInsertForm ::builder ( )
. person_id ( inserted_timmy . id )
. password_encrypted ( "123" . to_string ( ) )
. build ( ) ;
let timmy_local_user = LocalUser ::create ( pool , & new_local_user ) . await . unwrap ( ) ;
let timmy_view = LocalUserView {
local_user : timmy_local_user ,
person : inserted_timmy . clone ( ) ,
counts : Default ::default ( ) ,
} ;
let new_person_2 = PersonInsertForm ::builder ( )
. name ( "sara_crv" . into ( ) )
. public_key ( "pubkey" . to_string ( ) )
@ -412,7 +428,6 @@ mod tests {
local : true ,
banned : false ,
deleted : false ,
admin : false ,
bot_account : false ,
bio : None ,
banner : None ,
@ -436,7 +451,6 @@ mod tests {
local : true ,
banned : false ,
deleted : false ,
admin : false ,
bot_account : false ,
bio : None ,
banner : None ,
@ -480,7 +494,6 @@ mod tests {
local : true ,
banned : false ,
deleted : false ,
admin : false ,
bot_account : false ,
bio : None ,
banner : None ,
@ -497,7 +510,7 @@ mod tests {
// Do a batch read of timmys reports
let reports = CommentReportQuery ::default ( )
. list ( pool , & inserted_ timmy)
. list ( pool , & timmy_view )
. await
. unwrap ( ) ;
@ -546,7 +559,6 @@ mod tests {
local : true ,
banned : false ,
deleted : false ,
admin : false ,
bot_account : false ,
bio : None ,
banner : None ,
@ -572,7 +584,7 @@ mod tests {
unresolved_only : ( true ) ,
.. Default ::default ( )
}
. list ( pool , & inserted_ timmy)
. list ( pool , & timmy_view )
. await
. unwrap ( ) ;
assert_eq! ( reports_after_resolve [ 0 ] , expected_sara_report_view ) ;