post-reply soft-deletion: add option to purge a comment

This commit is contained in:
freamon 2024-10-19 17:24:48 +00:00
parent 5643c19e44
commit 148d230527
2 changed files with 30 additions and 1 deletions

View file

@ -1722,6 +1722,29 @@ def post_reply_restore(post_id: int, comment_id: int):
return redirect(url_for('activitypub.post_ap', post_id=post.id)) return redirect(url_for('activitypub.post_ap', post_id=post.id))
@bp.route('/post/<int:post_id>/comment/<int:comment_id>/purge', methods=['GET', 'POST'])
@login_required
def post_reply_purge(post_id: int, comment_id: int):
post = Post.query.get_or_404(post_id)
post_reply = PostReply.query.get_or_404(comment_id)
if not post_reply.deleted:
abort(404)
if post_reply.user_id == current_user.id and (post_reply.deleted_by is None or post_reply.deleted_by != post_reply.user_id):
abort(401)
if post_reply.user_id == current_user.id or post.community.is_moderator() or current_user.is_admin():
if not post_reply.has_replies():
post_reply.delete_dependencies()
db.session.delete(post_reply)
db.session.commit()
flash(_('Comment purged.'))
else:
flash(_('Comments that have been replied to cannot be purged.'))
else:
abort(401)
return redirect(url_for('activitypub.post_ap', post_id=post.id))
@bp.route('/post/<int:post_id>/notification', methods=['GET', 'POST']) @bp.route('/post/<int:post_id>/notification', methods=['GET', 'POST'])
@login_required @login_required
def post_notification(post_id: int): def post_notification(post_id: int):

View file

@ -19,8 +19,14 @@
{% endif -%} {% endif -%}
{% if post_reply.user_id == current_user.id or post.community.is_moderator() or post.community.is_owner() or current_user.is_admin() -%} {% if post_reply.user_id == current_user.id or post.community.is_moderator() or post.community.is_owner() or current_user.is_admin() -%}
{% if post_reply.deleted -%} {% if post_reply.deleted -%}
<li><a href="{{ url_for('post.post_reply_restore', post_id=post.id, comment_id=post_reply.id) }}" class="no-underline confirm_first" rel="nofollow"><span class="fe fe-delete"></span> <li><a href="{{ url_for('post.post_reply_restore', post_id=post.id, comment_id=post_reply.id) }}" class="no-underline confirm_first" rel="nofollow"><span class="fe fe-arrow-up"></span>
{{ _('Restore') }}</a></li> {{ _('Restore') }}</a></li>
{% if not post_reply.has_replies() -%}
{% if post.community.is_moderator() or current_user.is_admin() or (post_reply.user_id == current_user.id and post_reply.deleted_by == post_reply.user_id) -%}
<li><a href="{{ url_for('post.post_reply_purge', post_id=post.id, comment_id=post_reply.id) }}" class="no-underline confirm_first" rel="nofollow"><span class="fe fe-delete red"></span>
{{ _('Purge') }}</a></li>
{% endif -%}
{% endif -%}
{% else -%} {% else -%}
<li><a href="{{ url_for('post.post_reply_delete', post_id=post.id, comment_id=post_reply.id) }}" class="no-underline confirm_first" rel="nofollow"><span class="fe fe-delete"></span> <li><a href="{{ url_for('post.post_reply_delete', post_id=post.id, comment_id=post_reply.id) }}" class="no-underline confirm_first" rel="nofollow"><span class="fe fe-delete"></span>
{{ _('Delete') }}</a></li> {{ _('Delete') }}</a></li>