post-reply soft-deletion: don't overwrite content, so it can be restored

This commit is contained in:
freamon 2024-10-18 08:33:50 +00:00
parent df2dc6e020
commit a2a81e5726
3 changed files with 8 additions and 25 deletions

View file

@ -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:

View file

@ -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

View file

@ -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