Commit cade73fa authored by Michal Čihař's avatar Michal Čihař

Migrate trans.delete_comment permission check to new model

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 90ff5df2
{% load i18n %}
{% load permissions %}
{% can_ignore_check user check.project as user_can_ignore_check %}
{% for check in checks %}
......
{% load translations %}
{% load i18n %}
{% load permissions %}
{% can_delete_comment user unit.translation.subproject.project as user_can_delete_comment %}
{% for comment in comments %}
<div>
......@@ -13,7 +16,7 @@
{% endif %}
</span>
</div>
{% if perms.trans.delete_comment %}
{% if user_can_delete_comment %}
<form method="POST" action="{% url 'delete-comment' pk=comment.pk %}">
{% csrf_token %}
<input type="hidden" name="next" value="{{ next_url }}" />
......
......@@ -224,3 +224,11 @@ def can_ignore_check(user, project):
Checks whether user can edit translation priority.
"""
return check_permission(user, project, 'trans.ignore_check')
@cache_permission
def can_delete_comment(user, project):
"""
Checks whether user can edit translation priority.
"""
return check_permission(user, project, 'trans.delete_comment')
......@@ -106,3 +106,8 @@ def can_edit_priority(user, project):
@register.assignment_tag
def can_ignore_check(user, project):
return weblate.trans.permissions.can_ignore_check(user, project)
@register.assignment_tag
def can_delete_comment(user, project):
return weblate.trans.permissions.can_delete_comment(user, project)
......@@ -25,6 +25,7 @@ from django.http import HttpResponseRedirect, HttpResponse
from django.contrib import messages
from django.contrib.auth.decorators import login_required, permission_required
from django.utils import formats
from django.core.exceptions import PermissionDenied
import uuid
import time
......@@ -43,7 +44,7 @@ from weblate.trans.checks import CHECKS
from weblate.trans.util import join_plural
from weblate.trans.permissions import (
can_translate, can_suggest, can_accept_suggestion, can_delete_suggestion,
can_vote_suggestion,
can_vote_suggestion, can_delete_comment,
)
......@@ -693,6 +694,9 @@ def delete_comment(request, pk):
comment_obj = get_object_or_404(Comment, pk=pk)
comment_obj.project.check_acl(request)
if not can_delete_comment(request.user, comment_obj.project):
raise PermissionDenied()
units = get_related_units(comment_obj)
if units.exists():
fallback_url = units[0].get_absolute_url()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment