From: Dessalines Date: Fri, 30 Jul 2021 18:44:15 +0000 (-0400) Subject: Blank out extra info for deleted or removed content. Fixes #1679 (#1680) X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/save/%24%7BgetStaticDir%28%29%7D/js/static/git-favicon.png?a=commitdiff_plain;h=d85f0d087e4bec64573ba34892989d6392271afd;p=lemmy.git Blank out extra info for deleted or removed content. Fixes #1679 (#1680) --- diff --git a/api_tests/src/comment.spec.ts b/api_tests/src/comment.spec.ts index b0ca55d0..68dbcf7c 100644 --- a/api_tests/src/comment.spec.ts +++ b/api_tests/src/comment.spec.ts @@ -115,6 +115,7 @@ test('Delete a comment', async () => { commentRes.comment_view.comment.id ); expect(deleteCommentRes.comment_view.comment.deleted).toBe(true); + expect(deleteCommentRes.comment_view.comment.content).toBe(""); // Make sure that comment is undefined on beta 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) let removeCommentRes = await removeComment(beta, true, betaCommentId); 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) let refetchedPost = await getPost(alpha, postRes.post_view.post.id); diff --git a/api_tests/src/community.spec.ts b/api_tests/src/community.spec.ts index a86c1259..3d4a3a35 100644 --- a/api_tests/src/community.spec.ts +++ b/api_tests/src/community.spec.ts @@ -77,6 +77,7 @@ test('Delete community', async () => { communityRes.community_view.community.id ); expect(deleteCommunityRes.community_view.community.deleted).toBe(true); + expect(deleteCommunityRes.community_view.community.title).toBe(""); // Make sure it got deleted on A let communityOnAlphaDeleted = await getCommunity( @@ -128,6 +129,7 @@ test('Remove community', async () => { communityRes.community_view.community.id ); expect(removeCommunityRes.community_view.community.removed).toBe(true); + expect(removeCommunityRes.community_view.community.title).toBe(""); // Make sure it got Removed on A let communityOnAlphaRemoved = await getCommunity( diff --git a/api_tests/src/post.spec.ts b/api_tests/src/post.spec.ts index 36e5ac3f..c5630f33 100644 --- a/api_tests/src/post.spec.ts +++ b/api_tests/src/post.spec.ts @@ -210,6 +210,7 @@ test('Delete a post', async () => { let deletedPost = await deletePost(alpha, true, postRes.post_view.post); expect(deletedPost.post_view.post.deleted).toBe(true); + expect(deletedPost.post_view.post.name).toBe(""); // Make sure lemmy beta sees post is deleted 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); expect(removedPost.post_view.post.removed).toBe(true); + expect(removedPost.post_view.post.name).toBe(""); // Make sure lemmy beta sees post is NOT removed let searchBeta = await searchPost(beta, postRes.post_view.post); diff --git a/api_tests/src/private_message.spec.ts b/api_tests/src/private_message.spec.ts index 11b41cb1..0051f2c7 100644 --- a/api_tests/src/private_message.spec.ts +++ b/api_tests/src/private_message.spec.ts @@ -64,6 +64,7 @@ test('Delete a private message', async () => { pmRes.private_message_view.private_message.id ); expect(deletedPmRes.private_message_view.private_message.deleted).toBe(true); + expect(deletedPmRes.private_message_view.private_message.content).toBe(""); // The GetPrivateMessages filters out deleted, // even though they are in the actual database. diff --git a/crates/api/src/site.rs b/crates/api/src/site.rs index f9d7962b..d67c1181 100644 --- a/crates/api/src/site.rs +++ b/crates/api/src/site.rs @@ -15,6 +15,7 @@ use lemmy_db_queries::{ from_opt_str_to_opt_enum, source::site::Site_, Crud, + DeleteableOrRemoveable, ListingType, SearchType, 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 Ok(SearchResponse { type_: search_type.to_string(), diff --git a/crates/api_crud/src/comment/delete.rs b/crates/api_crud/src/comment/delete.rs index f58f3b0e..e2ec3080 100644 --- a/crates/api_crud/src/comment/delete.rs +++ b/crates/api_crud/src/comment/delete.rs @@ -9,7 +9,7 @@ use lemmy_api_common::{ send_local_notifs, }; 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_views::comment_view::CommentView; use lemmy_utils::{ApiError, ConnectionId, LemmyError}; @@ -47,7 +47,7 @@ impl PerformCrud for DeleteComment { // Do the delete 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) }) .await? @@ -55,6 +55,7 @@ impl PerformCrud for DeleteComment { // Send the apub message if deleted { + updated_comment = updated_comment.blank_out_deleted_or_removed_info(); updated_comment .send_delete(&local_user_view.person, context) .await?; @@ -67,11 +68,16 @@ impl PerformCrud for DeleteComment { // Refetch it let comment_id = data.comment_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)) }) .await??; + // Blank out deleted or removed info + if deleted { + comment_view.comment = comment_view.comment.blank_out_deleted_or_removed_info(); + } + // Build the recipients let comment_view_2 = comment_view.clone(); let mentions = vec![]; @@ -136,7 +142,7 @@ impl PerformCrud for RemoveComment { // Do the remove 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) }) .await? @@ -156,6 +162,7 @@ impl PerformCrud for RemoveComment { // Send the apub message if removed { + updated_comment = updated_comment.blank_out_deleted_or_removed_info(); updated_comment .send_remove(&local_user_view.person, context) .await?; @@ -168,11 +175,16 @@ impl PerformCrud for RemoveComment { // Refetch it let comment_id = data.comment_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)) }) .await??; + // Blank out deleted or removed info + if removed { + comment_view.comment = comment_view.comment.blank_out_deleted_or_removed_info(); + } + // Build the recipients let comment_view_2 = comment_view.clone(); diff --git a/crates/api_crud/src/comment/read.rs b/crates/api_crud/src/comment/read.rs index 47394402..fc4bd1e3 100644 --- a/crates/api_crud/src/comment/read.rs +++ b/crates/api_crud/src/comment/read.rs @@ -2,7 +2,7 @@ use crate::PerformCrud; use actix_web::web::Data; use lemmy_api_common::{blocking, comment::*, get_local_user_view_from_jwt_opt}; 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_utils::{ApiError, ConnectionId, LemmyError}; use lemmy_websocket::LemmyContext; @@ -36,7 +36,7 @@ impl PerformCrud for GetComments { let saved_only = data.saved_only; let page = data.page; let limit = data.limit; - let comments = blocking(context.pool(), move |conn| { + let mut comments = blocking(context.pool(), move |conn| { CommentQueryBuilder::create(conn) .listing_type(listing_type) .sort(sort) @@ -52,6 +52,14 @@ impl PerformCrud for GetComments { .await? .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 }) } } diff --git a/crates/api_crud/src/comment/update.rs b/crates/api_crud/src/comment/update.rs index e6ed6ab5..dbdb1a6d 100644 --- a/crates/api_crud/src/comment/update.rs +++ b/crates/api_crud/src/comment/update.rs @@ -8,7 +8,7 @@ use lemmy_api_common::{ send_local_notifs, }; 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_views::comment_view::CommentView; use lemmy_utils::{ @@ -78,11 +78,16 @@ impl PerformCrud for EditComment { let comment_id = data.comment_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)) }) .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 { comment_view, recipient_ids, diff --git a/crates/api_crud/src/community/delete.rs b/crates/api_crud/src/community/delete.rs index 2208a348..62fb0f38 100644 --- a/crates/api_crud/src/community/delete.rs +++ b/crates/api_crud/src/community/delete.rs @@ -2,7 +2,7 @@ use crate::{community::send_community_websocket, PerformCrud}; use actix_web::web::Data; use lemmy_api_common::{blocking, community::*, get_local_user_view_from_jwt, is_admin}; 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::{ community::*, moderator::{ModRemoveCommunity, ModRemoveCommunityForm}, @@ -50,6 +50,7 @@ impl PerformCrud for DeleteCommunity { // Send apub messages if deleted { updated_community + .blank_out_deleted_or_removed_info() .send_delete(local_user_view.person.to_owned(), context) .await?; } else { @@ -60,11 +61,16 @@ impl PerformCrud for DeleteCommunity { let community_id = data.community_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)) }) .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 }; send_community_websocket( @@ -118,18 +124,26 @@ impl PerformCrud for RemoveCommunity { // Apub messages if removed { - updated_community.send_remove(context).await?; + updated_community + .blank_out_deleted_or_removed_info() + .send_remove(context) + .await?; } else { updated_community.send_undo_remove(context).await?; } let community_id = data.community_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)) }) .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 }; send_community_websocket( diff --git a/crates/api_crud/src/community/read.rs b/crates/api_crud/src/community/read.rs index 0cca08df..94e4ce7f 100644 --- a/crates/api_crud/src/community/read.rs +++ b/crates/api_crud/src/community/read.rs @@ -2,7 +2,13 @@ use crate::PerformCrud; use actix_web::web::Data; use lemmy_api_common::{blocking, community::*, get_local_user_view_from_jwt_opt}; 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_views_actor::{ 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) }) .await? .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 = blocking(context.pool(), move |conn| { CommunityModeratorView::for_community(conn, community_id) }) @@ -93,7 +104,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) @@ -105,6 +116,14 @@ impl PerformCrud for ListCommunities { }) .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 Ok(ListCommunitiesResponse { communities }) } diff --git a/crates/api_crud/src/community/update.rs b/crates/api_crud/src/community/update.rs index b17a223e..49de1cfd 100644 --- a/crates/api_crud/src/community/update.rs +++ b/crates/api_crud/src/community/update.rs @@ -6,7 +6,7 @@ use lemmy_api_common::{ get_local_user_view_from_jwt, }; 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::{ naive_now, source::community::{Community, CommunityForm}, @@ -78,11 +78,16 @@ impl PerformCrud for EditCommunity { let community_id = data.community_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)) }) .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 }; send_community_websocket( diff --git a/crates/api_crud/src/post/delete.rs b/crates/api_crud/src/post/delete.rs index e7fcb2fd..cf48757d 100644 --- a/crates/api_crud/src/post/delete.rs +++ b/crates/api_crud/src/post/delete.rs @@ -8,7 +8,7 @@ use lemmy_api_common::{ post::*, }; 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_views::post_view::PostView; use lemmy_utils::{ApiError, ConnectionId, LemmyError}; @@ -52,6 +52,7 @@ impl PerformCrud for DeletePost { // apub updates if deleted { updated_post + .blank_out_deleted_or_removed_info() .send_delete(&local_user_view.person, context) .await?; } else { @@ -62,11 +63,15 @@ impl PerformCrud for DeletePost { // Refetch the post 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)) }) .await??; + if deleted { + post_view.post = post_view.post.blank_out_deleted_or_removed_info(); + } + let res = PostResponse { post_view }; context.chat_server().do_send(SendPost { @@ -132,6 +137,7 @@ impl PerformCrud for RemovePost { // apub updates if removed { updated_post + .blank_out_deleted_or_removed_info() .send_remove(&local_user_view.person, context) .await?; } else { @@ -143,11 +149,16 @@ impl PerformCrud for RemovePost { // Refetch the post let post_id = data.post_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)) }) .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 }; context.chat_server().do_send(SendPost { diff --git a/crates/api_crud/src/post/read.rs b/crates/api_crud/src/post/read.rs index 77e7a216..d651a057 100644 --- a/crates/api_crud/src/post/read.rs +++ b/crates/api_crud/src/post/read.rs @@ -2,7 +2,7 @@ use crate::PerformCrud; use actix_web::web::Data; 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_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, post_view::{PostQueryBuilder, PostView}, @@ -32,19 +32,24 @@ 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? .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 if let Some(person_id) = person_id { mark_post_as_read(person_id, id, context.pool()).await?; } let id = data.id; - let comments = blocking(context.pool(), move |conn| { + let mut comments = blocking(context.pool(), move |conn| { CommentQueryBuilder::create(conn) .my_person_id(person_id) .show_bot_accounts(show_bot_accounts) @@ -54,6 +59,14 @@ 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) @@ -61,12 +74,17 @@ impl PerformCrud for GetPost { .await??; // 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) }) .await? .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 .chat_server() .send(GetPostUsersOnline { post_id: data.id }) @@ -119,7 +137,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) @@ -137,6 +155,14 @@ impl PerformCrud for GetPosts { .await? .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 }) } } diff --git a/crates/api_crud/src/post/update.rs b/crates/api_crud/src/post/update.rs index f215da7d..5166f212 100644 --- a/crates/api_crud/src/post/update.rs +++ b/crates/api_crud/src/post/update.rs @@ -2,7 +2,7 @@ use crate::PerformCrud; use actix_web::web::Data; use lemmy_api_common::{blocking, check_community_ban, get_local_user_view_from_jwt, post::*}; 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_views::post_view::PostView; use lemmy_utils::{ @@ -94,11 +94,16 @@ impl PerformCrud for EditPost { .await?; 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)) }) .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 }; context.chat_server().do_send(SendPost { diff --git a/crates/api_crud/src/private_message/delete.rs b/crates/api_crud/src/private_message/delete.rs index 6befb75d..757596cd 100644 --- a/crates/api_crud/src/private_message/delete.rs +++ b/crates/api_crud/src/private_message/delete.rs @@ -6,7 +6,7 @@ use lemmy_api_common::{ person::{DeletePrivateMessage, PrivateMessageResponse}, }; 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_views::{local_user_view::LocalUserView, private_message_view::PrivateMessageView}; use lemmy_utils::{ApiError, ConnectionId, LemmyError}; @@ -46,6 +46,7 @@ impl PerformCrud for DeletePrivateMessage { // Send the apub update if data.deleted { updated_private_message + .blank_out_deleted_or_removed_info() .send_delete(&local_user_view.person, context) .await?; } else { @@ -55,11 +56,18 @@ impl PerformCrud for DeletePrivateMessage { } 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) }) .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 { private_message_view, }; diff --git a/crates/api_crud/src/private_message/read.rs b/crates/api_crud/src/private_message/read.rs index 6706bf41..3acbaa39 100644 --- a/crates/api_crud/src/private_message/read.rs +++ b/crates/api_crud/src/private_message/read.rs @@ -5,6 +5,7 @@ use lemmy_api_common::{ get_local_user_view_from_jwt, person::{GetPrivateMessages, PrivateMessagesResponse}, }; +use lemmy_db_queries::DeleteableOrRemoveable; use lemmy_db_views::private_message_view::PrivateMessageQueryBuilder; use lemmy_utils::{ConnectionId, LemmyError}; use lemmy_websocket::LemmyContext; @@ -25,7 +26,7 @@ impl PerformCrud for GetPrivateMessages { let page = data.page; let limit = data.limit; 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) .page(page) .limit(limit) @@ -34,6 +35,17 @@ impl PerformCrud for GetPrivateMessages { }) .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 { private_messages: messages, }) diff --git a/crates/api_crud/src/private_message/update.rs b/crates/api_crud/src/private_message/update.rs index 35a9806a..33c29d00 100644 --- a/crates/api_crud/src/private_message/update.rs +++ b/crates/api_crud/src/private_message/update.rs @@ -6,7 +6,7 @@ use lemmy_api_common::{ person::{EditPrivateMessage, PrivateMessageResponse}, }; 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_views::{local_user_view::LocalUserView, private_message_view::PrivateMessageView}; use lemmy_utils::{utils::remove_slurs, ApiError, ConnectionId, LemmyError}; @@ -49,11 +49,18 @@ impl PerformCrud for EditPrivateMessage { .await?; 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) }) .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 { private_message_view, }; diff --git a/crates/db_queries/src/lib.rs b/crates/db_queries/src/lib.rs index fbd508c1..adc0717a 100644 --- a/crates/db_queries/src/lib.rs +++ b/crates/db_queries/src/lib.rs @@ -117,6 +117,10 @@ pub trait Reportable
{ Self: Sized; } +pub trait DeleteableOrRemoveable { + fn blank_out_deleted_or_removed_info(self) -> Self; +} + pub trait ApubObject { fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result where diff --git a/crates/db_queries/src/source/comment.rs b/crates/db_queries/src/source/comment.rs index 1eec0c98..d0171cb8 100644 --- a/crates/db_queries/src/source/comment.rs +++ b/crates/db_queries/src/source/comment.rs @@ -1,4 +1,4 @@ -use crate::{ApubObject, Crud, Likeable, Saveable}; +use crate::{ApubObject, Crud, DeleteableOrRemoveable, Likeable, Saveable}; use diesel::{dsl::*, result::Error, *}; use lemmy_db_schema::{ naive_now, @@ -228,6 +228,13 @@ impl Saveable for CommentSaved { } } +impl DeleteableOrRemoveable for Comment { + fn blank_out_deleted_or_removed_info(mut self) -> Self { + self.content = "".into(); + self + } +} + #[cfg(test)] mod tests { use crate::{establish_unpooled_connection, Crud, Likeable, Saveable}; diff --git a/crates/db_queries/src/source/community.rs b/crates/db_queries/src/source/community.rs index 3f1f0476..2a621933 100644 --- a/crates/db_queries/src/source/community.rs +++ b/crates/db_queries/src/source/community.rs @@ -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 lemmy_db_schema::{ naive_now, @@ -11,6 +11,7 @@ use lemmy_db_schema::{ CommunityModeratorForm, CommunityPersonBan, CommunityPersonBanForm, + CommunitySafe, }, CommunityId, DbUrl, @@ -199,6 +200,26 @@ impl Joinable 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_ { fn delete_for_community( conn: &PgConnection, diff --git a/crates/db_queries/src/source/post.rs b/crates/db_queries/src/source/post.rs index 9f2d2f9b..f0cf1093 100644 --- a/crates/db_queries/src/source/post.rs +++ b/crates/db_queries/src/source/post.rs @@ -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 lemmy_db_schema::{ naive_now, @@ -260,6 +260,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::{establish_unpooled_connection, source::post::*}; diff --git a/crates/db_queries/src/source/private_message.rs b/crates/db_queries/src/source/private_message.rs index 98c8e08c..da1c5abd 100644 --- a/crates/db_queries/src/source/private_message.rs +++ b/crates/db_queries/src/source/private_message.rs @@ -1,4 +1,4 @@ -use crate::{ApubObject, Crud}; +use crate::{ApubObject, Crud, DeleteableOrRemoveable}; use diesel::{dsl::*, result::Error, *}; 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)] mod tests { use crate::{establish_unpooled_connection, source::private_message::PrivateMessage_, Crud};