Skip to content
Snippets Groups Projects
Commit 3f545238 authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Allow to delete comments

JIRA INFRA-618
parent 51f1a5a2
No related branches found
No related tags found
No related merge requests found
......@@ -135,6 +135,20 @@ def edit_comment(comment_id):
)
@bp.route("/items/comment/delete", methods=["POST"])
@login_groups_accepted("admin", "create")
def delete_comment():
comment = models.ItemComment.query.get_or_404(request.form["comment_id"])
ics_id = comment.item.ics_id
# Explicitely remove the comment from the item to make sure
# it will be re-indexed
comment.item.comments.remove(comment)
db.session.delete(comment)
db.session.commit()
flash(f"Comment {comment.id} has been deleted", "success")
return redirect(url_for("inventory.view_item", ics_id=ics_id))
@bp.route("/items/edit/<ics_id>", methods=("GET", "POST"))
@login_groups_accepted("admin", "create")
def edit_item(ics_id):
......
......@@ -227,6 +227,13 @@
{% if comment.updated_at != comment.created_at %}
<small class="">Edited {{ format_datetime(comment.updated_at) }}</small>
{% endif %}
<div class="float-sm-right">
<form method="POST" action="/inventory/items/comment/delete">
<input id="comment_id" name="comment_id" type="hidden" value="{{ comment.id }}">
{{ delete_button_with_confirmation("Delete comment", "deleteConfirmation-%s" | format(comment.id),
"Are you sure you want to delete this comment?") }}
</form>
</div>
<a class="btn btn-light float-sm-right" href="{{ url_for('inventory.edit_comment', comment_id=comment.id) }}#body">
<span class="oi oi-pencil" title="Edit comment" aria-hidden="true"></span>
</a>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment