mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-10 02:05:10 +00:00
* Fixing removed posts showing. Fixes #2875 * Fixing clippy.
This commit is contained in:
parent
39572e1c3e
commit
dce79b83bf
|
@ -147,10 +147,12 @@ impl PostView {
|
|||
.into_boxed();
|
||||
|
||||
// Hide deleted and removed for non-admins or mods
|
||||
if !is_mod_or_admin.unwrap_or(true) {
|
||||
if !is_mod_or_admin.unwrap_or(false) {
|
||||
query = query
|
||||
.filter(community::removed.eq(false))
|
||||
.filter(community::deleted.eq(false));
|
||||
.filter(community::deleted.eq(false))
|
||||
.filter(post::removed.eq(false))
|
||||
.filter(post::deleted.eq(false));
|
||||
}
|
||||
|
||||
let (
|
||||
|
@ -305,10 +307,12 @@ impl<'a> PostQuery<'a> {
|
|||
|
||||
// Hide deleted and removed for non-admins or mods
|
||||
// TODO This eventually needs to show posts where you are the creator
|
||||
if !self.is_mod_or_admin.unwrap_or(true) {
|
||||
if !self.is_mod_or_admin.unwrap_or(false) {
|
||||
query = query
|
||||
.filter(community::removed.eq(false))
|
||||
.filter(community::deleted.eq(false));
|
||||
.filter(community::deleted.eq(false))
|
||||
.filter(post::removed.eq(false))
|
||||
.filter(post::deleted.eq(false));
|
||||
}
|
||||
|
||||
if self.community_id.is_none() {
|
||||
|
@ -475,7 +479,7 @@ mod tests {
|
|||
local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm},
|
||||
person::{Person, PersonInsertForm},
|
||||
person_block::{PersonBlock, PersonBlockForm},
|
||||
post::{Post, PostInsertForm, PostLike, PostLikeForm},
|
||||
post::{Post, PostInsertForm, PostLike, PostLikeForm, PostUpdateForm},
|
||||
},
|
||||
traits::{Blockable, Crud, Likeable},
|
||||
utils::{build_db_pool_for_tests, DbPool},
|
||||
|
@ -870,6 +874,50 @@ mod tests {
|
|||
cleanup(data, pool).await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn post_listings_deleted() {
|
||||
let pool = &build_db_pool_for_tests().await;
|
||||
let data = init_data(pool).await;
|
||||
|
||||
// Delete the post
|
||||
Post::update(
|
||||
pool,
|
||||
data.inserted_post.id,
|
||||
&PostUpdateForm::builder().deleted(Some(true)).build(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Make sure you don't see the deleted post in the results
|
||||
let post_listings_no_admin = PostQuery::builder()
|
||||
.pool(pool)
|
||||
.sort(Some(SortType::New))
|
||||
.local_user(Some(&data.inserted_local_user))
|
||||
.is_mod_or_admin(Some(false))
|
||||
.build()
|
||||
.list()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(1, post_listings_no_admin.len());
|
||||
|
||||
// Make sure they see both
|
||||
let post_listings_is_admin = PostQuery::builder()
|
||||
.pool(pool)
|
||||
.sort(Some(SortType::New))
|
||||
.local_user(Some(&data.inserted_local_user))
|
||||
.is_mod_or_admin(Some(true))
|
||||
.build()
|
||||
.list()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(2, post_listings_is_admin.len());
|
||||
|
||||
cleanup(data, pool).await;
|
||||
}
|
||||
|
||||
async fn cleanup(data: Data, pool: &DbPool) {
|
||||
let num_deleted = Post::delete(pool, data.inserted_post.id).await.unwrap();
|
||||
Community::delete(pool, data.inserted_community.id)
|
||||
|
|
|
@ -69,7 +69,7 @@ impl CommunityView {
|
|||
.into_boxed();
|
||||
|
||||
// Hide deleted and removed for non-admins or mods
|
||||
if !is_mod_or_admin.unwrap_or(true) {
|
||||
if !is_mod_or_admin.unwrap_or(false) {
|
||||
query = query
|
||||
.filter(community::removed.eq(false))
|
||||
.filter(community::deleted.eq(false));
|
||||
|
@ -170,7 +170,7 @@ impl<'a> CommunityQuery<'a> {
|
|||
};
|
||||
|
||||
// Hide deleted and removed for non-admins or mods
|
||||
if !self.is_mod_or_admin.unwrap_or(true) {
|
||||
if !self.is_mod_or_admin.unwrap_or(false) {
|
||||
query = query
|
||||
.filter(community::removed.eq(false))
|
||||
.filter(community::deleted.eq(false))
|
||||
|
@ -213,8 +213,6 @@ impl<'a> CommunityQuery<'a> {
|
|||
let res = query
|
||||
.limit(limit)
|
||||
.offset(offset)
|
||||
.filter(community::removed.eq(false))
|
||||
.filter(community::deleted.eq(false))
|
||||
.load::<CommunityViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
|
|
Loading…
Reference in a new issue