mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-24 03:43:42 -08:00
post-reply soft-deletion: don't overwrite content, so it can be restored
This commit is contained in:
parent
df2dc6e020
commit
a2a81e5726
3 changed files with 8 additions and 25 deletions
|
@ -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):
|
elif isinstance(to_delete, PostReply):
|
||||||
if not to_delete.author.bot:
|
if not to_delete.author.bot:
|
||||||
to_delete.post.reply_count -= 1
|
to_delete.post.reply_count -= 1
|
||||||
if to_delete.has_replies():
|
to_delete.deleted = True
|
||||||
to_delete.body = 'Deleted by author' if to_delete.author.id == deletor.id else 'Deleted by moderator'
|
to_delete.deleted_by = deletor.id
|
||||||
to_delete.body_html = markdown_to_html(to_delete.body)
|
|
||||||
else:
|
|
||||||
to_delete.delete_dependencies()
|
|
||||||
to_delete.deleted = True
|
|
||||||
to_delete.author.post_reply_count -= 1
|
to_delete.author.post_reply_count -= 1
|
||||||
to_delete.deleted_by = deletor.id
|
to_delete.deleted_by = deletor.id
|
||||||
db.session.commit()
|
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:
|
for post_reply in post_replies:
|
||||||
if not user.bot:
|
if not user.bot:
|
||||||
post_reply.post.reply_count -= 1
|
post_reply.post.reply_count -= 1
|
||||||
if post_reply.has_replies():
|
post_reply.deleted = True
|
||||||
post_reply.body = 'Banned'
|
post_reply.deleted_by = deletor.id
|
||||||
post_reply.body_html = markdown_to_html(post_reply.body)
|
|
||||||
else:
|
|
||||||
post_reply.delete_dependencies()
|
|
||||||
post_reply.deleted = True
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
for post in posts:
|
for post in posts:
|
||||||
|
|
|
@ -566,12 +566,8 @@ def delete_post_reply_from_community_task(post_reply_id):
|
||||||
post = post_reply.post
|
post = post_reply.post
|
||||||
community = post.community
|
community = post.community
|
||||||
if post_reply.user_id == current_user.id or community.is_moderator():
|
if post_reply.user_id == current_user.id or community.is_moderator():
|
||||||
if post_reply.has_replies():
|
post_reply.deleted = True
|
||||||
post_reply.body = 'Deleted by author' if post_reply.author.id == current_user.id else 'Deleted by moderator'
|
post_reply.deleted_by = current_user.id
|
||||||
post_reply.body_html = markdown_to_html(post_reply.body)
|
|
||||||
else:
|
|
||||||
post_reply.delete_dependencies()
|
|
||||||
post_reply.deleted = True
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
# federate delete
|
# federate delete
|
||||||
|
|
|
@ -1597,17 +1597,12 @@ def post_reply_delete(post_id: int, comment_id: int):
|
||||||
post_reply = PostReply.query.get_or_404(comment_id)
|
post_reply = PostReply.query.get_or_404(comment_id)
|
||||||
community = post.community
|
community = post.community
|
||||||
if post_reply.user_id == current_user.id or community.is_moderator() or current_user.is_admin():
|
if post_reply.user_id == current_user.id or community.is_moderator() or current_user.is_admin():
|
||||||
if post_reply.has_replies():
|
post_reply.deleted = True
|
||||||
post_reply.body = 'Deleted by author' if post_reply.author.id == current_user.id else 'Deleted by moderator'
|
post_reply.deleted_by = current_user.id
|
||||||
post_reply.body_html = markdown_to_html(post_reply.body)
|
|
||||||
else:
|
|
||||||
post_reply.delete_dependencies()
|
|
||||||
post_reply.deleted = True
|
|
||||||
g.site.last_active = community.last_active = utcnow()
|
g.site.last_active = community.last_active = utcnow()
|
||||||
if not post_reply.author.bot:
|
if not post_reply.author.bot:
|
||||||
post.reply_count -= 1
|
post.reply_count -= 1
|
||||||
post_reply.author.post_reply_count -= 1
|
post_reply.author.post_reply_count -= 1
|
||||||
post_reply.deleted_by = current_user.id
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash(_('Comment deleted.'))
|
flash(_('Comment deleted.'))
|
||||||
# federate delete
|
# federate delete
|
||||||
|
|
Loading…
Add table
Reference in a new issue