Dont blank out post or community info. Fixes #1813

dont_blank_out_info
Dessalines 2021-10-14 12:04:27 -04:00
parent f4bac6a17f
commit f09ab9e384
8 changed files with 25 additions and 84 deletions

View File

@ -22,6 +22,7 @@ use lemmy_apub::{
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
impls::community::CommunityModerator_,
source::{ source::{
comment::Comment, comment::Comment,
community::{ community::{

View File

@ -347,20 +347,6 @@ impl Perform for Search {
cv.comment = cv.to_owned().comment.blank_out_deleted_or_removed_info(); cv.comment = cv.to_owned().comment.blank_out_deleted_or_removed_info();
} }
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();
}
// Return the jwt // Return the jwt
Ok(SearchResponse { Ok(SearchResponse {
type_: search_type.to_string(), type_: search_type.to_string(),

View File

@ -7,12 +7,7 @@ use lemmy_apub::{
objects::community::ApubCommunity, objects::community::ApubCommunity,
EndpointType, EndpointType,
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{from_opt_str_to_opt_enum, ListingType, SortType};
from_opt_str_to_opt_enum,
traits::DeleteableOrRemoveable,
ListingType,
SortType,
};
use lemmy_db_views_actor::{ use lemmy_db_views_actor::{
community_moderator_view::CommunityModeratorView, community_moderator_view::CommunityModeratorView,
community_view::{CommunityQueryBuilder, CommunityView}, community_view::{CommunityQueryBuilder, CommunityView},
@ -49,17 +44,12 @@ impl PerformCrud for GetCommunity {
} }
}; };
let mut community_view = blocking(context.pool(), move |conn| { let community_view = blocking(context.pool(), move |conn| {
CommunityView::read(conn, community_id, person_id) CommunityView::read(conn, community_id, person_id)
}) })
.await? .await?
.map_err(|e| ApiError::err("couldnt_find_community", e))?; .map_err(|e| ApiError::err("couldnt_find_community", e))?;
// 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: Vec<CommunityModeratorView> = blocking(context.pool(), move |conn| { let moderators: Vec<CommunityModeratorView> = blocking(context.pool(), move |conn| {
CommunityModeratorView::for_community(conn, community_id) CommunityModeratorView::for_community(conn, community_id)
}) })
@ -109,7 +99,7 @@ impl PerformCrud for ListCommunities {
let page = data.page; let page = data.page;
let limit = data.limit; let limit = data.limit;
let mut communities = blocking(context.pool(), move |conn| { let communities = blocking(context.pool(), move |conn| {
CommunityQueryBuilder::create(conn) CommunityQueryBuilder::create(conn)
.listing_type(listing_type) .listing_type(listing_type)
.sort(sort) .sort(sort)
@ -121,14 +111,6 @@ impl PerformCrud for ListCommunities {
}) })
.await??; .await??;
// Blank out deleted or removed info
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 // Return the jwt
Ok(ListCommunitiesResponse { communities }) Ok(ListCommunitiesResponse { communities })
} }

View File

@ -38,17 +38,12 @@ impl PerformCrud for GetPost {
let person_id = local_user_view.map(|u| u.person.id); let person_id = local_user_view.map(|u| u.person.id);
let id = data.id; let id = data.id;
let mut post_view = blocking(context.pool(), move |conn| { let post_view = blocking(context.pool(), move |conn| {
PostView::read(conn, id, person_id) PostView::read(conn, id, person_id)
}) })
.await? .await?
.map_err(|e| ApiError::err("couldnt_find_post", e))?; .map_err(|e| ApiError::err("couldnt_find_post", e))?;
// Blank out deleted info
if post_view.post.deleted || post_view.post.removed {
post_view.post = post_view.post.blank_out_deleted_or_removed_info();
}
// Mark the post as read // Mark the post as read
if let Some(person_id) = person_id { if let Some(person_id) = person_id {
mark_post_as_read(person_id, id, context.pool()).await?; mark_post_as_read(person_id, id, context.pool()).await?;
@ -80,17 +75,12 @@ impl PerformCrud for GetPost {
.await??; .await??;
// Necessary for the sidebar // Necessary for the sidebar
let mut community_view = blocking(context.pool(), move |conn| { let community_view = blocking(context.pool(), move |conn| {
CommunityView::read(conn, community_id, person_id) CommunityView::read(conn, community_id, person_id)
}) })
.await? .await?
.map_err(|e| ApiError::err("couldnt_find_community", e))?; .map_err(|e| ApiError::err("couldnt_find_community", e))?;
// 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 online = context let online = context
.chat_server() .chat_server()
.send(GetPostUsersOnline { post_id: data.id }) .send(GetPostUsersOnline { post_id: data.id })
@ -144,7 +134,7 @@ impl PerformCrud for GetPosts {
.unwrap_or(None); .unwrap_or(None);
let saved_only = data.saved_only; let saved_only = data.saved_only;
let mut posts = blocking(context.pool(), move |conn| { let posts = blocking(context.pool(), move |conn| {
PostQueryBuilder::create(conn) PostQueryBuilder::create(conn)
.listing_type(listing_type) .listing_type(listing_type)
.sort(sort) .sort(sort)
@ -162,14 +152,6 @@ impl PerformCrud for GetPosts {
.await? .await?
.map_err(|e| ApiError::err("couldnt_get_posts", e))?; .map_err(|e| ApiError::err("couldnt_get_posts", e))?;
// 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();
}
Ok(GetPostsResponse { posts }) Ok(GetPostsResponse { posts })
} }
} }

View File

@ -25,6 +25,7 @@ use lemmy_apub_lib::{
values::PublicUrl, values::PublicUrl,
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
impls::community::CommunityModerator_,
source::community::{CommunityModerator, CommunityModeratorForm}, source::community::{CommunityModerator, CommunityModeratorForm},
traits::Joinable, traits::Joinable,
}; };

View File

@ -204,8 +204,19 @@ impl DeleteableOrRemoveable for Community {
} }
} }
impl CommunityModerator { pub trait CommunityModerator_ {
pub fn delete_for_community( fn delete_for_community(
conn: &PgConnection,
for_community_id: CommunityId,
) -> Result<usize, Error>;
fn get_person_moderated_communities(
conn: &PgConnection,
for_person_id: PersonId,
) -> Result<Vec<CommunityId>, Error>;
}
impl CommunityModerator_ for CommunityModerator {
fn delete_for_community(
conn: &PgConnection, conn: &PgConnection,
for_community_id: CommunityId, for_community_id: CommunityId,
) -> Result<usize, Error> { ) -> Result<usize, Error> {
@ -213,7 +224,7 @@ impl CommunityModerator {
diesel::delete(community_moderator.filter(community_id.eq(for_community_id))).execute(conn) diesel::delete(community_moderator.filter(community_id.eq(for_community_id))).execute(conn)
} }
pub fn get_person_moderated_communities( fn get_person_moderated_communities(
conn: &PgConnection, conn: &PgConnection,
for_person_id: PersonId, for_person_id: PersonId,
) -> Result<Vec<CommunityId>, Error> { ) -> Result<Vec<CommunityId>, Error> {

View File

@ -11,7 +11,7 @@ use crate::{
PostSaved, PostSaved,
PostSavedForm, PostSavedForm,
}, },
traits::{Crud, DeleteableOrRemoveable, Likeable, Readable, Saveable}, traits::{Crud, Likeable, Readable, Saveable},
}; };
use diesel::{dsl::*, result::Error, ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl}; use diesel::{dsl::*, result::Error, ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
use url::Url; use url::Url;
@ -242,20 +242,6 @@ 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)] #[cfg(test)]
mod tests { mod tests {
use crate::{ use crate::{

View File

@ -43,15 +43,11 @@ pub async fn send_post_ws_message<OP: ToString + Send + OperationType + 'static>
person_id: Option<PersonId>, person_id: Option<PersonId>,
context: &LemmyContext, context: &LemmyContext,
) -> Result<PostResponse, LemmyError> { ) -> Result<PostResponse, LemmyError> {
let mut post_view = blocking(context.pool(), move |conn| { let post_view = blocking(context.pool(), move |conn| {
PostView::read(conn, post_id, person_id) PostView::read(conn, post_id, person_id)
}) })
.await??; .await??;
if post_view.post.deleted || post_view.post.removed {
post_view.post = post_view.post.blank_out_deleted_or_removed_info();
}
let res = PostResponse { post_view }; let res = PostResponse { post_view };
context.chat_server().do_send(SendPost { context.chat_server().do_send(SendPost {
@ -118,14 +114,10 @@ pub async fn send_community_ws_message<OP: ToString + Send + OperationType + 'st
person_id: Option<PersonId>, person_id: Option<PersonId>,
context: &LemmyContext, context: &LemmyContext,
) -> Result<CommunityResponse, LemmyError> { ) -> Result<CommunityResponse, LemmyError> {
let mut community_view = blocking(context.pool(), move |conn| { let community_view = blocking(context.pool(), move |conn| {
CommunityView::read(conn, community_id, person_id) CommunityView::read(conn, community_id, person_id)
}) })
.await??; .await??;
// 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 res = CommunityResponse { community_view }; let res = CommunityResponse { community_view };