Only blank out info for non-logged in users.

dont_blank_out_info
Dessalines 2021-10-20 11:42:36 -04:00
parent fba3d9b8df
commit a73e387ead
4 changed files with 97 additions and 27 deletions

View File

@ -339,12 +339,28 @@ impl Perform for Search {
}
};
// Blank out deleted or removed info
for cv in comments
.iter_mut()
.filter(|cv| cv.comment.deleted || cv.comment.removed)
{
cv.comment = cv.to_owned().comment.blank_out_deleted_or_removed_info();
// Blank out deleted or removed info for non logged in users
if person_id.is_none() {
for cv in communities
.iter_mut()
.filter(|cv| cv.community.deleted || cv.community.removed)
{
cv.community = cv.to_owned().community.blank_out_deleted_or_removed_info();
}
for pv in posts
.iter_mut()
.filter(|p| p.post.deleted || p.post.removed)
{
pv.post = pv.to_owned().post.blank_out_deleted_or_removed_info();
}
for cv in comments
.iter_mut()
.filter(|cv| cv.comment.deleted || cv.comment.removed)
{
cv.comment = cv.to_owned().comment.blank_out_deleted_or_removed_info();
}
}
// Return the jwt

View File

@ -7,7 +7,12 @@ use lemmy_apub::{
objects::community::ApubCommunity,
EndpointType,
};
use lemmy_db_schema::{from_opt_str_to_opt_enum, ListingType, SortType};
use lemmy_db_schema::{
from_opt_str_to_opt_enum,
traits::DeleteableOrRemoveable,
ListingType,
SortType,
};
use lemmy_db_views_actor::{
community_moderator_view::CommunityModeratorView,
community_view::{CommunityQueryBuilder, CommunityView},
@ -44,12 +49,18 @@ impl PerformCrud for GetCommunity {
}
};
let community_view = blocking(context.pool(), move |conn| {
let mut community_view = blocking(context.pool(), move |conn| {
CommunityView::read(conn, community_id, person_id)
})
.await?
.map_err(|e| ApiError::err("couldnt_find_community", e))?;
// Blank out deleted or removed info for non-logged in users
if person_id.is_none() && (community_view.community.deleted || community_view.community.removed)
{
community_view.community = community_view.community.blank_out_deleted_or_removed_info();
}
let moderators: Vec<CommunityModeratorView> = blocking(context.pool(), move |conn| {
CommunityModeratorView::for_community(conn, community_id)
})
@ -99,7 +110,7 @@ impl PerformCrud for ListCommunities {
let page = data.page;
let limit = data.limit;
let communities = blocking(context.pool(), move |conn| {
let mut communities = blocking(context.pool(), move |conn| {
CommunityQueryBuilder::create(conn)
.listing_type(listing_type)
.sort(sort)
@ -111,6 +122,16 @@ impl PerformCrud for ListCommunities {
})
.await??;
// Blank out deleted or removed info for non-logged in users
if person_id.is_none() {
for cv in communities
.iter_mut()
.filter(|cv| cv.community.deleted || cv.community.removed)
{
cv.community = cv.to_owned().community.blank_out_deleted_or_removed_info();
}
}
// Return the jwt
Ok(ListCommunitiesResponse { communities })
}

View File

@ -38,7 +38,7 @@ impl PerformCrud for GetPost {
let person_id = local_user_view.map(|u| u.person.id);
let id = data.id;
let post_view = blocking(context.pool(), move |conn| {
let mut post_view = blocking(context.pool(), move |conn| {
PostView::read(conn, id, person_id)
})
.await?
@ -60,27 +60,36 @@ impl PerformCrud for GetPost {
})
.await??;
// Blank out deleted or removed info
for cv in comments
.iter_mut()
.filter(|cv| cv.comment.deleted || cv.comment.removed)
{
cv.comment = cv.to_owned().comment.blank_out_deleted_or_removed_info();
}
let community_id = post_view.community.id;
let moderators = blocking(context.pool(), move |conn| {
CommunityModeratorView::for_community(conn, community_id)
})
.await??;
// Necessary for the sidebar
let community_view = blocking(context.pool(), move |conn| {
let community_id = post_view.community.id;
let mut community_view = blocking(context.pool(), move |conn| {
CommunityView::read(conn, community_id, person_id)
})
.await?
.map_err(|e| ApiError::err("couldnt_find_community", e))?;
// Blank out deleted or removed info for non-logged in users
if person_id.is_none() {
if post_view.post.deleted || post_view.post.removed {
post_view.post = post_view.post.blank_out_deleted_or_removed_info();
}
for cv in comments
.iter_mut()
.filter(|cv| cv.comment.deleted || cv.comment.removed)
{
cv.comment = cv.to_owned().comment.blank_out_deleted_or_removed_info();
}
if community_view.community.deleted || community_view.community.removed {
community_view.community = community_view.community.blank_out_deleted_or_removed_info();
}
}
let moderators = blocking(context.pool(), move |conn| {
CommunityModeratorView::for_community(conn, community_id)
})
.await??;
let online = context
.chat_server()
.send(GetPostUsersOnline { post_id: data.id })
@ -134,7 +143,7 @@ impl PerformCrud for GetPosts {
.unwrap_or(None);
let saved_only = data.saved_only;
let posts = blocking(context.pool(), move |conn| {
let mut posts = blocking(context.pool(), move |conn| {
PostQueryBuilder::create(conn)
.listing_type(listing_type)
.sort(sort)
@ -152,6 +161,16 @@ impl PerformCrud for GetPosts {
.await?
.map_err(|e| ApiError::err("couldnt_get_posts", e))?;
// Blank out deleted or removed info for non-logged in users
if person_id.is_none() {
for pv in posts
.iter_mut()
.filter(|p| p.post.deleted || p.post.removed)
{
pv.post = pv.to_owned().post.blank_out_deleted_or_removed_info();
}
}
Ok(GetPostsResponse { posts })
}
}

View File

@ -11,7 +11,7 @@ use crate::{
PostSaved,
PostSavedForm,
},
traits::{Crud, Likeable, Readable, Saveable},
traits::{Crud, DeleteableOrRemoveable, Likeable, Readable, Saveable},
};
use diesel::{dsl::*, result::Error, ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
use url::Url;
@ -242,6 +242,20 @@ impl Readable for PostRead {
}
}
impl DeleteableOrRemoveable for Post {
fn blank_out_deleted_or_removed_info(mut self) -> Self {
self.name = "".into();
self.url = None;
self.body = None;
self.embed_title = None;
self.embed_description = None;
self.embed_html = None;
self.thumbnail_url = None;
self
}
}
#[cfg(test)]
mod tests {
use crate::{