Skip to content

Commit

Permalink
feat(unit): show propagation failure reason from PermissionResult
Browse files Browse the repository at this point in the history
Since introduction of PermissionResult the has_perm gives exact reason
why string can't be edited, so display it to the user instead of
checking a single condition only.
  • Loading branch information
nijel committed Oct 16, 2024
1 parent 64aa009 commit 8077108
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions weblate/trans/models/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from django.utils.translation import gettext, gettext_lazy
from pyparsing import ParseException

from weblate.auth.permissions import PermissionResult
from weblate.checks.flags import Flags
from weblate.checks.models import CHECKS, Check
from weblate.formats.helpers import CONTROLCHARS
Expand Down Expand Up @@ -1035,26 +1036,19 @@ def get_target_plurals(self, plurals=None):

def propagate(self, user: User, change_action=None, author=None, request=None):
"""Propagate current translation to all others."""
from weblate.trans.models import ContributorAgreement

result = False
for unit in self.same_source_units:
if unit.target == self.target and unit.state == self.state:
continue
if user is not None and not user.has_perm("unit.edit", unit):
if user is not None and not (denied := user.has_perm("unit.edit", unit)):
component = unit.translation.component
if (
request
and component.agreement
and not ContributorAgreement.objects.has_agreed(user, component)
):
if request and isinstance(denied, PermissionResult):
messages.warning(
request,
gettext(
"String could not be propagated to %(component)s because "
"you have not agreed with a contributor agreement."
"String could not be propagated to %(component)s: %(reason)s"
)
% {"component": component},
% {"component": component, "reason": denied.reason},
)
continue
unit.target = self.target
Expand Down

0 comments on commit 8077108

Please sign in to comment.