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

Allow owners to use automatic translation

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 72c41c5b
......@@ -261,3 +261,11 @@ def can_download_changes(user, project):
Checks whether user can download CSV for changes on given project.
"""
return check_permission(user, project, 'trans.download_changes')
@cache_permission
def can_automatic_translation(user, project):
"""
Checks whether user can do automatic translation on given project.
"""
return check_permission(user, project, 'trans.automatic_translation')
......@@ -38,6 +38,7 @@ from weblate.trans.forms import (
AutoForm, ReviewForm, NewLanguageForm,
UserManageForm,
)
from weblate.trans.permissions import can_automatic_translation
from weblate.accounts.models import Profile, notify_new_language
from weblate.trans.views.helper import (
get_project, get_subproject, get_translation,
......@@ -284,7 +285,7 @@ def show_translation(request, project, subproject, lang):
form = get_upload_form(request)()
# Is user allowed to do automatic translation?
if request.user.has_perm('trans.automatic_translation'):
if can_automatic_translation(request.user, obj.subproject.project):
autoform = AutoForm(obj)
else:
autoform = None
......
......@@ -23,7 +23,7 @@ from django.views.decorators.http import require_POST
from django.utils.translation import ugettext as _
from django.http import HttpResponseRedirect, HttpResponse
from django.contrib import messages
from django.contrib.auth.decorators import login_required, permission_required
from django.contrib.auth.decorators import login_required
from django.utils import formats
from django.core.exceptions import PermissionDenied
import uuid
......@@ -44,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_delete_comment,
can_vote_suggestion, can_delete_comment, can_automatic_translation,
)
......@@ -599,9 +599,14 @@ def translate(request, project, subproject, lang):
)
@permission_required('trans.automatic_translation')
@require_POST
@login_required
def auto_translation(request, project, subproject, lang):
translation = get_translation(request, project, subproject, lang)
project = translation.subproject.project
if not can_automatic_translation(request.user, project):
raise PermissionDenied()
translation.commit_pending(request)
autoform = AutoForm(translation, request.POST)
change = None
......
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