Skip to content

Commit

Permalink
Comments can only be deleted by the author of the comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
tompollard committed Jul 11, 2024
1 parent 64c9cda commit 84754fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,15 @@ <h5>Uploaded Documents</h5>
<li class="list-group-item">
<p>{{ note.content }}</p>
<p class="small text-muted">Created by {{ note.created_by }} on {{ note.created_at }}</p>
<form action="{% url 'submission_info' project.slug %}" method="POST" id="internal_note_form">
{% csrf_token %}
<input type="hidden" name="note_id" value="{{ note.id }}">
<button class="btn btn-danger btn-rsp" type="submit" name="delete_internal_note" onclick="return confirm('Are you sure you want to delete this note?');">
Delete
</button>
</form>
{% if note.created_by == user %}
<form action="{% url 'submission_info' project.slug %}" method="POST" id="internal_note_form">
{% csrf_token %}
<input type="hidden" name="note_id" value="{{ note.id }}">
<button class="btn btn-danger btn-rsp" type="submit" name="delete_internal_note" onclick="return confirm('Are you sure you want to delete this note?');">
Delete
</button>
</form>
{% endif %}
</li>
{% endfor %}

Expand Down
7 changes: 5 additions & 2 deletions physionet-django/console/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,11 @@ def submission_info(request, project_slug):
if 'delete_internal_note' in request.POST:
note_id = request.POST['note_id']
note = get_object_or_404(InternalNote, pk=note_id, project=project)
note.delete()
messages.success(request, "Note deleted.")
if note.created_by == request.user:
note.delete()
messages.success(request, "Note deleted.")
else:
messages.error(request, "You are not authorized to delete this note.")
return redirect(f'{request.path}?tab=notes')

url_prefix = notification.get_url_prefix(request)
Expand Down

0 comments on commit 84754fb

Please sign in to comment.