Blank out extra info for deleted or removed content. Fixes #1679 (#1680)

This commit is contained in:
Dessalines 2021-07-30 14:44:15 -04:00 committed by GitHub
parent 6ffa291ec9
commit d85f0d087e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 252 additions and 37 deletions

View file

@ -115,6 +115,7 @@ test('Delete a comment', async () => {
commentRes.comment_view.comment.id commentRes.comment_view.comment.id
); );
expect(deleteCommentRes.comment_view.comment.deleted).toBe(true); expect(deleteCommentRes.comment_view.comment.deleted).toBe(true);
expect(deleteCommentRes.comment_view.comment.content).toBe("");
// Make sure that comment is undefined on beta // Make sure that comment is undefined on beta
let searchBeta = await searchComment(beta, commentRes.comment_view.comment); let searchBeta = await searchComment(beta, commentRes.comment_view.comment);
@ -149,6 +150,7 @@ test('Remove a comment from admin and community on the same instance', async ()
// The beta admin removes it (the community lives on beta) // The beta admin removes it (the community lives on beta)
let removeCommentRes = await removeComment(beta, true, betaCommentId); let removeCommentRes = await removeComment(beta, true, betaCommentId);
expect(removeCommentRes.comment_view.comment.removed).toBe(true); expect(removeCommentRes.comment_view.comment.removed).toBe(true);
expect(removeCommentRes.comment_view.comment.content).toBe("");
// Make sure that comment is removed on alpha (it gets pushed since an admin from beta removed it) // Make sure that comment is removed on alpha (it gets pushed since an admin from beta removed it)
let refetchedPost = await getPost(alpha, postRes.post_view.post.id); let refetchedPost = await getPost(alpha, postRes.post_view.post.id);

View file

@ -77,6 +77,7 @@ test('Delete community', async () => {
communityRes.community_view.community.id communityRes.community_view.community.id
); );
expect(deleteCommunityRes.community_view.community.deleted).toBe(true); expect(deleteCommunityRes.community_view.community.deleted).toBe(true);
expect(deleteCommunityRes.community_view.community.title).toBe("");
// Make sure it got deleted on A // Make sure it got deleted on A
let communityOnAlphaDeleted = await getCommunity( let communityOnAlphaDeleted = await getCommunity(
@ -128,6 +129,7 @@ test('Remove community', async () => {
communityRes.community_view.community.id communityRes.community_view.community.id
); );
expect(removeCommunityRes.community_view.community.removed).toBe(true); expect(removeCommunityRes.community_view.community.removed).toBe(true);
expect(removeCommunityRes.community_view.community.title).toBe("");
// Make sure it got Removed on A // Make sure it got Removed on A
let communityOnAlphaRemoved = await getCommunity( let communityOnAlphaRemoved = await getCommunity(

View file

@ -210,6 +210,7 @@ test('Delete a post', async () => {
let deletedPost = await deletePost(alpha, true, postRes.post_view.post); let deletedPost = await deletePost(alpha, true, postRes.post_view.post);
expect(deletedPost.post_view.post.deleted).toBe(true); expect(deletedPost.post_view.post.deleted).toBe(true);
expect(deletedPost.post_view.post.name).toBe("");
// Make sure lemmy beta sees post is deleted // Make sure lemmy beta sees post is deleted
let searchBeta = await searchPost(beta, postRes.post_view.post); let searchBeta = await searchPost(beta, postRes.post_view.post);
@ -237,6 +238,7 @@ test('Remove a post from admin and community on different instance', async () =>
let removedPost = await removePost(alpha, true, postRes.post_view.post); let removedPost = await removePost(alpha, true, postRes.post_view.post);
expect(removedPost.post_view.post.removed).toBe(true); expect(removedPost.post_view.post.removed).toBe(true);
expect(removedPost.post_view.post.name).toBe("");
// Make sure lemmy beta sees post is NOT removed // Make sure lemmy beta sees post is NOT removed
let searchBeta = await searchPost(beta, postRes.post_view.post); let searchBeta = await searchPost(beta, postRes.post_view.post);

View file

@ -64,6 +64,7 @@ test('Delete a private message', async () => {
pmRes.private_message_view.private_message.id pmRes.private_message_view.private_message.id
); );
expect(deletedPmRes.private_message_view.private_message.deleted).toBe(true); expect(deletedPmRes.private_message_view.private_message.deleted).toBe(true);
expect(deletedPmRes.private_message_view.private_message.content).toBe("");
// The GetPrivateMessages filters out deleted, // The GetPrivateMessages filters out deleted,
// even though they are in the actual database. // even though they are in the actual database.

View file

@ -15,6 +15,7 @@ use lemmy_db_queries::{
from_opt_str_to_opt_enum, from_opt_str_to_opt_enum,
source::site::Site_, source::site::Site_,
Crud, Crud,
DeleteableOrRemoveable,
ListingType, ListingType,
SearchType, SearchType,
SortType, SortType,
@ -332,6 +333,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();
}
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

@ -9,7 +9,7 @@ use lemmy_api_common::{
send_local_notifs, send_local_notifs,
}; };
use lemmy_apub::ApubObjectType; use lemmy_apub::ApubObjectType;
use lemmy_db_queries::{source::comment::Comment_, Crud}; use lemmy_db_queries::{source::comment::Comment_, Crud, DeleteableOrRemoveable};
use lemmy_db_schema::source::{comment::*, moderator::*}; use lemmy_db_schema::source::{comment::*, moderator::*};
use lemmy_db_views::comment_view::CommentView; use lemmy_db_views::comment_view::CommentView;
use lemmy_utils::{ApiError, ConnectionId, LemmyError}; use lemmy_utils::{ApiError, ConnectionId, LemmyError};
@ -47,7 +47,7 @@ impl PerformCrud for DeleteComment {
// Do the delete // Do the delete
let deleted = data.deleted; let deleted = data.deleted;
let updated_comment = blocking(context.pool(), move |conn| { let mut updated_comment = blocking(context.pool(), move |conn| {
Comment::update_deleted(conn, comment_id, deleted) Comment::update_deleted(conn, comment_id, deleted)
}) })
.await? .await?
@ -55,6 +55,7 @@ impl PerformCrud for DeleteComment {
// Send the apub message // Send the apub message
if deleted { if deleted {
updated_comment = updated_comment.blank_out_deleted_or_removed_info();
updated_comment updated_comment
.send_delete(&local_user_view.person, context) .send_delete(&local_user_view.person, context)
.await?; .await?;
@ -67,11 +68,16 @@ impl PerformCrud for DeleteComment {
// Refetch it // Refetch it
let comment_id = data.comment_id; let comment_id = data.comment_id;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let comment_view = blocking(context.pool(), move |conn| { let mut comment_view = blocking(context.pool(), move |conn| {
CommentView::read(conn, comment_id, Some(person_id)) CommentView::read(conn, comment_id, Some(person_id))
}) })
.await??; .await??;
// Blank out deleted or removed info
if deleted {
comment_view.comment = comment_view.comment.blank_out_deleted_or_removed_info();
}
// Build the recipients // Build the recipients
let comment_view_2 = comment_view.clone(); let comment_view_2 = comment_view.clone();
let mentions = vec![]; let mentions = vec![];
@ -136,7 +142,7 @@ impl PerformCrud for RemoveComment {
// Do the remove // Do the remove
let removed = data.removed; let removed = data.removed;
let updated_comment = blocking(context.pool(), move |conn| { let mut updated_comment = blocking(context.pool(), move |conn| {
Comment::update_removed(conn, comment_id, removed) Comment::update_removed(conn, comment_id, removed)
}) })
.await? .await?
@ -156,6 +162,7 @@ impl PerformCrud for RemoveComment {
// Send the apub message // Send the apub message
if removed { if removed {
updated_comment = updated_comment.blank_out_deleted_or_removed_info();
updated_comment updated_comment
.send_remove(&local_user_view.person, context) .send_remove(&local_user_view.person, context)
.await?; .await?;
@ -168,11 +175,16 @@ impl PerformCrud for RemoveComment {
// Refetch it // Refetch it
let comment_id = data.comment_id; let comment_id = data.comment_id;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let comment_view = blocking(context.pool(), move |conn| { let mut comment_view = blocking(context.pool(), move |conn| {
CommentView::read(conn, comment_id, Some(person_id)) CommentView::read(conn, comment_id, Some(person_id))
}) })
.await??; .await??;
// Blank out deleted or removed info
if removed {
comment_view.comment = comment_view.comment.blank_out_deleted_or_removed_info();
}
// Build the recipients // Build the recipients
let comment_view_2 = comment_view.clone(); let comment_view_2 = comment_view.clone();

View file

@ -2,7 +2,7 @@ use crate::PerformCrud;
use actix_web::web::Data; use actix_web::web::Data;
use lemmy_api_common::{blocking, comment::*, get_local_user_view_from_jwt_opt}; use lemmy_api_common::{blocking, comment::*, get_local_user_view_from_jwt_opt};
use lemmy_apub::{build_actor_id_from_shortname, EndpointType}; use lemmy_apub::{build_actor_id_from_shortname, EndpointType};
use lemmy_db_queries::{from_opt_str_to_opt_enum, ListingType, SortType}; use lemmy_db_queries::{from_opt_str_to_opt_enum, DeleteableOrRemoveable, ListingType, SortType};
use lemmy_db_views::comment_view::CommentQueryBuilder; use lemmy_db_views::comment_view::CommentQueryBuilder;
use lemmy_utils::{ApiError, ConnectionId, LemmyError}; use lemmy_utils::{ApiError, ConnectionId, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
@ -36,7 +36,7 @@ impl PerformCrud for GetComments {
let saved_only = data.saved_only; let saved_only = data.saved_only;
let page = data.page; let page = data.page;
let limit = data.limit; let limit = data.limit;
let comments = blocking(context.pool(), move |conn| { let mut comments = blocking(context.pool(), move |conn| {
CommentQueryBuilder::create(conn) CommentQueryBuilder::create(conn)
.listing_type(listing_type) .listing_type(listing_type)
.sort(sort) .sort(sort)
@ -52,6 +52,14 @@ impl PerformCrud for GetComments {
.await? .await?
.map_err(|_| ApiError::err("couldnt_get_comments"))?; .map_err(|_| ApiError::err("couldnt_get_comments"))?;
// 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();
}
Ok(GetCommentsResponse { comments }) Ok(GetCommentsResponse { comments })
} }
} }

View file

@ -8,7 +8,7 @@ use lemmy_api_common::{
send_local_notifs, send_local_notifs,
}; };
use lemmy_apub::ApubObjectType; use lemmy_apub::ApubObjectType;
use lemmy_db_queries::source::comment::Comment_; use lemmy_db_queries::{source::comment::Comment_, DeleteableOrRemoveable};
use lemmy_db_schema::source::comment::*; use lemmy_db_schema::source::comment::*;
use lemmy_db_views::comment_view::CommentView; use lemmy_db_views::comment_view::CommentView;
use lemmy_utils::{ use lemmy_utils::{
@ -78,11 +78,16 @@ impl PerformCrud for EditComment {
let comment_id = data.comment_id; let comment_id = data.comment_id;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let comment_view = blocking(context.pool(), move |conn| { let mut comment_view = blocking(context.pool(), move |conn| {
CommentView::read(conn, comment_id, Some(person_id)) CommentView::read(conn, comment_id, Some(person_id))
}) })
.await??; .await??;
// Blank out deleted or removed info
if comment_view.comment.deleted || comment_view.comment.removed {
comment_view.comment = comment_view.comment.blank_out_deleted_or_removed_info();
}
let res = CommentResponse { let res = CommentResponse {
comment_view, comment_view,
recipient_ids, recipient_ids,

View file

@ -2,7 +2,7 @@ use crate::{community::send_community_websocket, PerformCrud};
use actix_web::web::Data; use actix_web::web::Data;
use lemmy_api_common::{blocking, community::*, get_local_user_view_from_jwt, is_admin}; use lemmy_api_common::{blocking, community::*, get_local_user_view_from_jwt, is_admin};
use lemmy_apub::CommunityType; use lemmy_apub::CommunityType;
use lemmy_db_queries::{source::community::Community_, Crud}; use lemmy_db_queries::{source::community::Community_, Crud, DeleteableOrRemoveable};
use lemmy_db_schema::source::{ use lemmy_db_schema::source::{
community::*, community::*,
moderator::{ModRemoveCommunity, ModRemoveCommunityForm}, moderator::{ModRemoveCommunity, ModRemoveCommunityForm},
@ -50,6 +50,7 @@ impl PerformCrud for DeleteCommunity {
// Send apub messages // Send apub messages
if deleted { if deleted {
updated_community updated_community
.blank_out_deleted_or_removed_info()
.send_delete(local_user_view.person.to_owned(), context) .send_delete(local_user_view.person.to_owned(), context)
.await?; .await?;
} else { } else {
@ -60,11 +61,16 @@ impl PerformCrud for DeleteCommunity {
let community_id = data.community_id; let community_id = data.community_id;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let community_view = blocking(context.pool(), move |conn| { let mut community_view = blocking(context.pool(), move |conn| {
CommunityView::read(conn, community_id, Some(person_id)) CommunityView::read(conn, community_id, Some(person_id))
}) })
.await??; .await??;
// Blank out deleted or removed info
if deleted {
community_view.community = community_view.community.blank_out_deleted_or_removed_info();
}
let res = CommunityResponse { community_view }; let res = CommunityResponse { community_view };
send_community_websocket( send_community_websocket(
@ -118,18 +124,26 @@ impl PerformCrud for RemoveCommunity {
// Apub messages // Apub messages
if removed { if removed {
updated_community.send_remove(context).await?; updated_community
.blank_out_deleted_or_removed_info()
.send_remove(context)
.await?;
} else { } else {
updated_community.send_undo_remove(context).await?; updated_community.send_undo_remove(context).await?;
} }
let community_id = data.community_id; let community_id = data.community_id;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let community_view = blocking(context.pool(), move |conn| { let mut community_view = blocking(context.pool(), move |conn| {
CommunityView::read(conn, community_id, Some(person_id)) CommunityView::read(conn, community_id, Some(person_id))
}) })
.await??; .await??;
// Blank out deleted or removed info
if removed {
community_view.community = community_view.community.blank_out_deleted_or_removed_info();
}
let res = CommunityResponse { community_view }; let res = CommunityResponse { community_view };
send_community_websocket( send_community_websocket(

View file

@ -2,7 +2,13 @@ use crate::PerformCrud;
use actix_web::web::Data; use actix_web::web::Data;
use lemmy_api_common::{blocking, community::*, get_local_user_view_from_jwt_opt}; use lemmy_api_common::{blocking, community::*, get_local_user_view_from_jwt_opt};
use lemmy_apub::{build_actor_id_from_shortname, EndpointType}; use lemmy_apub::{build_actor_id_from_shortname, EndpointType};
use lemmy_db_queries::{from_opt_str_to_opt_enum, ApubObject, ListingType, SortType}; use lemmy_db_queries::{
from_opt_str_to_opt_enum,
ApubObject,
DeleteableOrRemoveable,
ListingType,
SortType,
};
use lemmy_db_schema::source::community::*; use lemmy_db_schema::source::community::*;
use lemmy_db_views_actor::{ use lemmy_db_views_actor::{
community_moderator_view::CommunityModeratorView, community_moderator_view::CommunityModeratorView,
@ -39,12 +45,17 @@ 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) CommunityView::read(conn, community_id, person_id)
}) })
.await? .await?
.map_err(|_| ApiError::err("couldnt_find_community"))?; .map_err(|_| ApiError::err("couldnt_find_community"))?;
// 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)
}) })
@ -93,7 +104,7 @@ impl PerformCrud for ListCommunities {
let page = data.page; let page = data.page;
let limit = data.limit; let limit = data.limit;
let communities = blocking(context.pool(), move |conn| { let mut communities = blocking(context.pool(), move |conn| {
CommunityQueryBuilder::create(conn) CommunityQueryBuilder::create(conn)
.listing_type(listing_type) .listing_type(listing_type)
.sort(sort) .sort(sort)
@ -105,6 +116,14 @@ 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

@ -6,7 +6,7 @@ use lemmy_api_common::{
get_local_user_view_from_jwt, get_local_user_view_from_jwt,
}; };
use lemmy_apub::CommunityType; use lemmy_apub::CommunityType;
use lemmy_db_queries::{diesel_option_overwrite_to_url, Crud}; use lemmy_db_queries::{diesel_option_overwrite_to_url, Crud, DeleteableOrRemoveable};
use lemmy_db_schema::{ use lemmy_db_schema::{
naive_now, naive_now,
source::community::{Community, CommunityForm}, source::community::{Community, CommunityForm},
@ -78,11 +78,16 @@ impl PerformCrud for EditCommunity {
let community_id = data.community_id; let community_id = data.community_id;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let community_view = blocking(context.pool(), move |conn| { let mut community_view = blocking(context.pool(), move |conn| {
CommunityView::read(conn, community_id, Some(person_id)) CommunityView::read(conn, community_id, Some(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 };
send_community_websocket( send_community_websocket(

View file

@ -8,7 +8,7 @@ use lemmy_api_common::{
post::*, post::*,
}; };
use lemmy_apub::ApubObjectType; use lemmy_apub::ApubObjectType;
use lemmy_db_queries::{source::post::Post_, Crud}; use lemmy_db_queries::{source::post::Post_, Crud, DeleteableOrRemoveable};
use lemmy_db_schema::source::{moderator::*, post::*}; use lemmy_db_schema::source::{moderator::*, post::*};
use lemmy_db_views::post_view::PostView; use lemmy_db_views::post_view::PostView;
use lemmy_utils::{ApiError, ConnectionId, LemmyError}; use lemmy_utils::{ApiError, ConnectionId, LemmyError};
@ -52,6 +52,7 @@ impl PerformCrud for DeletePost {
// apub updates // apub updates
if deleted { if deleted {
updated_post updated_post
.blank_out_deleted_or_removed_info()
.send_delete(&local_user_view.person, context) .send_delete(&local_user_view.person, context)
.await?; .await?;
} else { } else {
@ -62,11 +63,15 @@ impl PerformCrud for DeletePost {
// Refetch the post // Refetch the post
let post_id = data.post_id; let post_id = data.post_id;
let post_view = blocking(context.pool(), move |conn| { let mut post_view = blocking(context.pool(), move |conn| {
PostView::read(conn, post_id, Some(local_user_view.person.id)) PostView::read(conn, post_id, Some(local_user_view.person.id))
}) })
.await??; .await??;
if deleted {
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 {
@ -132,6 +137,7 @@ impl PerformCrud for RemovePost {
// apub updates // apub updates
if removed { if removed {
updated_post updated_post
.blank_out_deleted_or_removed_info()
.send_remove(&local_user_view.person, context) .send_remove(&local_user_view.person, context)
.await?; .await?;
} else { } else {
@ -143,11 +149,16 @@ impl PerformCrud for RemovePost {
// Refetch the post // Refetch the post
let post_id = data.post_id; let post_id = data.post_id;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let post_view = blocking(context.pool(), move |conn| { let mut post_view = blocking(context.pool(), move |conn| {
PostView::read(conn, post_id, Some(person_id)) PostView::read(conn, post_id, Some(person_id))
}) })
.await??; .await??;
// Blank out deleted or removed info
if 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 {

View file

@ -2,7 +2,7 @@ use crate::PerformCrud;
use actix_web::web::Data; use actix_web::web::Data;
use lemmy_api_common::{blocking, get_local_user_view_from_jwt_opt, mark_post_as_read, post::*}; use lemmy_api_common::{blocking, get_local_user_view_from_jwt_opt, mark_post_as_read, post::*};
use lemmy_apub::{build_actor_id_from_shortname, EndpointType}; use lemmy_apub::{build_actor_id_from_shortname, EndpointType};
use lemmy_db_queries::{from_opt_str_to_opt_enum, ListingType, SortType}; use lemmy_db_queries::{from_opt_str_to_opt_enum, DeleteableOrRemoveable, ListingType, SortType};
use lemmy_db_views::{ use lemmy_db_views::{
comment_view::CommentQueryBuilder, comment_view::CommentQueryBuilder,
post_view::{PostQueryBuilder, PostView}, post_view::{PostQueryBuilder, PostView},
@ -32,19 +32,24 @@ 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 post_view = blocking(context.pool(), move |conn| { let mut post_view = blocking(context.pool(), move |conn| {
PostView::read(conn, id, person_id) PostView::read(conn, id, person_id)
}) })
.await? .await?
.map_err(|_| ApiError::err("couldnt_find_post"))?; .map_err(|_| ApiError::err("couldnt_find_post"))?;
// 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?;
} }
let id = data.id; let id = data.id;
let comments = blocking(context.pool(), move |conn| { let mut comments = blocking(context.pool(), move |conn| {
CommentQueryBuilder::create(conn) CommentQueryBuilder::create(conn)
.my_person_id(person_id) .my_person_id(person_id)
.show_bot_accounts(show_bot_accounts) .show_bot_accounts(show_bot_accounts)
@ -54,6 +59,14 @@ impl PerformCrud for GetPost {
}) })
.await??; .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 community_id = post_view.community.id;
let moderators = blocking(context.pool(), move |conn| { let moderators = blocking(context.pool(), move |conn| {
CommunityModeratorView::for_community(conn, community_id) CommunityModeratorView::for_community(conn, community_id)
@ -61,12 +74,17 @@ impl PerformCrud for GetPost {
.await??; .await??;
// Necessary for the sidebar // Necessary for the sidebar
let community_view = blocking(context.pool(), move |conn| { let mut 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(|_| ApiError::err("couldnt_find_community"))?; .map_err(|_| ApiError::err("couldnt_find_community"))?;
// 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 })
@ -119,7 +137,7 @@ impl PerformCrud for GetPosts {
.unwrap_or(None); .unwrap_or(None);
let saved_only = data.saved_only; let saved_only = data.saved_only;
let posts = blocking(context.pool(), move |conn| { let mut posts = blocking(context.pool(), move |conn| {
PostQueryBuilder::create(conn) PostQueryBuilder::create(conn)
.listing_type(listing_type) .listing_type(listing_type)
.sort(sort) .sort(sort)
@ -137,6 +155,14 @@ impl PerformCrud for GetPosts {
.await? .await?
.map_err(|_| ApiError::err("couldnt_get_posts"))?; .map_err(|_| ApiError::err("couldnt_get_posts"))?;
// 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

@ -2,7 +2,7 @@ use crate::PerformCrud;
use actix_web::web::Data; use actix_web::web::Data;
use lemmy_api_common::{blocking, check_community_ban, get_local_user_view_from_jwt, post::*}; use lemmy_api_common::{blocking, check_community_ban, get_local_user_view_from_jwt, post::*};
use lemmy_apub::ApubObjectType; use lemmy_apub::ApubObjectType;
use lemmy_db_queries::{source::post::Post_, Crud}; use lemmy_db_queries::{source::post::Post_, Crud, DeleteableOrRemoveable};
use lemmy_db_schema::{naive_now, source::post::*}; use lemmy_db_schema::{naive_now, source::post::*};
use lemmy_db_views::post_view::PostView; use lemmy_db_views::post_view::PostView;
use lemmy_utils::{ use lemmy_utils::{
@ -94,11 +94,16 @@ impl PerformCrud for EditPost {
.await?; .await?;
let post_id = data.post_id; let post_id = data.post_id;
let post_view = blocking(context.pool(), move |conn| { let mut post_view = blocking(context.pool(), move |conn| {
PostView::read(conn, post_id, Some(local_user_view.person.id)) PostView::read(conn, post_id, Some(local_user_view.person.id))
}) })
.await??; .await??;
// 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();
}
let res = PostResponse { post_view }; let res = PostResponse { post_view };
context.chat_server().do_send(SendPost { context.chat_server().do_send(SendPost {

View file

@ -6,7 +6,7 @@ use lemmy_api_common::{
person::{DeletePrivateMessage, PrivateMessageResponse}, person::{DeletePrivateMessage, PrivateMessageResponse},
}; };
use lemmy_apub::ApubObjectType; use lemmy_apub::ApubObjectType;
use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud}; use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud, DeleteableOrRemoveable};
use lemmy_db_schema::source::private_message::PrivateMessage; use lemmy_db_schema::source::private_message::PrivateMessage;
use lemmy_db_views::{local_user_view::LocalUserView, private_message_view::PrivateMessageView}; use lemmy_db_views::{local_user_view::LocalUserView, private_message_view::PrivateMessageView};
use lemmy_utils::{ApiError, ConnectionId, LemmyError}; use lemmy_utils::{ApiError, ConnectionId, LemmyError};
@ -46,6 +46,7 @@ impl PerformCrud for DeletePrivateMessage {
// Send the apub update // Send the apub update
if data.deleted { if data.deleted {
updated_private_message updated_private_message
.blank_out_deleted_or_removed_info()
.send_delete(&local_user_view.person, context) .send_delete(&local_user_view.person, context)
.await?; .await?;
} else { } else {
@ -55,11 +56,18 @@ impl PerformCrud for DeletePrivateMessage {
} }
let private_message_id = data.private_message_id; let private_message_id = data.private_message_id;
let private_message_view = blocking(context.pool(), move |conn| { let mut private_message_view = blocking(context.pool(), move |conn| {
PrivateMessageView::read(conn, private_message_id) PrivateMessageView::read(conn, private_message_id)
}) })
.await??; .await??;
// Blank out deleted or removed info
if deleted {
private_message_view.private_message = private_message_view
.private_message
.blank_out_deleted_or_removed_info();
}
let res = PrivateMessageResponse { let res = PrivateMessageResponse {
private_message_view, private_message_view,
}; };

View file

@ -5,6 +5,7 @@ use lemmy_api_common::{
get_local_user_view_from_jwt, get_local_user_view_from_jwt,
person::{GetPrivateMessages, PrivateMessagesResponse}, person::{GetPrivateMessages, PrivateMessagesResponse},
}; };
use lemmy_db_queries::DeleteableOrRemoveable;
use lemmy_db_views::private_message_view::PrivateMessageQueryBuilder; use lemmy_db_views::private_message_view::PrivateMessageQueryBuilder;
use lemmy_utils::{ConnectionId, LemmyError}; use lemmy_utils::{ConnectionId, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
@ -25,7 +26,7 @@ impl PerformCrud for GetPrivateMessages {
let page = data.page; let page = data.page;
let limit = data.limit; let limit = data.limit;
let unread_only = data.unread_only; let unread_only = data.unread_only;
let messages = blocking(context.pool(), move |conn| { let mut messages = blocking(context.pool(), move |conn| {
PrivateMessageQueryBuilder::create(conn, person_id) PrivateMessageQueryBuilder::create(conn, person_id)
.page(page) .page(page)
.limit(limit) .limit(limit)
@ -34,6 +35,17 @@ impl PerformCrud for GetPrivateMessages {
}) })
.await??; .await??;
// Blank out deleted or removed info
for pmv in messages
.iter_mut()
.filter(|pmv| pmv.private_message.deleted)
{
pmv.private_message = pmv
.to_owned()
.private_message
.blank_out_deleted_or_removed_info();
}
Ok(PrivateMessagesResponse { Ok(PrivateMessagesResponse {
private_messages: messages, private_messages: messages,
}) })

View file

@ -6,7 +6,7 @@ use lemmy_api_common::{
person::{EditPrivateMessage, PrivateMessageResponse}, person::{EditPrivateMessage, PrivateMessageResponse},
}; };
use lemmy_apub::ApubObjectType; use lemmy_apub::ApubObjectType;
use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud}; use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud, DeleteableOrRemoveable};
use lemmy_db_schema::source::private_message::PrivateMessage; use lemmy_db_schema::source::private_message::PrivateMessage;
use lemmy_db_views::{local_user_view::LocalUserView, private_message_view::PrivateMessageView}; use lemmy_db_views::{local_user_view::LocalUserView, private_message_view::PrivateMessageView};
use lemmy_utils::{utils::remove_slurs, ApiError, ConnectionId, LemmyError}; use lemmy_utils::{utils::remove_slurs, ApiError, ConnectionId, LemmyError};
@ -49,11 +49,18 @@ impl PerformCrud for EditPrivateMessage {
.await?; .await?;
let private_message_id = data.private_message_id; let private_message_id = data.private_message_id;
let private_message_view = blocking(context.pool(), move |conn| { let mut private_message_view = blocking(context.pool(), move |conn| {
PrivateMessageView::read(conn, private_message_id) PrivateMessageView::read(conn, private_message_id)
}) })
.await??; .await??;
// Blank out deleted or removed info
if private_message_view.private_message.deleted {
private_message_view.private_message = private_message_view
.private_message
.blank_out_deleted_or_removed_info();
}
let res = PrivateMessageResponse { let res = PrivateMessageResponse {
private_message_view, private_message_view,
}; };

View file

@ -117,6 +117,10 @@ pub trait Reportable<Form> {
Self: Sized; Self: Sized;
} }
pub trait DeleteableOrRemoveable {
fn blank_out_deleted_or_removed_info(self) -> Self;
}
pub trait ApubObject<Form> { pub trait ApubObject<Form> {
fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Self, Error> fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Self, Error>
where where

View file

@ -1,4 +1,4 @@
use crate::{ApubObject, Crud, Likeable, Saveable}; use crate::{ApubObject, Crud, DeleteableOrRemoveable, Likeable, Saveable};
use diesel::{dsl::*, result::Error, *}; use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::{ use lemmy_db_schema::{
naive_now, naive_now,
@ -228,6 +228,13 @@ impl Saveable<CommentSavedForm> for CommentSaved {
} }
} }
impl DeleteableOrRemoveable for Comment {
fn blank_out_deleted_or_removed_info(mut self) -> Self {
self.content = "".into();
self
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{establish_unpooled_connection, Crud, Likeable, Saveable}; use crate::{establish_unpooled_connection, Crud, Likeable, Saveable};

View file

@ -1,4 +1,4 @@
use crate::{ApubObject, Bannable, Crud, Followable, Joinable}; use crate::{ApubObject, Bannable, Crud, DeleteableOrRemoveable, Followable, Joinable};
use diesel::{dsl::*, result::Error, *}; use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::{ use lemmy_db_schema::{
naive_now, naive_now,
@ -11,6 +11,7 @@ use lemmy_db_schema::{
CommunityModeratorForm, CommunityModeratorForm,
CommunityPersonBan, CommunityPersonBan,
CommunityPersonBanForm, CommunityPersonBanForm,
CommunitySafe,
}, },
CommunityId, CommunityId,
DbUrl, DbUrl,
@ -199,6 +200,26 @@ impl Joinable<CommunityModeratorForm> for CommunityModerator {
} }
} }
impl DeleteableOrRemoveable for CommunitySafe {
fn blank_out_deleted_or_removed_info(mut self) -> Self {
self.title = "".into();
self.description = None;
self.icon = None;
self.banner = None;
self
}
}
impl DeleteableOrRemoveable for Community {
fn blank_out_deleted_or_removed_info(mut self) -> Self {
self.title = "".into();
self.description = None;
self.icon = None;
self.banner = None;
self
}
}
pub trait CommunityModerator_ { pub trait CommunityModerator_ {
fn delete_for_community( fn delete_for_community(
conn: &PgConnection, conn: &PgConnection,

View file

@ -1,4 +1,4 @@
use crate::{ApubObject, Crud, Likeable, Readable, Saveable}; use crate::{ApubObject, Crud, DeleteableOrRemoveable, Likeable, Readable, Saveable};
use diesel::{dsl::*, result::Error, *}; use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::{ use lemmy_db_schema::{
naive_now, naive_now,
@ -260,6 +260,20 @@ impl Readable<PostReadForm> 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::{establish_unpooled_connection, source::post::*}; use crate::{establish_unpooled_connection, source::post::*};

View file

@ -1,4 +1,4 @@
use crate::{ApubObject, Crud}; use crate::{ApubObject, Crud, DeleteableOrRemoveable};
use diesel::{dsl::*, result::Error, *}; use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::{naive_now, source::private_message::*, DbUrl, PersonId, PrivateMessageId}; use lemmy_db_schema::{naive_now, source::private_message::*, DbUrl, PersonId, PrivateMessageId};
@ -137,6 +137,13 @@ impl PrivateMessage_ for PrivateMessage {
} }
} }
impl DeleteableOrRemoveable for PrivateMessage {
fn blank_out_deleted_or_removed_info(mut self) -> Self {
self.content = "".into();
self
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{establish_unpooled_connection, source::private_message::PrivateMessage_, Crud}; use crate::{establish_unpooled_connection, source::private_message::PrivateMessage_, Crud};