diff --git a/app/post/routes.py b/app/post/routes.py index a90ae1db..fc0f8d66 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -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)) +@bp.route('/post//comment//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//notification', methods=['GET', 'POST']) @login_required def post_notification(post_id: int): diff --git a/app/templates/post/post_reply_options.html b/app/templates/post/post_reply_options.html index 78bb7f36..339deb57 100644 --- a/app/templates/post/post_reply_options.html +++ b/app/templates/post/post_reply_options.html @@ -19,8 +19,14 @@ {% 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.deleted -%} -
  • +
  • {{ _('Restore') }}
  • + {% 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) -%} +
  • + {{ _('Purge') }}
  • + {% endif -%} + {% endif -%} {% else -%}
  • {{ _('Delete') }}