diff --git a/junction/proposals/comments_views.py b/junction/proposals/comments_views.py index c214830b..0981f79f 100644 --- a/junction/proposals/comments_views.py +++ b/junction/proposals/comments_views.py @@ -123,3 +123,20 @@ def unmark_comment_as_spam( return HttpResponse("Unmarked as spam") return HttpResponseForbidden() + +@login_required +@csrf_exempt +@require_http_methods(["POST"]) +def delete_self_comment(request, conference_slug, proposal_slug, proposal_comment_id): + if not request.is_ajax() or request.user.is_active is False: + return HttpResponseForbidden() + + conference = get_object_or_404(Conference, slug=conference_slug) + proposal = get_object_or_404(Proposal, slug=proposal_slug, conference=conference) + proposal_comment = get_object_or_404( + ProposalComment, proposal=proposal, id=proposal_comment_id + ) + + proposal_comment.delete() + return HttpResponse("Comment Deleted") + \ No newline at end of file diff --git a/junction/proposals/models.py b/junction/proposals/models.py index 9ce59543..b50c30bf 100644 --- a/junction/proposals/models.py +++ b/junction/proposals/models.py @@ -392,6 +392,12 @@ def get_mark_spam_url(self): "comment_mark_spam", args=[self.proposal.conference.slug, self.proposal.slug, self.id], ) + + def get_delete_self_comment_url(self): + return reverse( + "delete_self_comment", + args=[self.proposal.conference.slug, self.proposal.slug, self.id], + ) def get_unmark_spam_url(self): return reverse( diff --git a/junction/proposals/urls.py b/junction/proposals/urls.py index 4b5ab6fa..f613aa0e 100644 --- a/junction/proposals/urls.py +++ b/junction/proposals/urls.py @@ -26,6 +26,11 @@ comments_views.mark_comment_as_spam, name="comment_mark_spam", ), + url( + r"^(?P[\w-]+)/comments/(?P\d+)/delete/$", + comments_views.delete_self_comment, + name="delete_self_comment" + ), url( r"^(?P[\w-]+)/comments/(?P\d+)/unmark_spam/$", comments_views.unmark_comment_as_spam, diff --git a/junction/templates/proposals/detail/comments.html b/junction/templates/proposals/detail/comments.html index 2653a920..98e4a05d 100644 --- a/junction/templates/proposals/detail/comments.html +++ b/junction/templates/proposals/detail/comments.html @@ -48,7 +48,10 @@
{% if request.user.is_authenticated and request.user != comment.commenter %} Mark as spam

{% endif %} + {% if request.user.is_authenticated and request.user == comment.commenter %} + Delete comment

{% endif %} + {% endif %} {% if comment.private or comment.reviewer %} {% if comment.commenter == proposal.author %} @@ -139,6 +142,16 @@
}); }); + $('.js-delete-self-comment').click(function(e){ + e.preventDefault(); + var that = $(this); + var url = that.attr('data-url'); + $.post(url, {}, function(result){ + console.log(result); + location.reload(true); + }); + }); + {% else %} $('.js-proposal-upvote, .js-proposal-downvote, .js-proposal-comment-upvote, .js-proposal-comment-downvote').click(function(e){ e.preventDefault();