Commit 3bc7ce6b authored by Michal Čihař's avatar Michal Čihař

Add wrapper for suggestion privileges

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 316339f6
......@@ -5,6 +5,7 @@
{% load crispy_forms_tags %}
{% load permissions %}
{% can_translate request.user unit.translation as user_can_translate %}
{% can_suggest request.user unit.translation as user_can_suggest %}
{% block extra_meta %}
......@@ -94,13 +95,11 @@
{% endwith %}
{% endif %}
{% if unit.translation.subproject.enable_suggestions %}
{% if perms.trans.add_suggestion %}
{% if user_can_suggest %}
<input class="btn btn-default" type="submit" value="{% trans "Suggest" %}" name="suggest" tabindex="151" {% if project_locked %}disabled="disabled"{% endif %} />
{% else %}
{% trans "No privileges for adding suggestions!" %}
{% endif %}
{% endif %}
{% if user_can_translate %}
<div class="pull-right flip hidden-xs">
......@@ -362,7 +361,7 @@
<td>{{ item.source }}</td>
<td class="target">{% format_translation item.target unit.translation.language simple=True %}</td>
<td>
{% if user_can_translate or perms.trans.add_suggestion %}
{% if user_can_translate or user_can_suggest %}
<a class="copydict btn btn-default btn-xs" title="{% trans "Copy word to translation" %}">{% trans "Copy" %}</a>
{% endif %}
</td>
......
......@@ -36,3 +36,14 @@ def can_translate(user, translation):
user.has_perm('trans.override_suggestion')):
return False
return True
def can_suggest(user, translation):
"""
Checks whether user can add suggestions to given translation.
"""
if not translation.subproject.enable_suggestions:
return False
if not user.has_perm('trans.add_translation'):
return False
return True
......@@ -28,3 +28,10 @@ def can_translate(user, translation):
return weblate.trans.permissions.can_translate(
user, translation
)
@register.assignment_tag
def can_suggest(user, translation):
return weblate.trans.permissions.can_suggest(
user, translation
)
......@@ -41,7 +41,7 @@ from weblate.trans.forms import (
from weblate.trans.views.helper import get_translation
from weblate.trans.checks import CHECKS
from weblate.trans.util import join_plural
from weblate.trans.permissions import can_translate
from weblate.trans.permissions import can_translate, can_suggest
def cleanup_session(session):
......@@ -176,7 +176,7 @@ def perform_suggestion(unit, form, request):
messages.error(request, _('Your suggestion is empty!'))
# Stay on same entry
return False
elif not request.user.has_perm('trans.add_suggestion'):
elif can_suggest(request.user, unit.translation):
# Need privilege to add
messages.error(
request,
......@@ -184,14 +184,6 @@ def perform_suggestion(unit, form, request):
)
# Stay on same entry
return False
elif not unit.translation.subproject.enable_suggestions:
# Need privilege to add
messages.error(
request,
_('Suggestions are not allowed on this translation!')
)
# Stay on same entry
return False
# Invite user to become translator if there is nobody else
recent_changes = Change.objects.content(True).filter(
translation=unit.translation,
......
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