Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Delete self comment. Solves issue #736 #737

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions junction/proposals/comments_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

6 changes: 6 additions & 0 deletions junction/proposals/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions junction/proposals/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
comments_views.mark_comment_as_spam,
name="comment_mark_spam",
),
url(
r"^(?P<proposal_slug>[\w-]+)/comments/(?P<proposal_comment_id>\d+)/delete/$",
comments_views.delete_self_comment,
name="delete_self_comment"
),
url(
r"^(?P<proposal_slug>[\w-]+)/comments/(?P<proposal_comment_id>\d+)/unmark_spam/$",
comments_views.unmark_comment_as_spam,
Expand Down
13 changes: 13 additions & 0 deletions junction/templates/proposals/detail/comments.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ <h5 class="text-muted clear-margin vote-count">
{% if request.user.is_authenticated and request.user != comment.commenter %}
<a href="#" data-url="{{ comment.get_mark_spam_url }}" class="js-mark-spam">Mark as spam</a><br/><br/>
{% endif %}
{% if request.user.is_authenticated and request.user == comment.commenter %}
<a href="#" data-url="{{ comment.get_delete_self_comment_url }}" class="js-delete-self-comment">Delete comment</a><br/><br/>
{% endif %}
{% endif %}
<b>
{% if comment.private or comment.reviewer %}
{% if comment.commenter == proposal.author %}
Expand Down Expand Up @@ -139,6 +142,16 @@ <h5 class="text-muted clear-margin vote-count">
});
});

$('.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();
Expand Down