Skip to content

Commit

Permalink
Actually delete comments from DB. Refs #1028
Browse files Browse the repository at this point in the history
instead of flagging comments as removed delete them from DB
  • Loading branch information
atodorov committed Nov 24, 2019
1 parent 4076082 commit 78a2daa
Showing 1 changed file with 7 additions and 36 deletions.
43 changes: 7 additions & 36 deletions tcms/core/contrib/comments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from django.conf import settings
from django.contrib.auth.decorators import permission_required
from django.core.exceptions import ObjectDoesNotExist
from django.http import JsonResponse
from django.views.decorators.http import require_POST

Expand All @@ -25,39 +24,11 @@ def post(request):
@require_POST
@permission_required("django_comments.can_moderate")
def delete(request):
"""Deletes a comment"""

ajax_response = {'rc': 0, 'response': 'ok'}
comments_s = comments.get_model().objects.filter(
"""Delete comments via POST request"""
comments.get_model().objects.filter(
pk__in=request.POST.getlist('comment_id'),
site__pk=settings.SITE_ID,
is_removed=False,
user_id=request.user.id
)

if not comments_s:
if request.is_ajax():
ajax_response = {'rc': 1, 'response': 'Object does not exist.'}
return JsonResponse(ajax_response)

raise ObjectDoesNotExist()

# Flag the comment as deleted instead of actually deleting it.
for comment in comments_s:
if comment.user == request.user:
flag, created = comments.models.CommentFlag.objects.get_or_create(
comment=comment,
user=request.user,
flag=comments.models.CommentFlag.MODERATOR_DELETION
)
comment.is_removed = True
comment.save()
comments.signals.comment_was_flagged.send(
sender=comment.__class__,
comment=comment,
flag=flag,
created=created,
request=request,
)

return JsonResponse(ajax_response)
site=settings.SITE_ID,
user=request.user.pk
).delete()

return JsonResponse({'rc': 0, 'response': 'ok'})

0 comments on commit 78a2daa

Please sign in to comment.