From 157378b4c98a1fc8f915b2594fc10252693a346f Mon Sep 17 00:00:00 2001 From: Nutomic Date: Tue, 5 Mar 2024 14:52:35 +0100 Subject: [PATCH] Clear text of deleted/removed comments (#4503) --- api_tests/prepare-drone-federation-test.sh | 2 +- api_tests/src/comment.spec.ts | 14 +++++++++++++- crates/db_views/src/comment_view.rs | 17 ++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/api_tests/prepare-drone-federation-test.sh b/api_tests/prepare-drone-federation-test.sh index 34a05c02b..147a553ab 100755 --- a/api_tests/prepare-drone-federation-test.sh +++ b/api_tests/prepare-drone-federation-test.sh @@ -9,7 +9,7 @@ then fi export RUST_BACKTRACE=1 -export RUST_LOG="warn,lemmy_server=$LEMMY_LOG_LEVEL,lemmy_federate=$LEMMY_LOG_LEVEL,lemmy_api=$LEMMY_LOG_LEVEL,lemmy_api_common=$LEMMY_LOG_LEVEL,lemmy_api_crud=$LEMMY_LOG_LEVEL,lemmy_apub=$LEMMY_LOG_LEVEL,lemmy_db_schema=$LEMMY_LOG_LEVEL,lemmy_db_views=$LEMMY_LOG_LEVEL,lemmy_db_views_actor=$LEMMY_LOG_LEVEL,lemmy_db_views_moderator=$LEMMY_LOG_LEVEL,lemmy_routes=$LEMMY_LOG_LEVEL,lemmy_utils=$LEMMY_LOG_LEVEL,lemmy_websocket=$LEMMY_LOG_LEVEL" +#export RUST_LOG="warn,lemmy_server=$LEMMY_LOG_LEVEL,lemmy_federate=$LEMMY_LOG_LEVEL,lemmy_api=$LEMMY_LOG_LEVEL,lemmy_api_common=$LEMMY_LOG_LEVEL,lemmy_api_crud=$LEMMY_LOG_LEVEL,lemmy_apub=$LEMMY_LOG_LEVEL,lemmy_db_schema=$LEMMY_LOG_LEVEL,lemmy_db_views=$LEMMY_LOG_LEVEL,lemmy_db_views_actor=$LEMMY_LOG_LEVEL,lemmy_db_views_moderator=$LEMMY_LOG_LEVEL,lemmy_routes=$LEMMY_LOG_LEVEL,lemmy_utils=$LEMMY_LOG_LEVEL,lemmy_websocket=$LEMMY_LOG_LEVEL" export LEMMY_TEST_FAST_FEDERATION=1 # by default, the persistent federation queue has delays in the scale of 30s-5min diff --git a/api_tests/src/comment.spec.ts b/api_tests/src/comment.spec.ts index 4655a81ff..de714f687 100644 --- a/api_tests/src/comment.spec.ts +++ b/api_tests/src/comment.spec.ts @@ -128,8 +128,9 @@ test("Update a comment", async () => { }); test("Delete a comment", async () => { + let post = await createPost(alpha, betaCommunity!.community.id); // creating a comment on alpha (remote from home of community) - let commentRes = await createComment(alpha, postOnAlphaRes.post_view.post.id); + let commentRes = await createComment(alpha, post.post_view.post.id); // Find the comment on beta (home of community) let betaComment = ( @@ -157,6 +158,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 await waitUntil( @@ -255,6 +257,16 @@ test("Remove a comment from admin and community on different instance", async () betaComment.comment.id, ); expect(removeCommentRes.comment_view.comment.removed).toBe(true); + expect(removeCommentRes.comment_view.comment.content).toBe(""); + + // Comment text is also hidden from list + let listComments = await getComments( + beta, + removeCommentRes.comment_view.post.id, + ); + expect(listComments.comments.length).toBe(1); + expect(listComments.comments[0].comment.removed).toBe(true); + expect(listComments.comments[0].comment.content).toBe(""); // Make sure its not removed on alpha let refetchedPostComments = await getComments( diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index 4be2f6f13..a72d0b210 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -363,6 +363,9 @@ impl CommentView { if my_person_id.is_some() && res.my_vote.is_none() { res.my_vote = Some(0); } + if res.comment.deleted || res.comment.removed { + res.comment.content = String::new(); + } Ok(res) } } @@ -387,7 +390,19 @@ pub struct CommentQuery<'a> { impl<'a> CommentQuery<'a> { pub async fn list(self, pool: &mut DbPool<'_>) -> Result, Error> { - queries().list(pool, self).await + Ok( + queries() + .list(pool, self) + .await? + .into_iter() + .map(|mut c| { + if c.comment.deleted || c.comment.removed { + c.comment.content = String::new(); + } + c + }) + .collect(), + ) } }