From a2a81e57267f9595064d46167df566523661e3ca Mon Sep 17 00:00:00 2001 From: freamon Date: Fri, 18 Oct 2024 08:33:50 +0000 Subject: [PATCH] post-reply soft-deletion: don't overwrite content, so it can be restored --- app/activitypub/util.py | 16 ++++------------ app/community/util.py | 8 ++------ app/post/routes.py | 9 ++------- 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/app/activitypub/util.py b/app/activitypub/util.py index 4def65ef..b753036a 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -1323,12 +1323,8 @@ def delete_post_or_comment_task(user_ap_id, community_ap_id, to_be_deleted_ap_id elif isinstance(to_delete, PostReply): if not to_delete.author.bot: to_delete.post.reply_count -= 1 - if to_delete.has_replies(): - to_delete.body = 'Deleted by author' if to_delete.author.id == deletor.id else 'Deleted by moderator' - to_delete.body_html = markdown_to_html(to_delete.body) - else: - to_delete.delete_dependencies() - to_delete.deleted = True + to_delete.deleted = True + to_delete.deleted_by = deletor.id to_delete.author.post_reply_count -= 1 to_delete.deleted_by = deletor.id db.session.commit() @@ -1398,12 +1394,8 @@ def remove_data_from_banned_user_task(deletor_ap_id, user_ap_id, target): for post_reply in post_replies: if not user.bot: post_reply.post.reply_count -= 1 - if post_reply.has_replies(): - post_reply.body = 'Banned' - post_reply.body_html = markdown_to_html(post_reply.body) - else: - post_reply.delete_dependencies() - post_reply.deleted = True + post_reply.deleted = True + post_reply.deleted_by = deletor.id db.session.commit() for post in posts: diff --git a/app/community/util.py b/app/community/util.py index b865d48c..7d5eba0f 100644 --- a/app/community/util.py +++ b/app/community/util.py @@ -566,12 +566,8 @@ def delete_post_reply_from_community_task(post_reply_id): post = post_reply.post community = post.community if post_reply.user_id == current_user.id or community.is_moderator(): - if post_reply.has_replies(): - post_reply.body = 'Deleted by author' if post_reply.author.id == current_user.id else 'Deleted by moderator' - post_reply.body_html = markdown_to_html(post_reply.body) - else: - post_reply.delete_dependencies() - post_reply.deleted = True + post_reply.deleted = True + post_reply.deleted_by = current_user.id db.session.commit() # federate delete diff --git a/app/post/routes.py b/app/post/routes.py index 47f5fc77..62962cc3 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -1597,17 +1597,12 @@ def post_reply_delete(post_id: int, comment_id: int): post_reply = PostReply.query.get_or_404(comment_id) community = post.community if post_reply.user_id == current_user.id or community.is_moderator() or current_user.is_admin(): - if post_reply.has_replies(): - post_reply.body = 'Deleted by author' if post_reply.author.id == current_user.id else 'Deleted by moderator' - post_reply.body_html = markdown_to_html(post_reply.body) - else: - post_reply.delete_dependencies() - post_reply.deleted = True + post_reply.deleted = True + post_reply.deleted_by = current_user.id g.site.last_active = community.last_active = utcnow() if not post_reply.author.bot: post.reply_count -= 1 post_reply.author.post_reply_count -= 1 - post_reply.deleted_by = current_user.id db.session.commit() flash(_('Comment deleted.')) # federate delete